mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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>
This commit is contained in:
parent
0ab6b11688
commit
e815286492
@ -20,7 +20,6 @@ import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import repo_trace
|
||||
|
||||
|
||||
def find_pytest():
|
||||
|
25
tests/conftest.py
Normal file
25
tests/conftest.py
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright 2022 The Android Open Source Project
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""Common fixtures for pytests."""
|
||||
|
||||
import pytest
|
||||
|
||||
import repo_trace
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def disable_repo_trace(tmp_path):
|
||||
"""Set an environment marker to relax certain strict checks for test code."""
|
||||
repo_trace._TRACE_FILE = str(tmp_path / 'TRACE_FILE_from_test')
|
@ -19,7 +19,6 @@ import tempfile
|
||||
import unittest
|
||||
|
||||
import git_config
|
||||
import repo_trace
|
||||
|
||||
|
||||
def fixture(*paths):
|
||||
@ -34,16 +33,9 @@ class GitConfigReadOnlyTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
"""Create a GitConfig object using the test.gitconfig fixture.
|
||||
"""
|
||||
|
||||
self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests')
|
||||
repo_trace._TRACE_FILE = os.path.join(self.tempdirobj.name, 'TRACE_FILE_from_test')
|
||||
|
||||
config_fixture = fixture('test.gitconfig')
|
||||
self.config = git_config.GitConfig(config_fixture)
|
||||
|
||||
def tearDown(self):
|
||||
self.tempdirobj.cleanup()
|
||||
|
||||
def test_GetString_with_empty_config_values(self):
|
||||
"""
|
||||
Test config entries with no value.
|
||||
@ -117,15 +109,9 @@ class GitConfigReadWriteTests(unittest.TestCase):
|
||||
"""Read/write tests of the GitConfig class."""
|
||||
|
||||
def setUp(self):
|
||||
self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests')
|
||||
repo_trace._TRACE_FILE = os.path.join(self.tempdirobj.name, 'TRACE_FILE_from_test')
|
||||
|
||||
self.tmpfile = tempfile.NamedTemporaryFile()
|
||||
self.config = self.get_config()
|
||||
|
||||
def tearDown(self):
|
||||
self.tempdirobj.cleanup()
|
||||
|
||||
def get_config(self):
|
||||
"""Get a new GitConfig instance."""
|
||||
return git_config.GitConfig(self.tmpfile.name)
|
||||
|
@ -24,7 +24,6 @@ from unittest import mock
|
||||
import git_superproject
|
||||
import git_trace2_event_log
|
||||
import manifest_xml
|
||||
import repo_trace
|
||||
from test_manifest_xml import sort_attributes
|
||||
|
||||
|
||||
@ -40,7 +39,6 @@ class SuperprojectTestCase(unittest.TestCase):
|
||||
"""Set up superproject every time."""
|
||||
self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests')
|
||||
self.tempdir = self.tempdirobj.name
|
||||
repo_trace._TRACE_FILE = os.path.join(self.tempdir, 'TRACE_FILE_from_test')
|
||||
self.repodir = os.path.join(self.tempdir, '.repo')
|
||||
self.manifest_file = os.path.join(
|
||||
self.repodir, manifest_xml.MANIFEST_FILE_NAME)
|
||||
|
@ -23,7 +23,6 @@ import xml.dom.minidom
|
||||
|
||||
import error
|
||||
import manifest_xml
|
||||
import repo_trace
|
||||
|
||||
|
||||
# Invalid paths that we don't want in the filesystem.
|
||||
@ -94,7 +93,6 @@ class ManifestParseTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests')
|
||||
self.tempdir = self.tempdirobj.name
|
||||
repo_trace._TRACE_FILE = os.path.join(self.tempdir, 'TRACE_FILE_from_test')
|
||||
self.repodir = os.path.join(self.tempdir, '.repo')
|
||||
self.manifest_dir = os.path.join(self.repodir, 'manifests')
|
||||
self.manifest_file = os.path.join(
|
||||
|
@ -27,7 +27,6 @@ import git_command
|
||||
import git_config
|
||||
import platform_utils
|
||||
import project
|
||||
import repo_trace
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
@ -66,13 +65,6 @@ class FakeProject(object):
|
||||
class ReviewableBranchTests(unittest.TestCase):
|
||||
"""Check ReviewableBranch behavior."""
|
||||
|
||||
def setUp(self):
|
||||
self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests')
|
||||
repo_trace._TRACE_FILE = os.path.join(self.tempdirobj.name, 'TRACE_FILE_from_test')
|
||||
|
||||
def tearDown(self):
|
||||
self.tempdirobj.cleanup()
|
||||
|
||||
def test_smoke(self):
|
||||
"""A quick run through everything."""
|
||||
with TempGitTree() as tempdir:
|
||||
@ -418,8 +410,6 @@ class ManifestPropertiesFetchedCorrectly(unittest.TestCase):
|
||||
"""Ensure properties are fetched properly."""
|
||||
|
||||
def setUpManifest(self, tempdir):
|
||||
repo_trace._TRACE_FILE = os.path.join(tempdir, 'TRACE_FILE_from_test')
|
||||
|
||||
repodir = os.path.join(tempdir, '.repo')
|
||||
manifest_dir = os.path.join(repodir, 'manifests')
|
||||
manifest_file = os.path.join(
|
||||
|
Loading…
Reference in New Issue
Block a user