def test_pull_existing(self): self.mock_path_exists.return_value = True hg = sources.Mercurial("hg://my-source", "source_dir") hg.pull() self.mock_run.assert_called_once_with(["hg", "pull", "hg://my-source"])
def test_pull_existing(self): self.mock_path_exists.return_value = True hg = sources.Mercurial('hg://my-source', 'source_dir') hg.pull() self.mock_run.assert_called_once_with(['hg', 'pull', 'hg://my-source'])
def test_init_with_source_depth_raises_exception(self): with self.assertRaises(sources.IncompatibleOptionsError) as raised: sources.Mercurial('hg://mysource', 'source_dir', source_depth=2) expected_message = ( 'can\'t specify source-depth for a mercurial source') self.assertEqual(raised.exception.message, expected_message)
def setUp(self): super().setUp() self.working_tree = 'hg-test' self.source_dir = 'hg-checkout' self.clean_dir(self.working_tree) self.clean_dir(self.source_dir) os.chdir(self.working_tree) call(['hg', 'init']) with open('testing', 'w') as fp: fp.write('testing') call(['hg', 'add', 'testing']) call(['hg', 'commit', '-m', 'testing', '-u', 'Test User <*****@*****.**>']) call(['hg', 'tag', '-u', 'test', 'test-tag']) self.expected_commit = call_with_output(['hg', 'id']).split()[0] self.expected_branch = call_with_output(['hg', 'branch']) self.expected_tag = 'test-tag' os.chdir('..') self.hg = sources.Mercurial(self.working_tree, self.source_dir, silent=True) self.hg.pull() self.source_details = self.hg._get_source_details()
def setUp(self): super().setUp() self.working_tree = "hg-test" self.source_dir = "hg-checkout" self.clean_dir(self.working_tree) self.clean_dir(self.source_dir) os.chdir(self.working_tree) call(["hg", "init"]) with open("testing", "w") as fp: fp.write("testing") call(["hg", "add", "testing"]) call([ "hg", "commit", "-m", "testing", "-u", "Test User <*****@*****.**>" ]) call(["hg", "tag", "-u", "test", "test-tag"]) self.expected_commit = call_with_output(["hg", "id"]).split()[0] self.expected_branch = call_with_output(["hg", "branch"]) self.expected_tag = "test-tag" os.chdir("..") self.hg = sources.Mercurial(self.working_tree, self.source_dir, silent=True) self.hg.pull() self.source_details = self.hg._get_source_details()
def test_pull_tag(self): hg = sources.Mercurial('hg://my-source', 'source_dir', source_tag='tag') hg.pull() self.mock_run.assert_called_once_with( ['hg', 'clone', '-u', 'tag', 'hg://my-source', 'source_dir'])
def test_pull_branch(self): hg = sources.Mercurial('hg://my-source', 'source_dir', source_branch='my-branch') hg.pull() self.mock_run.assert_called_once_with( ['hg', 'clone', '-u', 'my-branch', 'hg://my-source', 'source_dir'])
def test_hg_details_tag(self): self.clean_dir(self.source_dir) self.hg = sources.Mercurial(self.working_tree, self.source_dir, silent=True, source_tag='test-tag') self.hg.pull() self.source_details = self.hg._get_source_details() self.assertEqual(self.expected_tag, self.source_details['tag'])
def test_hg_details_branch(self): self.clean_dir(self.source_dir) self.hg = sources.Mercurial(self.working_tree, self.source_dir, silent=True, source_branch='default') self.hg.pull() self.source_details = self.hg._get_source_details() self.assertEqual(self.expected_branch, self.source_details['branch'])
def test_pull_commit(self): hg = sources.Mercurial("hg://my-source", "source_dir", source_commit="2") hg.pull() self.mock_run.assert_called_once_with( ["hg", "clone", "-u", "2", "hg://my-source", "source_dir"])
def test_pull_branch(self): hg = sources.Mercurial("hg://my-source", "source_dir", source_branch="my-branch") hg.pull() self.mock_run.assert_called_once_with( ["hg", "clone", "-u", "my-branch", "hg://my-source", "source_dir"])
def test_pull_failure(self): self.mock_run.side_effect = subprocess.CalledProcessError(1, []) hg = sources.Mercurial("hg://my-source", "source_dir") raised = self.assertRaises(sources.errors.SnapcraftPullError, hg.pull) self.assertThat(raised.command, Equals("hg clone hg://my-source source_dir")) self.assertThat(raised.exit_code, Equals(1))
def test_init_with_source_commit_and_branch_raises_exception(self): with self.assertRaises(sources.IncompatibleOptionsError) as raised: sources.Mercurial( 'hg://mysource', 'source_dir', source_commit='2', source_branch='branch') expected_message = ( 'can\'t specify both source-branch and source-commit for ' 'a mercurial source') self.assertEqual(raised.exception.message, expected_message)
def test_hg_details_tag(self): self.clean_dir(self.source_dir) self.hg = sources.Mercurial(self.working_tree, self.source_dir, silent=True, source_tag="test-tag") self.hg.pull() self.source_details = self.hg._get_source_details() self.assertThat(self.source_details["source-tag"], Equals(self.expected_tag))
def test_hg_details_branch(self): self.clean_dir(self.source_dir) self.hg = sources.Mercurial(self.working_tree, self.source_dir, silent=True, source_branch="default") self.hg.pull() self.source_details = self.hg._get_source_details() self.assertThat(self.source_details["source-branch"], Equals(self.expected_branch))
def test_hg_details_commit(self): hg = sources.Mercurial(self.working_tree, self.source_dir, silent=True) hg.pull() source_details = hg._get_source_details() self.assertThat(source_details["source-commit"], Equals("mock-commit")) self.fake_check_output.mock.assert_has_calls([ mock.call(["hg", "id", self.source_dir]), mock.call(["hg", "id", self.source_dir]), ]) self.fake_check_call.mock.assert_called_once_with( ["hg", "pull", self.working_tree], stderr=-3, stdout=-3)
def test_hg_details_tag(self): hg = sources.Mercurial(self.working_tree, self.source_dir, silent=True, source_tag="test-tag") hg.pull() source_details = hg._get_source_details() self.assertThat(source_details["source-tag"], Equals("test-tag")) self.fake_check_output.mock.assert_not_called() self.fake_check_call.mock.assert_called_once_with( ["hg", "pull", "-r", "test-tag", self.working_tree], stderr=-3, stdout=-3)