def test_non_cannonical_identifiers(self): with mocks.local.Svn(self.path), OutputCapture(): self.assertEqual('2@trunk', str(local.Svn(self.path).commit(identifier='0@branch-a'))) self.assertEqual('1@trunk', str(local.Svn(self.path).commit(identifier='-1@branch-a'))) self.assertEqual('2@trunk', str(local.Svn(self.path).commit(identifier='0@branch-b'))) self.assertEqual('1@trunk', str(local.Svn(self.path).commit(identifier='-1@branch-b')))
def test_checkout_svn(self): with mocks.local.Git(), mocks.local.Svn(self.path), MockTime, OutputCapture(): self.assertEqual(6, local.Svn(self.path).commit().revision) self.assertEqual(0, program.main( args=('checkout', '3@trunk'), path=self.path, )) self.assertEqual(4, local.Svn(self.path).commit().revision)
def test_cache(self): try: dirname = tempfile.mkdtemp() with mocks.local.Svn(dirname) as mock_repo, OutputCapture(): os.mkdir(os.path.join(dirname, '.svn')) self.assertEqual('4@trunk', str(local.Svn(dirname).commit())) mock_repo.connected = False commit = local.Svn(dirname).commit() self.assertEqual('4@trunk', str(commit)) with self.assertRaises(local.Svn.Exception): local.Svn(dirname).commit(revision=3) finally: shutil.rmtree(dirname)
def from_path(cls, path, contributors=None): from webkitscmpy import local if local.Git.is_checkout(path): return local.Git(path, contributors=contributors) if local.Svn.is_checkout(path): return local.Svn(path, contributors=contributors) raise OSError("'{}' is not a known SCM type".format(path))
def from_path(cls, path): from webkitscmpy import local if local.Git.is_checkout(path): return local.Git(path) if local.Svn.is_checkout(path): return local.Svn(path) raise OSError('{} is not a known SCM type')
def test_identifier(self): with mocks.local.Svn(self.path), OutputCapture(): self.assertEqual(1, local.Svn(self.path).commit(identifier='1@trunk').revision) self.assertEqual(2, local.Svn(self.path).commit(identifier='2@trunk').revision) self.assertEqual(3, local.Svn(self.path).commit(identifier='2.1@branch-a').revision) self.assertEqual(4, local.Svn(self.path).commit(identifier='3@trunk').revision) self.assertEqual(5, local.Svn(self.path).commit(identifier='2.2@branch-b').revision) self.assertEqual(6, local.Svn(self.path).commit(identifier='4@trunk').revision) self.assertEqual(7, local.Svn(self.path).commit(identifier='2.2@branch-a').revision) self.assertEqual(8, local.Svn(self.path).commit(identifier='2.3@branch-b').revision)
def test_commit_revision(self): with mocks.local.Svn(self.path), OutputCapture(): self.assertEqual('1@trunk', str(local.Svn(self.path).commit(revision=1))) self.assertEqual('2@trunk', str(local.Svn(self.path).commit(revision=2))) self.assertEqual('2.1@branch-a', str(local.Svn(self.path).commit(revision=3))) self.assertEqual('3@trunk', str(local.Svn(self.path).commit(revision=4))) self.assertEqual('2.2@branch-b', str(local.Svn(self.path).commit(revision=5))) self.assertEqual('4@trunk', str(local.Svn(self.path).commit(revision=6))) self.assertEqual('2.2@branch-a', str(local.Svn(self.path).commit(revision=7))) self.assertEqual('2.3@branch-b', str(local.Svn(self.path).commit(revision=8))) # Out-of-bounds commit with self.assertRaises(local.Svn.Exception): self.assertEqual(None, local.Svn(self.path).commit(revision=11))
def test_commits_branch(self): with mocks.local.Svn(self.path), OutputCapture(): svn = local.Svn(self.path) self.assertEqual(Commit.Encoder().default([ svn.commit(revision='r7'), svn.commit(revision='r3'), svn.commit(revision='r2'), svn.commit(revision='r1'), ]), Commit.Encoder().default(list(svn.commits(begin=dict(argument='r1'), end=dict(argument='r7')))))
def test_branches_priority(self): with mocks.local.Svn(self.path): self.assertEqual( 'trunk', local.Svn(self.path).prioritize_branches(['trunk', 'branch-a', 'dev/12345', 'safari-610-branch', 'safari-610.1-branch']) ) self.assertEqual( 'safari-610-branch', local.Svn(self.path).prioritize_branches(['branch-a', 'dev/12345', 'safari-610-branch', 'safari-610.1-branch']) ) self.assertEqual( 'safari-610.1-branch', local.Svn(self.path).prioritize_branches(['branch-a', 'dev/12345', 'safari-610.1-branch']) ) self.assertEqual( 'branch-a', local.Svn(self.path).prioritize_branches(['branch-a', 'dev/12345']) )
def test_checkout(self): with mocks.local.Svn(self.path), OutputCapture(): repository = local.Svn(self.path) self.assertEqual(6, repository.commit().revision) self.assertEqual(5, repository.checkout('r5').revision) self.assertEqual(5, repository.commit().revision) self.assertEqual(4, repository.checkout('3@trunk').revision) self.assertEqual(4, repository.commit().revision) self.assertEqual(9, repository.checkout('tag-1').revision) self.assertEqual(9, repository.commit().revision)
def test_info(self): with mocks.local.Svn(self.path): self.assertDictEqual( { u'Path': u'.', u'Working Copy Root Path': u'/mock/repository', u'Repository Root': u'https://svn.mock.org/repository/repository', u'URL': u'https://svn.mock.org/repository/repository/trunk', u'Relative URL': u'^/trunk', u'Revision': u'6', u'NodeKind': u'directory', u'Schedule': u'normal', u'Last Changed Author': u'*****@*****.**', u'Last Changed Rev': u'6', u'Last Changed Date': datetime.utcfromtimestamp(1601665100).strftime('%Y-%m-%d %H:%M:%S 0000 (%a, %d %b %Y)'), }, local.Svn(self.path).info(), )
def test_no_network(self): with mocks.local.Svn(self.path) as mock_repo, OutputCapture(): repo = local.Svn(self.path) self.assertEqual('4@trunk', str(repo.commit())) mock_repo.connected = False commit = repo.commit() self.assertEqual('4@trunk', str(commit)) self.assertEqual(6, commit.revision) self.assertEqual(None, commit.message) commit = repo.commit(revision=4) self.assertEqual('3@trunk', str(commit)) self.assertEqual(None, commit.message) with self.assertRaises(local.Svn.Exception): repo.commit(revision=3) mock_repo.connected = True self.assertEqual('2.1@branch-a', str(repo.commit(revision=3))) mock_repo.connected = False self.assertEqual('2.1@branch-a', str(repo.commit(revision=3)))
def test_scm_type(self): with mocks.local.Svn(self.path): self.assertTrue(local.Svn(self.path).is_svn) self.assertFalse(local.Svn(self.path).is_git)
def test_default_branch(self): with mocks.local.Svn(self.path): self.assertEqual(local.Svn(self.path).default_branch, 'trunk')
def test_tags(self): with mocks.local.Svn(self.path): self.assertEqual( local.Svn(self.path).tags, ['tag-1', 'tag-2'], )
def test_branches(self): with mocks.local.Svn(self.path): self.assertEqual( local.Svn(self.path).branches, ['trunk', 'branch-a', 'branch-b'], )
def test_remote(self): with mocks.local.Svn(self.path) as repo: self.assertEqual(local.Svn(self.path).remote(), repo.remote)
def test_root(self): with mocks.local.Svn(self.path): self.assertEqual(local.Svn(self.path).root_path, self.path) with self.assertRaises(OSError): local.Svn(os.path.dirname(self.path)).root_path
def test_no_identifier(self): with mocks.local.Svn(self.path), OutputCapture(): self.assertIsNone(local.Svn(self.path).find('trunk', include_identifier=False).identifier)
def test_tag_previous(self): with mocks.local.Svn(self.path), OutputCapture(): self.assertEqual(7, local.Svn(self.path).commit(identifier='2.2@tags/tag-1').revision)
def test_tag(self): with mocks.local.Svn(self.path), OutputCapture(): self.assertEqual(9, local.Svn(self.path).commit(tag='tag-1').revision)
def test_alternative_default_branch(self): with mocks.local.Svn(self.path), OutputCapture(): self.assertEqual(str(local.Svn(self.path).find('4@main')), '4@trunk') self.assertEqual(str(local.Svn(self.path).find('4@master')), '4@trunk')
def test_no_log(self): with mocks.local.Svn(self.path), OutputCapture(): self.assertIsNone(local.Svn(self.path).commit(identifier='4@trunk', include_log=False).message)
def test_branches(self): with mocks.local.Svn(self.path, branches=('branch-1', 'branch-2')): self.assertEqual( local.Svn(self.path).branches, ['trunk', 'branch-1', 'branch-2'], )
def test_commit_from_branch(self): with mocks.local.Svn(self.path), OutputCapture(): self.assertEqual('4@trunk', str(local.Svn(self.path).commit(branch='trunk'))) self.assertEqual('2.2@branch-a', str(local.Svn(self.path).commit(branch='branch-a'))) self.assertEqual('2.3@branch-b', str(local.Svn(self.path).commit(branch='branch-b')))