From e64ac4043d6a6d0b4d3921a88e6aa2c53436da29 Mon Sep 17 00:00:00 2001 From: Remco Wendt Date: Sun, 23 Oct 2011 22:55:34 +0200 Subject: Fixed unit tests for use on mac, since /tmp is a symlink to /private/tmp --- test_dotfiles.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'test_dotfiles.py') diff --git a/test_dotfiles.py b/test_dotfiles.py index bb54578..f82f3ae 100755 --- a/test_dotfiles.py +++ b/test_dotfiles.py @@ -49,7 +49,8 @@ class DotfilesTestCase(unittest.TestCase): dotfiles.sync(force=True) self.assertEqual( - os.path.realpath(os.path.join(self.home, '.lastpass')), '/tmp') + os.path.realpath(os.path.join(self.home, '.lastpass')), + os.path.realpath('/tmp')) def test_move_repository(self): """Test the move() method for a Dotfiles repository.""" @@ -65,7 +66,7 @@ class DotfilesTestCase(unittest.TestCase): # Make sure sync() did the right thing. self.assertEqual( os.path.realpath(os.path.join(self.home, '.bashrc')), - os.path.join(self.repo, 'bashrc')) + os.path.realpath(os.path.join(self.repo, 'bashrc'))) target = os.path.join(self.home, 'MyDotfiles') @@ -74,7 +75,7 @@ class DotfilesTestCase(unittest.TestCase): self.assertTrue(os.path.exists(os.path.join(target, 'bashrc'))) self.assertEqual( os.path.realpath(os.path.join(self.home, '.bashrc')), - os.path.join(target, 'bashrc')) + os.path.realpath(os.path.join(target, 'bashrc'))) def test_sync_unmanaged_directory_symlink(self): """Test a forced sync on a directory symlink. @@ -98,7 +99,7 @@ class DotfilesTestCase(unittest.TestCase): # Make sure the symlink points to the correct location. self.assertEqual( os.path.realpath(os.path.join(self.home, '.vim')), - os.path.join(self.home, 'vim')) + os.path.realpath(os.path.join(self.home, 'vim'))) dotfiles = core.Dotfiles( home=self.home, repo=self.repo, prefix='', @@ -109,7 +110,7 @@ class DotfilesTestCase(unittest.TestCase): # The symlink should now point to the directory in the repository. self.assertEqual( os.path.realpath(os.path.join(self.home, '.vim')), - os.path.join(self.repo, 'vim')) + os.path.realpath(os.path.join(self.repo, 'vim'))) def suite(): -- cgit v1.2.3 From 1c9d0a6641863de75e6c218882dfcdce051c1471 Mon Sep 17 00:00:00 2001 From: Remco Wendt Date: Sun, 23 Oct 2011 23:53:09 +0200 Subject: Added unit test for glob pattern, which fail horribly yay! --- test_dotfiles.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'test_dotfiles.py') diff --git a/test_dotfiles.py b/test_dotfiles.py index f82f3ae..d12b5b0 100755 --- a/test_dotfiles.py +++ b/test_dotfiles.py @@ -112,6 +112,66 @@ class DotfilesTestCase(unittest.TestCase): os.path.realpath(os.path.join(self.home, '.vim')), os.path.realpath(os.path.join(self.repo, 'vim'))) + def test_glob_ignore_pattern(self): + """ Test that the use of glob pattern matching works in the ignores list. + + The following repo dir exists: + + myscript.py + myscript.pyc + myscript.pyo + bashrc + bashrc.swp + vimrc + vimrc.swp + install.sh + + Using the glob pattern dotfiles should have the following sync result in home: + + .myscript.py -> Dotfiles/myscript.py + .bashrc -> Dotfiles/bashrc + .vimrc -> Dotfiles/vimrc + + """ + ignore = ['*.swp', '.py?', 'install.sh'] + + all_repo_files = ( + ('myscript.py', '.myscript.py'), + ('myscript.pyc', None), + ('myscript.pyo', None), + ('bashrc', '.bashrc'), + ('bashrc.swp', None), + ('vimrc', '.vimrc'), + ('vimrc.swp', None), + ('install.sh', None) + ) + + all_dotfiles = [f for f in all_repo_files if f[1] is not None] + + for original, symlink in all_repo_files: + touch(os.path.join(self.repo, original)) + + dotfiles = core.Dotfiles( + home=self.home, repo=self.repo, prefix='', + ignore=ignore, externals={}) + + dotfiles.sync() + + # Now check that the files that should have a symlink + # point to the correct file and are the only files that + # exist in the home dir. + self.assertEqual( + sorted(os.listdir(self.home)), + sorted([f[1] for f in all_dotfiles])) + + for original, symlink in all_dotfiles: + original_path = os.path.join(self.repo, original) + symlink_path = os.path.join(self.home, symlink) + + self.assertEqual( + os.path.realpath(original_path), + os.path.realpath(symlink_path)) + def suite(): suite = unittest.TestLoader().loadTestsFromTestCase(DotfilesTestCase) -- cgit v1.2.3 From 92e7a8ead118311086217c983a6747287ec084ff Mon Sep 17 00:00:00 2001 From: Remco Wendt Date: Mon, 24 Oct 2011 00:39:22 +0200 Subject: Added glob style pattern support for the ignore option --- dotfiles/core.py | 9 ++++++++- test_dotfiles.py | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'test_dotfiles.py') diff --git a/dotfiles/core.py b/dotfiles/core.py index c679039..ae79724 100644 --- a/dotfiles/core.py +++ b/dotfiles/core.py @@ -9,6 +9,7 @@ This module provides the basic functionality of dotfiles. import os import shutil +import fnmatch __version__ = '0.4.2' @@ -83,7 +84,13 @@ class Dotfiles(object): self.dotfiles = list() - for dotfile in list(x for x in os.listdir(self.repo) if x not in self.ignore): + all_repofiles = os.listdir(self.repo) + repofiles_to_symlink = set(all_repofiles) + + for pat in self.ignore: + repofiles_to_symlink.difference_update(fnmatch.filter(all_repofiles, pat)) + + for dotfile in repofiles_to_symlink: self.dotfiles.append(Dotfile(dotfile[len(self.prefix):], os.path.join(self.repo, dotfile), self.home)) diff --git a/test_dotfiles.py b/test_dotfiles.py index d12b5b0..0284ba4 100755 --- a/test_dotfiles.py +++ b/test_dotfiles.py @@ -133,7 +133,7 @@ class DotfilesTestCase(unittest.TestCase): .vimrc -> Dotfiles/vimrc """ - ignore = ['*.swp', '.py?', 'install.sh'] + ignore = ['*.swp', '*.py?', 'install.sh'] all_repo_files = ( ('myscript.py', '.myscript.py'), @@ -162,7 +162,7 @@ class DotfilesTestCase(unittest.TestCase): # exist in the home dir. self.assertEqual( sorted(os.listdir(self.home)), - sorted([f[1] for f in all_dotfiles])) + sorted([f[1] for f in all_dotfiles] + ['Dotfiles'])) for original, symlink in all_dotfiles: original_path = os.path.join(self.repo, original) -- cgit v1.2.3 From 43372591599c05f59370b67fb5104f9a483038be Mon Sep 17 00:00:00 2001 From: Remco Wendt Date: Mon, 24 Oct 2011 00:59:57 +0200 Subject: Refactored tests to use an assertPathEquals --- test_dotfiles.py | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'test_dotfiles.py') diff --git a/test_dotfiles.py b/test_dotfiles.py index 0284ba4..f9d6fcf 100755 --- a/test_dotfiles.py +++ b/test_dotfiles.py @@ -30,6 +30,11 @@ class DotfilesTestCase(unittest.TestCase): shutil.rmtree(self.home) + def assertPathEqual(self, path1, path2): + self.assertEqual( + os.path.realpath(path1), + os.path.realpath(path2)) + def test_force_sync_directory(self): """Test forced sync when the dotfile is a directory. @@ -48,9 +53,9 @@ class DotfilesTestCase(unittest.TestCase): dotfiles.sync(force=True) - self.assertEqual( - os.path.realpath(os.path.join(self.home, '.lastpass')), - os.path.realpath('/tmp')) + self.assertPathEqual( + os.path.join(self.home, '.lastpass'), + '/tmp') def test_move_repository(self): """Test the move() method for a Dotfiles repository.""" @@ -64,18 +69,18 @@ class DotfilesTestCase(unittest.TestCase): dotfiles.sync() # Make sure sync() did the right thing. - self.assertEqual( - os.path.realpath(os.path.join(self.home, '.bashrc')), - os.path.realpath(os.path.join(self.repo, 'bashrc'))) + self.assertPathEqual( + os.path.join(self.home, '.bashrc'), + os.path.join(self.repo, 'bashrc')) target = os.path.join(self.home, 'MyDotfiles') dotfiles.move(target) self.assertTrue(os.path.exists(os.path.join(target, 'bashrc'))) - self.assertEqual( - os.path.realpath(os.path.join(self.home, '.bashrc')), - os.path.realpath(os.path.join(target, 'bashrc'))) + self.assertPathEqual( + os.path.join(self.home, '.bashrc'), + os.path.join(target, 'bashrc')) def test_sync_unmanaged_directory_symlink(self): """Test a forced sync on a directory symlink. @@ -97,9 +102,9 @@ class DotfilesTestCase(unittest.TestCase): os.mkdir(os.path.join(self.repo, 'vim')) # Make sure the symlink points to the correct location. - self.assertEqual( - os.path.realpath(os.path.join(self.home, '.vim')), - os.path.realpath(os.path.join(self.home, 'vim'))) + self.assertPathEqual( + os.path.join(self.home, '.vim'), + os.path.join(self.home, 'vim')) dotfiles = core.Dotfiles( home=self.home, repo=self.repo, prefix='', @@ -108,9 +113,9 @@ class DotfilesTestCase(unittest.TestCase): dotfiles.sync(force=True) # The symlink should now point to the directory in the repository. - self.assertEqual( - os.path.realpath(os.path.join(self.home, '.vim')), - os.path.realpath(os.path.join(self.repo, 'vim'))) + self.assertPathEqual( + os.path.join(self.home, '.vim'), + os.path.join(self.repo, 'vim')) def test_glob_ignore_pattern(self): """ Test that the use of glob pattern matching works in the ignores list. @@ -165,13 +170,9 @@ class DotfilesTestCase(unittest.TestCase): sorted([f[1] for f in all_dotfiles] + ['Dotfiles'])) for original, symlink in all_dotfiles: - original_path = os.path.join(self.repo, original) - symlink_path = os.path.join(self.home, symlink) - - self.assertEqual( - os.path.realpath(original_path), - os.path.realpath(symlink_path)) - + self.assertPathEqual( + os.path.join(self.repo, original), + os.path.join(self.home, symlink)) def suite(): suite = unittest.TestLoader().loadTestsFromTestCase(DotfilesTestCase) -- cgit v1.2.3