Exemplo n.º 1
0
    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"])
Exemplo n.º 2
0
    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'])
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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()
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
    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'])
Exemplo n.º 7
0
    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'])
Exemplo n.º 8
0
    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'])
Exemplo n.º 9
0
    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'])
Exemplo n.º 10
0
    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"])
Exemplo n.º 11
0
    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"])
Exemplo n.º 12
0
    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))
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    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))
Exemplo n.º 15
0
    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))
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
    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)