diff options
| author | Mike Frysinger <vapier@google.com> | 2022-12-08 08:55:54 -0500 |
|---|---|---|
| committer | Mike Frysinger <vapier@google.com> | 2022-12-08 22:22:39 +0000 |
| commit | e81528649236ec9fb5983191767a96dc30acff54 (patch) | |
| tree | 74b288fe316d673595a8eaf56e5270d4d41b224f /tests | |
| parent | 0ab6b1168811586b62d8d1c26bad118b0a4b3807 (diff) | |
| download | git-repo-e81528649236ec9fb5983191767a96dc30acff54.tar.gz | |
tests: clean up repo_trace._TRACE_FILE patching
Patch this automatically for all tests rather than duplicating the
boilerplate in diff testcases.
Change-Id: I391d5c859974cda3d5680d34ede2ce6e9e925838
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/354358
Reviewed-by: Joanna Wang <jojwang@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/conftest.py | 25 | ||||
| -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 | 2 | ||||
| -rw-r--r-- | tests/test_project.py | 10 |
5 files changed, 25 insertions, 28 deletions
diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..3e43f6d3 --- /dev/null +++ b/tests/conftest.py | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | # Copyright 2022 The Android Open Source Project | ||
| 2 | # | ||
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | # you may not use this file except in compliance with the License. | ||
| 5 | # You may obtain a copy of the License at | ||
| 6 | # | ||
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | # | ||
| 9 | # Unless required by applicable law or agreed to in writing, software | ||
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | # See the License for the specific language governing permissions and | ||
| 13 | # limitations under the License. | ||
| 14 | |||
| 15 | """Common fixtures for pytests.""" | ||
| 16 | |||
| 17 | import pytest | ||
| 18 | |||
| 19 | import repo_trace | ||
| 20 | |||
| 21 | |||
| 22 | @pytest.fixture(autouse=True) | ||
| 23 | def disable_repo_trace(tmp_path): | ||
| 24 | """Set an environment marker to relax certain strict checks for test code.""" | ||
| 25 | repo_trace._TRACE_FILE = str(tmp_path / 'TRACE_FILE_from_test') | ||
diff --git a/tests/test_git_config.py b/tests/test_git_config.py index 63c148f3..3b0aa8b4 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 1425f4ce..225e98c2 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 c7e814a3..3634701f 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( |
diff --git a/tests/test_project.py b/tests/test_project.py index 7ab44984..66c05f6a 100644 --- a/tests/test_project.py +++ b/tests/test_project.py | |||
| @@ -27,7 +27,6 @@ import git_command | |||
| 27 | import git_config | 27 | import git_config |
| 28 | import platform_utils | 28 | import platform_utils |
| 29 | import project | 29 | import project |
| 30 | import repo_trace | ||
| 31 | 30 | ||
| 32 | 31 | ||
| 33 | @contextlib.contextmanager | 32 | @contextlib.contextmanager |
| @@ -66,13 +65,6 @@ class FakeProject(object): | |||
| 66 | class ReviewableBranchTests(unittest.TestCase): | 65 | class ReviewableBranchTests(unittest.TestCase): |
| 67 | """Check ReviewableBranch behavior.""" | 66 | """Check ReviewableBranch behavior.""" |
| 68 | 67 | ||
| 69 | def setUp(self): | ||
| 70 | self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests') | ||
| 71 | repo_trace._TRACE_FILE = os.path.join(self.tempdirobj.name, 'TRACE_FILE_from_test') | ||
| 72 | |||
| 73 | def tearDown(self): | ||
| 74 | self.tempdirobj.cleanup() | ||
| 75 | |||
| 76 | def test_smoke(self): | 68 | def test_smoke(self): |
| 77 | """A quick run through everything.""" | 69 | """A quick run through everything.""" |
| 78 | with TempGitTree() as tempdir: | 70 | with TempGitTree() as tempdir: |
| @@ -418,8 +410,6 @@ class ManifestPropertiesFetchedCorrectly(unittest.TestCase): | |||
| 418 | """Ensure properties are fetched properly.""" | 410 | """Ensure properties are fetched properly.""" |
| 419 | 411 | ||
| 420 | def setUpManifest(self, tempdir): | 412 | def setUpManifest(self, tempdir): |
| 421 | repo_trace._TRACE_FILE = os.path.join(tempdir, 'TRACE_FILE_from_test') | ||
| 422 | |||
| 423 | repodir = os.path.join(tempdir, '.repo') | 413 | repodir = os.path.join(tempdir, '.repo') |
| 424 | manifest_dir = os.path.join(repodir, 'manifests') | 414 | manifest_dir = os.path.join(repodir, 'manifests') |
| 425 | manifest_file = os.path.join( | 415 | manifest_file = os.path.join( |
