Skip to content

Commit

Permalink
Use TestCase.addCleanup where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jimporter committed Dec 7, 2023
1 parent 7e5cabe commit bfc6fc1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
17 changes: 8 additions & 9 deletions test/unit/builtins/test_link.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
from unittest import mock

from .. import make_env
from .common import AttrDict, BuiltinTest

from bfg9000 import file_types, options as opts
from bfg9000.backends.make import syntax as make
from bfg9000.backends.msbuild.solution import Solution
from bfg9000.backends.ninja import syntax as ninja
from bfg9000.builtins import (compile, default, link, packages, # noqa: F401
project)
from bfg9000 import file_types, options as opts
from bfg9000.environment import LibraryMode
from bfg9000.iterutils import listify, unlistify
from bfg9000.packages import CommonPackage
from bfg9000.path import Path, Root
from bfg9000.tools.msvc import MsvcBuilder


class LinkTest(BuiltinTest):
Expand Down Expand Up @@ -938,18 +941,14 @@ def test_extra_deps(self):

class TestMsbuildBackend(BuiltinTest):
def setUp(self):
from .. import make_env
self.env = make_env('winnt', clear_variables=True,
variables={'CXX': 'nonexist'})
self.build, self.context = self._make_context(self.env)

from bfg9000.tools.msvc import MsvcBuilder
self.patch_builder = mock.patch('bfg9000.tools.c_family._builders',
(MsvcBuilder,))
self.patch_builder.start()

def tearDown(self):
self.patch_builder.stop()
patch_builder = mock.patch('bfg9000.tools.c_family._builders',
(MsvcBuilder,))
patch_builder.start()
self.addCleanup(patch_builder.stop)

def assertSubdict(self, actual, expected):
subdict = {k: v for k, v in actual.items() if k in expected}
Expand Down
7 changes: 3 additions & 4 deletions test/unit/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ def setUp(self):
self.logger = log.getLogger('bfg9000.test.unit')
self.logger.propagate = False
log._init_logging(self.logger, debug=False, stream=self.stream)
self.patch_logger = mock.patch('bfg9000.driver.logger', self.logger)
self.patch_logger.start()

def tearDown(self):
self.patch_logger.stop()
patch_logger = mock.patch('bfg9000.driver.logger', self.logger)
patch_logger.start()
self.addCleanup(patch_logger.stop)

def test_message(self):
try:
Expand Down

0 comments on commit bfc6fc1

Please sign in to comment.