summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py25
-rw-r--r--tests/test_git_config.py14
-rw-r--r--tests/test_git_superproject.py2
-rw-r--r--tests/test_manifest_xml.py2
-rw-r--r--tests/test_project.py10
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
17import pytest
18
19import repo_trace
20
21
22@pytest.fixture(autouse=True)
23def 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
19import unittest 19import unittest
20 20
21import git_config 21import git_config
22import repo_trace
23 22
24 23
25def fixture(*paths): 24def 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
24import git_superproject 24import git_superproject
25import git_trace2_event_log 25import git_trace2_event_log
26import manifest_xml 26import manifest_xml
27import repo_trace
28from test_manifest_xml import sort_attributes 27from 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
24import error 24import error
25import manifest_xml 25import manifest_xml
26import 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
27import git_config 27import git_config
28import platform_utils 28import platform_utils
29import project 29import project
30import repo_trace
31 30
32 31
33@contextlib.contextmanager 32@contextlib.contextmanager
@@ -66,13 +65,6 @@ class FakeProject(object):
66class ReviewableBranchTests(unittest.TestCase): 65class 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(