diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_git_config.py | 14 | ||||
-rw-r--r-- | tests/test_git_superproject.py | 2 | ||||
-rw-r--r-- | tests/test_manifest_xml.py | 16 | ||||
-rw-r--r-- | tests/test_project.py | 8 | ||||
-rw-r--r-- | tests/test_subcmds_sync.py | 55 |
5 files changed, 14 insertions, 81 deletions
diff --git a/tests/test_git_config.py b/tests/test_git_config.py index 0df38430..a4fad9ef 100644 --- a/tests/test_git_config.py +++ b/tests/test_git_config.py | |||
@@ -19,7 +19,6 @@ import tempfile | |||
19 | import unittest | 19 | import unittest |
20 | 20 | ||
21 | import git_config | 21 | import git_config |
22 | import repo_trace | ||
23 | 22 | ||
24 | 23 | ||
25 | def fixture(*paths): | 24 | def fixture(*paths): |
@@ -34,16 +33,9 @@ class GitConfigReadOnlyTests(unittest.TestCase): | |||
34 | def setUp(self): | 33 | def setUp(self): |
35 | """Create a GitConfig object using the test.gitconfig fixture. | 34 | """Create a GitConfig object using the test.gitconfig fixture. |
36 | """ | 35 | """ |
37 | |||
38 | self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests') | ||
39 | repo_trace._TRACE_FILE = os.path.join(self.tempdirobj.name, 'TRACE_FILE_from_test') | ||
40 | |||
41 | config_fixture = fixture('test.gitconfig') | 36 | config_fixture = fixture('test.gitconfig') |
42 | self.config = git_config.GitConfig(config_fixture) | 37 | self.config = git_config.GitConfig(config_fixture) |
43 | 38 | ||
44 | def tearDown(self): | ||
45 | self.tempdirobj.cleanup() | ||
46 | |||
47 | def test_GetString_with_empty_config_values(self): | 39 | def test_GetString_with_empty_config_values(self): |
48 | """ | 40 | """ |
49 | Test config entries with no value. | 41 | Test config entries with no value. |
@@ -117,15 +109,9 @@ class GitConfigReadWriteTests(unittest.TestCase): | |||
117 | """Read/write tests of the GitConfig class.""" | 109 | """Read/write tests of the GitConfig class.""" |
118 | 110 | ||
119 | def setUp(self): | 111 | def setUp(self): |
120 | self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests') | ||
121 | repo_trace._TRACE_FILE = os.path.join(self.tempdirobj.name, 'TRACE_FILE_from_test') | ||
122 | |||
123 | self.tmpfile = tempfile.NamedTemporaryFile() | 112 | self.tmpfile = tempfile.NamedTemporaryFile() |
124 | self.config = self.get_config() | 113 | self.config = self.get_config() |
125 | 114 | ||
126 | def tearDown(self): | ||
127 | self.tempdirobj.cleanup() | ||
128 | |||
129 | def get_config(self): | 115 | def get_config(self): |
130 | """Get a new GitConfig instance.""" | 116 | """Get a new GitConfig instance.""" |
131 | return git_config.GitConfig(self.tmpfile.name) | 117 | return git_config.GitConfig(self.tmpfile.name) |
diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py index 0bb77185..0ad9b01d 100644 --- a/tests/test_git_superproject.py +++ b/tests/test_git_superproject.py | |||
@@ -24,7 +24,6 @@ from unittest import mock | |||
24 | import git_superproject | 24 | import git_superproject |
25 | import git_trace2_event_log | 25 | import git_trace2_event_log |
26 | import manifest_xml | 26 | import manifest_xml |
27 | import repo_trace | ||
28 | from test_manifest_xml import sort_attributes | 27 | from test_manifest_xml import sort_attributes |
29 | 28 | ||
30 | 29 | ||
@@ -40,7 +39,6 @@ class SuperprojectTestCase(unittest.TestCase): | |||
40 | """Set up superproject every time.""" | 39 | """Set up superproject every time.""" |
41 | self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests') | 40 | self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests') |
42 | self.tempdir = self.tempdirobj.name | 41 | self.tempdir = self.tempdirobj.name |
43 | repo_trace._TRACE_FILE = os.path.join(self.tempdir, 'TRACE_FILE_from_test') | ||
44 | self.repodir = os.path.join(self.tempdir, '.repo') | 42 | self.repodir = os.path.join(self.tempdir, '.repo') |
45 | self.manifest_file = os.path.join( | 43 | self.manifest_file = os.path.join( |
46 | self.repodir, manifest_xml.MANIFEST_FILE_NAME) | 44 | self.repodir, manifest_xml.MANIFEST_FILE_NAME) |
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index f92108e1..e181b642 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py | |||
@@ -23,7 +23,6 @@ import xml.dom.minidom | |||
23 | 23 | ||
24 | import error | 24 | import error |
25 | import manifest_xml | 25 | import manifest_xml |
26 | import repo_trace | ||
27 | 26 | ||
28 | 27 | ||
29 | # Invalid paths that we don't want in the filesystem. | 28 | # Invalid paths that we don't want in the filesystem. |
@@ -94,7 +93,6 @@ class ManifestParseTestCase(unittest.TestCase): | |||
94 | def setUp(self): | 93 | def setUp(self): |
95 | self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests') | 94 | self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests') |
96 | self.tempdir = self.tempdirobj.name | 95 | self.tempdir = self.tempdirobj.name |
97 | repo_trace._TRACE_FILE = os.path.join(self.tempdir, 'TRACE_FILE_from_test') | ||
98 | self.repodir = os.path.join(self.tempdir, '.repo') | 96 | self.repodir = os.path.join(self.tempdir, '.repo') |
99 | self.manifest_dir = os.path.join(self.repodir, 'manifests') | 97 | self.manifest_dir = os.path.join(self.repodir, 'manifests') |
100 | self.manifest_file = os.path.join( | 98 | self.manifest_file = os.path.join( |
@@ -264,10 +262,10 @@ class XmlManifestTests(ManifestParseTestCase): | |||
264 | '<project name="r" groups="keep"/>' | 262 | '<project name="r" groups="keep"/>' |
265 | '</manifest>') | 263 | '</manifest>') |
266 | self.assertEqual( | 264 | self.assertEqual( |
267 | sort_attributes(manifest.ToXml(omit_local=True).toxml()), | 265 | manifest.ToXml(omit_local=True).toxml(), |
268 | '<?xml version="1.0" ?><manifest>' | 266 | '<?xml version="1.0" ?><manifest>' |
269 | '<remote fetch=".." name="a"/><default remote="a" revision="r"/>' | 267 | '<remote name="a" fetch=".."/><default remote="a" revision="r"/>' |
270 | '<project name="q"/><project groups="keep" name="r"/></manifest>') | 268 | '<project name="q"/><project name="r" groups="keep"/></manifest>') |
271 | 269 | ||
272 | def test_toxml_with_local(self): | 270 | def test_toxml_with_local(self): |
273 | """Does include local_manifests projects when omit_local=False.""" | 271 | """Does include local_manifests projects when omit_local=False.""" |
@@ -279,11 +277,11 @@ class XmlManifestTests(ManifestParseTestCase): | |||
279 | '<project name="r" groups="keep"/>' | 277 | '<project name="r" groups="keep"/>' |
280 | '</manifest>') | 278 | '</manifest>') |
281 | self.assertEqual( | 279 | self.assertEqual( |
282 | sort_attributes(manifest.ToXml(omit_local=False).toxml()), | 280 | manifest.ToXml(omit_local=False).toxml(), |
283 | '<?xml version="1.0" ?><manifest>' | 281 | '<?xml version="1.0" ?><manifest>' |
284 | '<remote fetch=".." name="a"/><default remote="a" revision="r"/>' | 282 | '<remote name="a" fetch=".."/><default remote="a" revision="r"/>' |
285 | '<project groups="local::me" name="p"/>' | 283 | '<project name="p" groups="local::me"/>' |
286 | '<project name="q"/><project groups="keep" name="r"/></manifest>') | 284 | '<project name="q"/><project name="r" groups="keep"/></manifest>') |
287 | 285 | ||
288 | def test_repo_hooks(self): | 286 | def test_repo_hooks(self): |
289 | """Check repo-hooks settings.""" | 287 | """Check repo-hooks settings.""" |
diff --git a/tests/test_project.py b/tests/test_project.py index 5c600be7..acd44ccc 100644 --- a/tests/test_project.py +++ b/tests/test_project.py | |||
@@ -26,7 +26,6 @@ import git_command | |||
26 | import git_config | 26 | import git_config |
27 | import platform_utils | 27 | import platform_utils |
28 | import project | 28 | import project |
29 | import repo_trace | ||
30 | 29 | ||
31 | 30 | ||
32 | @contextlib.contextmanager | 31 | @contextlib.contextmanager |
@@ -65,13 +64,6 @@ class FakeProject(object): | |||
65 | class ReviewableBranchTests(unittest.TestCase): | 64 | class ReviewableBranchTests(unittest.TestCase): |
66 | """Check ReviewableBranch behavior.""" | 65 | """Check ReviewableBranch behavior.""" |
67 | 66 | ||
68 | def setUp(self): | ||
69 | self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests') | ||
70 | repo_trace._TRACE_FILE = os.path.join(self.tempdirobj.name, 'TRACE_FILE_from_test') | ||
71 | |||
72 | def tearDown(self): | ||
73 | self.tempdirobj.cleanup() | ||
74 | |||
75 | def test_smoke(self): | 67 | def test_smoke(self): |
76 | """A quick run through everything.""" | 68 | """A quick run through everything.""" |
77 | with TempGitTree() as tempdir: | 69 | with TempGitTree() as tempdir: |
diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py index 13f3f873..aad713f2 100644 --- a/tests/test_subcmds_sync.py +++ b/tests/test_subcmds_sync.py | |||
@@ -11,9 +11,9 @@ | |||
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | # See the License for the specific language governing permissions and | 12 | # See the License for the specific language governing permissions and |
13 | # limitations under the License. | 13 | # limitations under the License. |
14 | |||
14 | """Unittests for the subcmds/sync.py module.""" | 15 | """Unittests for the subcmds/sync.py module.""" |
15 | 16 | ||
16 | import unittest | ||
17 | from unittest import mock | 17 | from unittest import mock |
18 | 18 | ||
19 | import pytest | 19 | import pytest |
@@ -21,14 +21,17 @@ import pytest | |||
21 | from subcmds import sync | 21 | from subcmds import sync |
22 | 22 | ||
23 | 23 | ||
24 | @pytest.mark.parametrize('use_superproject, cli_args, result', [ | 24 | @pytest.mark.parametrize( |
25 | 'use_superproject, cli_args, result', | ||
26 | [ | ||
25 | (True, ['--current-branch'], True), | 27 | (True, ['--current-branch'], True), |
26 | (True, ['--no-current-branch'], True), | 28 | (True, ['--no-current-branch'], True), |
27 | (True, [], True), | 29 | (True, [], True), |
28 | (False, ['--current-branch'], True), | 30 | (False, ['--current-branch'], True), |
29 | (False, ['--no-current-branch'], False), | 31 | (False, ['--no-current-branch'], False), |
30 | (False, [], None), | 32 | (False, [], None), |
31 | ]) | 33 | ] |
34 | ) | ||
32 | def test_get_current_branch_only(use_superproject, cli_args, result): | 35 | def test_get_current_branch_only(use_superproject, cli_args, result): |
33 | """Test Sync._GetCurrentBranchOnly logic. | 36 | """Test Sync._GetCurrentBranchOnly logic. |
34 | 37 | ||
@@ -38,49 +41,5 @@ def test_get_current_branch_only(use_superproject, cli_args, result): | |||
38 | cmd = sync.Sync() | 41 | cmd = sync.Sync() |
39 | opts, _ = cmd.OptionParser.parse_args(cli_args) | 42 | opts, _ = cmd.OptionParser.parse_args(cli_args) |
40 | 43 | ||
41 | with mock.patch('git_superproject.UseSuperproject', | 44 | with mock.patch('git_superproject.UseSuperproject', return_value=use_superproject): |
42 | return_value=use_superproject): | ||
43 | assert cmd._GetCurrentBranchOnly(opts, cmd.manifest) == result | 45 | assert cmd._GetCurrentBranchOnly(opts, cmd.manifest) == result |
44 | |||
45 | |||
46 | class GetPreciousObjectsState(unittest.TestCase): | ||
47 | """Tests for _GetPreciousObjectsState.""" | ||
48 | |||
49 | def setUp(self): | ||
50 | """Common setup.""" | ||
51 | self.cmd = sync.Sync() | ||
52 | self.project = p = mock.MagicMock(use_git_worktrees=False, | ||
53 | UseAlternates=False) | ||
54 | p.manifest.GetProjectsWithName.return_value = [p] | ||
55 | |||
56 | self.opt = mock.Mock(spec_set=['this_manifest_only']) | ||
57 | self.opt.this_manifest_only = False | ||
58 | |||
59 | def test_worktrees(self): | ||
60 | """False for worktrees.""" | ||
61 | self.project.use_git_worktrees = True | ||
62 | self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt)) | ||
63 | |||
64 | def test_not_shared(self): | ||
65 | """Singleton project.""" | ||
66 | self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt)) | ||
67 | |||
68 | def test_shared(self): | ||
69 | """Shared project.""" | ||
70 | self.project.manifest.GetProjectsWithName.return_value = [ | ||
71 | self.project, self.project | ||
72 | ] | ||
73 | self.assertTrue(self.cmd._GetPreciousObjectsState(self.project, self.opt)) | ||
74 | |||
75 | def test_shared_with_alternates(self): | ||
76 | """Shared project, with alternates.""" | ||
77 | self.project.manifest.GetProjectsWithName.return_value = [ | ||
78 | self.project, self.project | ||
79 | ] | ||
80 | self.project.UseAlternates = True | ||
81 | self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt)) | ||
82 | |||
83 | def test_not_found(self): | ||
84 | """Project not found in manifest.""" | ||
85 | self.project.manifest.GetProjectsWithName.return_value = [] | ||
86 | self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt)) | ||