From 5c523d66556af48730fb404e2d102edd4fc0a105 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Wed, 16 Dec 2015 17:29:39 +0000 Subject: [PATCH] Begin conversion to testscenarios Use testscenarios where possible due to the way parameters within each scenario can be accessed directly on the object for providing additional feedback in the case of failed tests. Moves each searcher test into a separate yaml file to be loaded as a scenario which helps separate test info and actual code performing the test. Change-Id: Ie86561a8a1b80dc66bfc4bd43bda3ba46b0a5a4a --- git_upstream/tests/base.py | 33 +- git_upstream/tests/searchers/__init__.py | 0 .../searchers/scenarios/addition_branch.yaml | 44 ++ .../additional_branch_multiple_imports.yaml | 55 +++ .../tests/searchers/scenarios/basic.yaml | 38 ++ .../changes_approved_after_import_merge.yaml | 63 +++ .../changes_upload_prior_to_import.yaml | 63 +++ .../multi_changes_upload_prior_to_import.yaml | 62 +++ .../old_style_merge_replace_first.yaml | 52 +++ .../scenarios/switch_tracked_branches.yaml | 54 +++ .../switch_tracked_branches_incorrect.yaml | 57 +++ .../tests/searchers/test_searchers.py | 54 +++ git_upstream/tests/test_searchers.py | 410 ------------------ test-requirements.txt | 2 + 14 files changed, 574 insertions(+), 413 deletions(-) create mode 100644 git_upstream/tests/searchers/__init__.py create mode 100644 git_upstream/tests/searchers/scenarios/addition_branch.yaml create mode 100644 git_upstream/tests/searchers/scenarios/additional_branch_multiple_imports.yaml create mode 100644 git_upstream/tests/searchers/scenarios/basic.yaml create mode 100644 git_upstream/tests/searchers/scenarios/changes_approved_after_import_merge.yaml create mode 100644 git_upstream/tests/searchers/scenarios/changes_upload_prior_to_import.yaml create mode 100644 git_upstream/tests/searchers/scenarios/multi_changes_upload_prior_to_import.yaml create mode 100644 git_upstream/tests/searchers/scenarios/old_style_merge_replace_first.yaml create mode 100644 git_upstream/tests/searchers/scenarios/switch_tracked_branches.yaml create mode 100644 git_upstream/tests/searchers/scenarios/switch_tracked_branches_incorrect.yaml create mode 100644 git_upstream/tests/searchers/test_searchers.py delete mode 100644 git_upstream/tests/test_searchers.py diff --git a/git_upstream/tests/base.py b/git_upstream/tests/base.py index 49fbbb8..efd883f 100644 --- a/git_upstream/tests/base.py +++ b/git_upstream/tests/base.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +import io import logging import os from pprint import pformat @@ -24,6 +25,7 @@ import git import loremipsum import testtools from testtools.content import text_content +import yaml def _get_node_to_pick(node): @@ -89,6 +91,22 @@ def reverse_toposort(data): raise RuntimeError(message) +def get_scenarios(scenarios_path): + """Returns a list of scenarios, each scenario being describe + by it's name, and a dict containing the parameters + """ + + scenarios = [] + for root, dirs, files in os.walk(scenarios_path): + for f in files: + if f.endswith('.yaml'): + filename = os.path.join(root, f) + with io.open(filename, 'r', encoding='utf-8') as yaml_file: + data = yaml.load(yaml_file) + scenarios.append((filename, data[0])) + return scenarios + + class DiveDir(fixtures.Fixture): """Dive into given directory and return back on cleanup. @@ -296,9 +314,18 @@ class BaseTestCase(testtools.TestCase): return [self._graph[n] for n in nodes] def attach_graph_info(self, exc_info): + # appears to be an odd bug where this method is called twice + # if registered with addOnException so make sure to guard + # that the path actually exists before running + if not (hasattr(self.testrepo, 'path') and + os.path.exists(self.testrepo.path)): + return + if not self._graph: return self.addDetail('graph-dict', text_content(pformat(self._graph))) - self.addDetail('git-log-with-graph', - text_content(self.git.log(graph=True, oneline=True, - decorate=True, all=True))) + + self.addDetail( + 'git-log-with-graph', + text_content(self.repo.git.log(graph=True, oneline=True, + decorate=True, all=True))) diff --git a/git_upstream/tests/searchers/__init__.py b/git_upstream/tests/searchers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/git_upstream/tests/searchers/scenarios/addition_branch.yaml b/git_upstream/tests/searchers/scenarios/addition_branch.yaml new file mode 100644 index 0000000..5ad94a2 --- /dev/null +++ b/git_upstream/tests/searchers/scenarios/addition_branch.yaml @@ -0,0 +1,44 @@ +# +# Copyright (c) 2016 Hewlett-Packard Enterprise Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--- +- desc: | + Construct a repo layout where previously an additional branch has been + included and validate that locate changes walker can find the expected + changes. + + Repository layout being tested + + B example/packaging + \ + C---D---E master + / + A---F---G upstream/master + + tree: + - [A, []] + - [B, []] + - [C, [A, B]] + - [D, [C]] + - [E, [D]] + - [F, [A]] + - [G, [F]] + + branches: + head: [master, E] + upstream: [upstream/master, G] + + expected_changes: [C, D, E] diff --git a/git_upstream/tests/searchers/scenarios/additional_branch_multiple_imports.yaml b/git_upstream/tests/searchers/scenarios/additional_branch_multiple_imports.yaml new file mode 100644 index 0000000..4f68460 --- /dev/null +++ b/git_upstream/tests/searchers/scenarios/additional_branch_multiple_imports.yaml @@ -0,0 +1,55 @@ +# +# Copyright (c) 2016 Hewlett-Packard Enterprise Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--- +- desc: | + Construct a repo layout where previously an additional branch has been + included and validate that locate changes walker can find the right + changes after an additional import. + + Repository layout being tested + + B-- example/packaging + \ \ + C---D---E-------I---J---K master + / \ / + / --H---D1--E1 import/next + / / + A---F---G---L---M upstream/master + + tree: + - [A, []] + - [B, []] + - [C, [A, B]] + - [D, [C]] + - [E, [D]] + - [F, [A]] + - [G, [F]] + - [H, [G, B]] + - [D1, [H]] + - [E1, [D1]] + - [I, [E, =E1]] + - [J, [I]] + - [J, [I]] + - [K, [J]] + - [L, [G]] + - [M, [L]] + + branches: + head: [master, K] + upstream: [upstream/master, M] + + expected_changes: [H, D1, E1, I, J, K] diff --git a/git_upstream/tests/searchers/scenarios/basic.yaml b/git_upstream/tests/searchers/scenarios/basic.yaml new file mode 100644 index 0000000..f8a9e17 --- /dev/null +++ b/git_upstream/tests/searchers/scenarios/basic.yaml @@ -0,0 +1,38 @@ +# +# Copyright (c) 2016 Hewlett-Packard Enterprise Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--- +- desc: | + Construct a basic repo layout and validate that locate changes walker + can find the expected changes. + + Repository layout being tested + + B master + / + A---C---D upstream/master + + tree: + - [A, []] + - [B, [A]] + - [C, [A]] + - [D, [C]] + + branches: + head: [master, B] + upstream: [upstream/master, D] + + expected_changes: [B] diff --git a/git_upstream/tests/searchers/scenarios/changes_approved_after_import_merge.yaml b/git_upstream/tests/searchers/scenarios/changes_approved_after_import_merge.yaml new file mode 100644 index 0000000..e2b47fd --- /dev/null +++ b/git_upstream/tests/searchers/scenarios/changes_approved_after_import_merge.yaml @@ -0,0 +1,63 @@ +# +# Copyright (c) 2016 Hewlett-Packard Enterprise Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--- +- desc: | + Construct a repo layout where using a complex layout where a previous + import from upstream having been completed, test that if a change was + created on before the previous import was created, and merged to the + target branch and then the previous import merge commit was merged + with it, can we find the change correctly. + + i.e. will the searcher also include commit 'O' in the diagram below. + + Repository layout being tested + + O---- + / \ + B---C---D---H---I---J---K master + / \ / + / ----G + / / + / B1--C1--D1 import/next + / / + A---E---F---L---M upstream/master + + + tree: + - [A, []] + - [B, [A]] + - [C, [B]] + - [D, [C]] + - [E, [A]] + - [F, [E]] + - [B1, [F]] + - [C1, [B1]] + - [D1, [C1]] + - [G, [D, =D1]] + - [O, [C]] + - [H, [D, O]] + - [I, [H, G]] + - [J, [I]] + - [K, [J]] + - [L, [F]] + - [M, [L]] + + branches: + head: [master, K] + upstream: [upstream/master, M] + + expected_changes: [O, H, B1, C1, D1, G, I, J, K] diff --git a/git_upstream/tests/searchers/scenarios/changes_upload_prior_to_import.yaml b/git_upstream/tests/searchers/scenarios/changes_upload_prior_to_import.yaml new file mode 100644 index 0000000..141f978 --- /dev/null +++ b/git_upstream/tests/searchers/scenarios/changes_upload_prior_to_import.yaml @@ -0,0 +1,63 @@ +# +# Copyright (c) 2016 Hewlett-Packard Enterprise Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--- +- desc: | + Construct a repo layout where using a complex layout involving additional + branches having been included, and a previous import from upstream having + been completed, test that if a change was created on before the previous + import, and this change was merged to the target branch after the previous + import was merged, can we find it correctly. + + i.e. will the strategy also include commit 'O' in the diagram below. + + Repository layout being tested + + B-- + \ \ + \ \ O---------------- + \ \ / \ + C---D---E-------I---J---K---P---Q master + / \ / + / --H---D1--E1 + / / + A---F---G---L---M upstream/master + + tree: + - [A, []] + - [B, []] + - [C, [A, B]] + - [D, [C]] + - [E, [D]] + - [F, [A]] + - [G, [F]] + - [H, [G, B]] + - [D1, [H]] + - [E1, [D1]] + - [I, [E, =E1]] + - [J, [I]] + - [K, [J]] + - [L, [G]] + - [M, [L]] + - [O, [E]] + - [P, [K, O]] + - [Q, [P]] + + branches: + head: [master, Q] + upstream: [upstream/master, M] + + expected_changes: [H, D1, E1, I, J, K, O, P, Q] diff --git a/git_upstream/tests/searchers/scenarios/multi_changes_upload_prior_to_import.yaml b/git_upstream/tests/searchers/scenarios/multi_changes_upload_prior_to_import.yaml new file mode 100644 index 0000000..f78871d --- /dev/null +++ b/git_upstream/tests/searchers/scenarios/multi_changes_upload_prior_to_import.yaml @@ -0,0 +1,62 @@ +# +# Copyright (c) 2016 Hewlett-Packard Enterprise Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--- +- desc: | + Construct a repo layout where using a complex layout involving an additional + branch having been included, and a previous import from upstream completed + completed, test that if multiple changes were created on the mainline branch + before the previous import was created, and merged to the target branch + after the previous import, that we can find them correctly. + + i.e. will the strategy also include commits 'L' and 'J' from the diagram. + + Repository layout being tested + + B-- L------------- + \ \ / \ + \ \ / J--------- \ + \ \ / / \ \ + C---D---E-------I---K---M---O---P master + / \ / + / --H---D1--E1 + / / + A---F---G---Q---R upstream/master + + tree: + - [A, []] + - [B, []] + - [C, [A, B]] + - [D, [C]] + - [E, [D]] + - [F, [A]] + - [G, [F]] + - [H, [G, B]] + - [D1, [H]] + - [E1, [D1]] + - [I, [E, =E1]] + - [J, [E]] + - [K, [I, J]] + - [L, [D]] + - [M, [K, L]] + - [O, [M]] + - [P, [O]] + - [Q, [G]] + - [R, [Q]] + branches: + head: [master, P] + upstream: [upstream/master, R] + expected_changes: [H, D1, E1, I, J, K, L, M, O, P] diff --git a/git_upstream/tests/searchers/scenarios/old_style_merge_replace_first.yaml b/git_upstream/tests/searchers/scenarios/old_style_merge_replace_first.yaml new file mode 100644 index 0000000..dc405ad --- /dev/null +++ b/git_upstream/tests/searchers/scenarios/old_style_merge_replace_first.yaml @@ -0,0 +1,52 @@ +# +# Copyright (c) 2016 Hewlett-Packard Enterprise Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--- +- desc: | + Construct a repo layout using an old approach where the mainline would + be replaced with the upstream and then local changes replayed on top. + Check to see if we can correctly convert from this approach. + + Repository layout being tested + + B-----------G packaging + \ \ + C---D---E---H--D1--E1 master + / / + / / + / / + A---F-----------I---J upstream/master + + tree: + - [A, []] + - [B, []] + - [C, [A, B]] + - [D, [C]] + - [E, [D]] + - [F, [A]] + - [G, [B]] + - [H, [E, =F, =G]] + - [D1, [H]] + - [E1, [D1]] + - [I, [F]] + - [J, [I]] + + branches: + head: [master, E1] + upstream: [upstream/master, I] + packaging: [packaging, B] + + expected_changes: [H, D1, E1] diff --git a/git_upstream/tests/searchers/scenarios/switch_tracked_branches.yaml b/git_upstream/tests/searchers/scenarios/switch_tracked_branches.yaml new file mode 100644 index 0000000..3313f55 --- /dev/null +++ b/git_upstream/tests/searchers/scenarios/switch_tracked_branches.yaml @@ -0,0 +1,54 @@ +# +# Copyright (c) 2016 Hewlett-Packard Enterprise Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--- +- desc: | + Construct a repository layout where the upstream branch is switched, + after one import, and test that changes from the previous branch used, + 'upstream/stable', are not listed. This tests usage of the pattern + attribute. + + Repository layout being tested + + B-----------J master + / / + / B1 + / / + / E---I upstream/stable + / / + A---C---D---F---G---H upstream/master + + tree: + - [A, []] + - [B, [A]] + - [C, [A]] + - [D, [C]] + - [E, [D]] + - [F, [D]] + - [G, [F]] + - [H, [G]] + - [I, [E]] + - [B1, [I]] + - [J, [B, =B1]] + + branches: + head: [master, J] + stable: [upstream/stable, I] + upstream: [upstream/master, H] + + expected_changes: [B1, J] + + pattern: upstream/* diff --git a/git_upstream/tests/searchers/scenarios/switch_tracked_branches_incorrect.yaml b/git_upstream/tests/searchers/scenarios/switch_tracked_branches_incorrect.yaml new file mode 100644 index 0000000..f532616 --- /dev/null +++ b/git_upstream/tests/searchers/scenarios/switch_tracked_branches_incorrect.yaml @@ -0,0 +1,57 @@ +# +# Copyright (c) 2016 Hewlett-Packard Enterprise Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--- +- desc: | + Construct a repository layout where the upstream branch is switched + after an initial import, from 'upstream/stable' to 'upstream/master'. + Test that using the new branch as the search pattern forces changes + from 'upstream/stable' to be included. This is in contrast to the + test in `switch_tracked_branches`. + + This shows the additional changes that are picked up. + + Repository layout being tested + + B-----------J master + / / + / B1 + / / + / E---I upstream/stable + / / + A---C---D---F---G---H upstream/master + + tree: + - [A, []] + - [B, [A]] + - [C, [A]] + - [D, [C]] + - [E, [D]] + - [F, [D]] + - [G, [F]] + - [H, [G]] + - [I, [E]] + - [B1, [I]] + - [J, [B, =B1]] + + branches: + head: [master, J] + stable: [upstream/stable, I] + upstream: [upstream/master, H] + + expected_changes: [E, I, B1, J] + + pattern: upstream/master diff --git a/git_upstream/tests/searchers/test_searchers.py b/git_upstream/tests/searchers/test_searchers.py new file mode 100644 index 0000000..90a65e7 --- /dev/null +++ b/git_upstream/tests/searchers/test_searchers.py @@ -0,0 +1,54 @@ +# Copyright (c) 2014 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +from pprint import pformat + +from testscenarios import TestWithScenarios +from testtools.content import text_content + +from git_upstream.lib.searchers import UpstreamMergeBaseSearcher +from git_upstream.tests.base import BaseTestCase +from git_upstream.tests.base import get_scenarios + + +class TestUpstreamMergeBaseSearcher(TestWithScenarios, BaseTestCase): + + scenarios = get_scenarios(os.path.join(os.path.dirname(__file__), + "scenarios")) + + def setUp(self): + super(TestUpstreamMergeBaseSearcher, self).setUp() + + self.addDetail('description', text_content(self.desc)) + self._build_git_tree(self.tree, self.branches.values()) + + # need the tree built at this point + self.addDetail('expected-changes', + text_content(pformat( + list((c, self._graph[c].hexsha) + for c in self.expected_changes)))) + + def test_search_changes(self): + if getattr(self, 'pattern', None): + pattern = [self.pattern] + else: + pattern = None + + searcher = UpstreamMergeBaseSearcher(branch=self.branches['head'][0], + patterns=pattern, repo=self.repo) + self.assertEqual( + self._commits_from_nodes(reversed(self.expected_changes)), + searcher.list()) diff --git a/git_upstream/tests/test_searchers.py b/git_upstream/tests/test_searchers.py deleted file mode 100644 index 5a39144..0000000 --- a/git_upstream/tests/test_searchers.py +++ /dev/null @@ -1,410 +0,0 @@ -# Copyright (c) 2014 Hewlett-Packard Development Company, L.P. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from git_upstream.lib.searchers import UpstreamMergeBaseSearcher - -from base import BaseTestCase - - -class TestUpstreamMergeBaseSearcher(BaseTestCase): - - def _verify_expected(self, tree, branches, expected_nodes, pattern=None): - self._build_git_tree(tree, branches.values()) - - if pattern: - pattern = [pattern] - searcher = UpstreamMergeBaseSearcher(branch=branches['head'][0], - patterns=pattern, repo=self.repo) - - self.assertEqual(self._commits_from_nodes(reversed(expected_nodes)), - searcher.list()) - - def test_search_basic(self): - """Construct a basic repo layout and validate that locate changes - walker can find the expected changes. - - Repository layout being tested - - B master - / - A---C---D upstream/master - - """ - tree = [ - ('A', []), - ('B', ['A']), - ('C', ['A']), - ('D', ['C']) - ] - - branches = { - 'head': ('master', 'B'), - 'upstream': ('upstream/master', 'D'), - } - - expected_changes = ["B"] - self._verify_expected(tree, branches, expected_changes) - - def test_search_additional_branch(self): - """Construct a repo layout where previously an additional branch has - been included and validate that locate changes walker can find the - expected changes - - Repository layout being tested - - B example/packaging - \ - C---D---E master - / - A---F---G upstream/master - - """ - tree = [ - ('A', []), - ('B', []), - ('C', ['A', 'B']), - ('D', ['C']), - ('E', ['D']), - ('F', ['A']), - ('G', ['F']) - ] - - branches = { - 'head': ('master', 'E'), - 'upstream': ('upstream/master', 'G'), - } - - expected_changes = ["C", "D", "E"] - self._verify_expected(tree, branches, expected_changes) - - def test_search_old_style_merge_replace_first(self): - """Construct a repo layout using an old approach where the mainline - would be replaced with the upstream and then local changes replayed - on top. Check to see if we can correctly convert from this approach. - - Repository layout being tested - - B-----------G packaging - \ \ - C---D---E---H--D1--E1 master - / / - / / - / / - A---F-----------I---J upstream/master - - """ - tree = [ - ('A', []), - ('B', []), - ('C', ['A', 'B']), - ('D', ['C']), - ('E', ['D']), - ('F', ['A']), - ('G', ['B']), - ('H', ['E', '=F', '=G']), - ('D1', ['H']), - ('E1', ['D1']), - ('I', ['F']), - ('J', ['I']), - ] - - branches = { - 'head': ('master', 'E1'), - 'upstream': ('upstream/master', 'I'), - 'packaging': ('packaging', 'B') - } - - expected_changes = ["H", "D1", "E1"] - self._verify_expected(tree, branches, expected_changes) - - def test_search_additional_branch_multiple_imports(self): - """Construct a repo layout where previously an additional branch has - been included and validate that locate changes walker can find the - right changes after an additional import - - Repository layout being tested - - B-- example/packaging - \ \ - C---D---E-------I---J---K master - / \ / - / --H---D1--E1 import/next - / / - A---F---G---L---M upstream/master - - """ - tree = [ - ('A', []), - ('B', []), - ('C', ['A', 'B']), - ('D', ['C']), - ('E', ['D']), - ('F', ['A']), - ('G', ['F']), - ('H', ['G', 'B']), - ('D1', ['H']), - ('E1', ['D1']), - ('I', ['E', '=E1']), - ('J', ['I']), - ('K', ['J']), - ('L', ['G']), - ('M', ['L']) - ] - - branches = { - 'head': ('master', 'K'), - 'upstream': ('upstream/master', 'M'), - } - - expected_changes = ["H", "D1", "E1", "I", "J", "K"] - self._verify_expected(tree, branches, expected_changes) - - def test_search_changes_upload_prior_to_import(self): - """Construct a repo layout where using a complex layout involving - additional branches having been included, and a previous import from - upstream having been completed, test that if a change was created on - another branch before the previous import was created, and merged to - the target branch after the previous import, can we find it correctly. - i.e. will the strategy also include commit 'O' in the diagram below. - - Repository layout being tested - - B-- - \ \ - \ \ O---------------- - \ \ / \ - C---D---E-------I---J---K---P---Q master - / \ / - / --H---D1--E1 - / / - A---F---G---L---M upstream/master - - """ - - tree = [ - ('A', []), - ('B', []), - ('C', ['A', 'B']), - ('D', ['C']), - ('E', ['D']), - ('F', ['A']), - ('G', ['F']), - ('H', ['G', 'B']), - ('D1', ['H']), - ('E1', ['D1']), - ('I', ['E', '=E1']), - ('J', ['I']), - ('K', ['J']), - ('L', ['G']), - ('M', ['L']), - ('O', ['E']), - ('P', ['K', 'O']), - ('Q', ['P']) - ] - - branches = { - 'head': ('master', 'Q'), - 'upstream': ('upstream/master', 'M'), - } - - expected_changes = ["H", "D1", "E1", "I", "J", "K", "O", "P", "Q"] - self._verify_expected(tree, branches, expected_changes) - - def test_search_multi_changes_upload_prior_to_import(self): - """Construct a repo layout where using a complex layout involving - additional branches having been included, and a previous import from - upstream having been completed, test that if a change was created on - another branch before the previous import was created, and merged to - the target branch after the previous import, can we find it correctly. - i.e. will the strategy also include commit 'O' in the diagram below. - - Repository layout being tested - - B-- L------------- - \ \ / \ - \ \ / J--------- \ - \ \ / / \ \ - C---D---E-------I---K---M---O---P master - / \ / - / --H---D1--E1 - / / - A---F---G---Q---R upstream/master - - """ - - tree = [ - ('A', []), - ('B', []), - ('C', ['A', 'B']), - ('D', ['C']), - ('E', ['D']), - ('F', ['A']), - ('G', ['F']), - ('H', ['G', 'B']), - ('D1', ['H']), - ('E1', ['D1']), - ('I', ['E', '=E1']), - ('J', ['E']), - ('K', ['I', 'J']), - ('L', ['D']), - ('M', ['K', 'L']), - ('O', ['M']), - ('P', ['O']), - ('Q', ['G']), - ('R', ['Q']) - ] - - branches = { - 'head': ('master', 'P'), - 'upstream': ('upstream/master', 'R'), - } - - expected_changes = ["H", "D1", "E1", "I", "J", "K", "L", "M", "O", "P"] - self._verify_expected(tree, branches, expected_changes) - - def test_search_switch_tracked_branches(self): - """Search a repository layout where previously was tracking a - difference branch to the one that the user now wishes to import - - Repository layout being tested - - B-----------J master - / / - / B1 - / / - / E---I upstream/stable - / / - A---C---D---F---G---H upstream/master - - """ - - tree = [ - ('A', []), - ('B', ['A']), - ('C', ['A']), - ('D', ['C']), - ('E', ['D']), - ('F', ['D']), - ('G', ['F']), - ('H', ['G']), - ('I', ['E']), - ('B1', ['I']), - ('J', ['B', '=B1']) - ] - - branches = { - 'head': ('master', 'J'), - 'stable': ('upstream/stable', 'I'), - 'upstream': ('upstream/master', 'H') - } - - expected_changes = ['B1', 'J'] - self._verify_expected(tree, branches, expected_changes, - pattern="upstream/*") - - def test_search_switch_tracked_branches_incorrect(self): - """Search a repository layout where previously was tracking a - difference branch to the one that the user now wishes to import based - on using the new branch as the basis to search on. - - This shows the additional changes that are picked up by mistake - - Repository layout being tested - - B-----------J master - / / - / B1 - / / - / E---I upstream/stable - / / - A---C---D---F---G---H upstream/master - - """ - - tree = [ - ('A', []), - ('B', ['A']), - ('C', ['A']), - ('D', ['C']), - ('E', ['D']), - ('F', ['D']), - ('G', ['F']), - ('H', ['G']), - ('I', ['E']), - ('B1', ['I']), - ('J', ['B', '=B1']) - ] - - branches = { - 'head': ('master', 'J'), - 'stable': ('upstream/stable', 'I'), - 'upstream': ('upstream/master', 'H') - } - - expected_changes = ['E', 'I', 'B1', 'J'] - self._verify_expected(tree, branches, expected_changes, - pattern='upstream/master') - - def test_search_changes_approved_after_import_merge(self): - """Construct a repo layout where using a complex layout involving - additional branches having been included, and a previous import from - upstream having been completed, test that if a change was created on - another branch before the previous import was created, and merged to - the target branch before the previous import was merged, can we find - it correctly. - i.e. will the searcher also include commit 'O' in the diagram below. - - Repository layout being tested - - O---- - / \ - B---C---D---H---I---J---K master - / \ / - / ----G - / / - / B1--C1--D1 import/next - / / - A---E---F---L---M upstream/master - - """ - - tree = [ - ('A', []), - ('B', ['A']), - ('C', ['B']), - ('D', ['C']), - ('E', ['A']), - ('F', ['E']), - ('B1', ['F']), - ('C1', ['B1']), - ('D1', ['C1']), - ('G', ['D', '=D1']), - ('O', ['C']), - ('H', ['D', 'O']), - ('I', ['H', 'G']), - ('J', ['I']), - ('K', ['J']), - ('L', ['F']), - ('M', ['L']) - ] - - branches = { - 'head': ('master', 'K'), - 'upstream': ('upstream/master', 'M'), - } - - expected_changes = ["O", "H", "B1", "C1", "D1", "G", "I", "J", "K"] - self._verify_expected(tree, branches, expected_changes) diff --git a/test-requirements.txt b/test-requirements.txt index 99430f9..6db383b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,5 +6,7 @@ discover fixtures>=0.3.14 python-subunit testrepository>=0.0.17 +testscenarios>=0.4 testtools>=0.9.32 sphinxcontrib-programoutput +PyYAML>=3.1.0