def test_git_eq(self): """Test GitVC.__eq__.""" vc_obj1 = GitVC(self.context, '/example') vc_obj2 = GitVC(self.context, '/example', 'master') vc_obj3 = GitVC(self.context, '/example', 'other') vc_obj4 = GitVC(self.context, '/other') vc_obj5 = SvnVC(self.context, '/example') self.assertEqual(vc_obj1, vc_obj1) self.assertEqual(vc_obj1, vc_obj2) self.assertNotEqual(vc_obj1, vc_obj3) self.assertNotEqual(vc_obj1, vc_obj4) self.assertNotEqual(vc_obj1, vc_obj5) self.assertEqual(vc_obj2, vc_obj1) self.assertEqual(vc_obj2, vc_obj2) self.assertNotEqual(vc_obj2, vc_obj3) self.assertNotEqual(vc_obj2, vc_obj4) self.assertNotEqual(vc_obj2, vc_obj5) self.assertNotEqual(vc_obj3, vc_obj1) self.assertNotEqual(vc_obj3, vc_obj2) self.assertEqual(vc_obj3, vc_obj3) self.assertNotEqual(vc_obj3, vc_obj4) self.assertNotEqual(vc_obj3, vc_obj5) self.assertNotEqual(vc_obj4, vc_obj1) self.assertNotEqual(vc_obj4, vc_obj2) self.assertNotEqual(vc_obj4, vc_obj3) self.assertEqual(vc_obj4, vc_obj4) self.assertNotEqual(vc_obj4, vc_obj5)
def test_git_branch(self): """Test checkouts from git, non-master branch.""" os.mkdir(self.codir) subprocess.run(['git', 'init', '-q'], cwd=self.codir, check=True) self.co_file_write('gitfile', 'gitfile contents') subprocess.run(['git', 'add', '.'], cwd=self.codir, check=True) subprocess.run(['git', 'commit', '-q', '-m', 'commit message'], cwd=self.codir, check=True) subprocess.run(['git', 'branch', '-q', 'newbranch'], cwd=self.codir, check=True) vc_obj = GitVC(self.context, self.codir, 'newbranch') vc_obj.vc_checkout(self.srcdir, False) self.assertEqual(self.src_file_read('gitfile'), 'gitfile contents') self.co_file_write('gitfile', 'modified contents') subprocess.run(['git', 'commit', '-q', '-a', '-m', 'commit 2'], cwd=self.codir, check=True) # master has been modified, but not yet newbranch. vc_obj.vc_checkout(self.srcdir, True) self.assertEqual(self.src_file_read('gitfile'), 'gitfile contents') subprocess.run(['git', 'checkout', '-q', 'newbranch'], cwd=self.codir, check=True) subprocess.run(['git', 'merge', '-q', 'master'], cwd=self.codir, check=True) # newbranch has now been modified as well. vc_obj.vc_checkout(self.srcdir, True) self.assertEqual(self.src_file_read('gitfile'), 'modified contents')
def test_git_errors(self): """Test checkouts from git, errors.""" self.context.execute_silent = True os.mkdir(self.codir) subprocess.run(['git', 'init', '-q'], cwd=self.codir, check=True) self.co_file_write('gitfile', 'gitfile contents') subprocess.run(['git', 'add', '.'], cwd=self.codir, check=True) subprocess.run(['git', 'commit', '-q', '-m', 'commit message'], cwd=self.codir, check=True) vc_obj = GitVC(self.context, self.codir) vc_obj.vc_checkout(self.srcdir, False) self.assertEqual(self.src_file_read('gitfile'), 'gitfile contents') shutil.rmtree(self.codir) self.assertRaises(subprocess.CalledProcessError, vc_obj.vc_checkout, self.srcdir, True) shutil.rmtree(self.srcdir) self.assertRaises(subprocess.CalledProcessError, vc_obj.vc_checkout, self.srcdir, False)
def test_svn_eq(self): """Test SvnVC.__eq__.""" vc_obj1 = SvnVC(self.context, 'file:///example') vc_obj2 = SvnVC(self.context, 'file:///other') vc_obj3 = GitVC(self.context, 'file:///example') self.assertEqual(vc_obj1, vc_obj1) self.assertNotEqual(vc_obj1, vc_obj2) self.assertNotEqual(vc_obj1, vc_obj3) self.assertNotEqual(vc_obj2, vc_obj1) self.assertEqual(vc_obj2, vc_obj2) self.assertNotEqual(vc_obj1, vc_obj3)
def test_git(self): """Test checkouts from git.""" os.mkdir(self.codir) subprocess.run(['git', 'init', '-q'], cwd=self.codir, check=True) self.co_file_write('gitfile', 'gitfile contents') subprocess.run(['git', 'add', '.'], cwd=self.codir, check=True) subprocess.run(['git', 'commit', '-q', '-m', 'commit message'], cwd=self.codir, check=True) vc_obj = GitVC(self.context, self.codir) vc_obj.vc_checkout(self.srcdir, False) self.assertEqual(self.src_file_read('gitfile'), 'gitfile contents') self.co_file_write('gitfile', 'modified contents') subprocess.run(['git', 'commit', '-q', '-a', '-m', 'commit 2'], cwd=self.codir, check=True) vc_obj.vc_checkout(self.srcdir, True) self.assertEqual(self.src_file_read('gitfile'), 'modified contents')
def test_git_copy_without_metadata(self): """Test copying checkouts from git.""" os.mkdir(self.codir) subprocess.run(['git', 'init', '-q'], cwd=self.codir, check=True) self.co_file_write('gitfile', 'gitfile contents') subprocess.run(['git', 'add', '.'], cwd=self.codir, check=True) subprocess.run(['git', 'commit', '-q', '-m', 'commit message'], cwd=self.codir, check=True) vc_obj = GitVC(self.context, self.codir) vc_obj.vc_checkout(self.srcdir, False) os.chmod(os.path.join(self.srcdir, 'gitfile'), stat.S_IRUSR) vc_obj.copy_without_metadata(self.srcdir, self.srcdir_copy) self.assertEqual(read_files(self.srcdir_copy), (set(), { 'gitfile': 'gitfile contents' }, {})) mode = stat.S_IMODE( os.stat(os.path.join(self.srcdir_copy, 'gitfile')).st_mode) self.assertEqual(mode, (stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH))
def test_git_metadata_paths(self): """Test GitVC.metadata_paths.""" vc_obj = GitVC(self.context, '/example') self.assertEqual(vc_obj.metadata_paths('/some/where'), {'/some/where/.git'})
def test_git_repr(self): """Test GitVC.__repr__.""" vc_obj = GitVC(self.context, '/example') self.assertEqual(repr(vc_obj), "GitVC('/example', 'master')") vc_obj = GitVC(self.context, '/example', 'branch') self.assertEqual(repr(vc_obj), "GitVC('/example', 'branch')")