Set the flag for the test mode of generator even in test runner process

So that its functions behave identically regardless of how being invoked: either
by importing the module directly or launching generator in a separate process.

GitOrigin-RevId: a4e513a851faece624b8133cba2068a6b0e5ce82
This commit is contained in:
Mikhail Golubev
2019-06-10 22:09:47 +03:00
committed by intellij-monorepo-bot
parent defc680bb1
commit 513e5d6cda
2 changed files with 10 additions and 4 deletions
@@ -7,6 +7,8 @@ import unittest
from contextlib import contextmanager
from io import open
from pycharm_generator_utils.constants import ENV_TEST_MODE_FLAG
_test_dir = os.path.dirname(__file__)
_test_data_root_dir = os.path.join(_test_dir, 'data')
_override_test_data = False
@@ -27,8 +29,12 @@ class GeneratorTestCase(unittest.TestCase):
cls.log.addHandler(handler)
cls.log.setLevel(logging.DEBUG)
os.environ[ENV_TEST_MODE_FLAG] = 'True'
@classmethod
def tearDownClass(cls):
os.environ.pop(ENV_TEST_MODE_FLAG)
delattr(cls, 'log')
super(GeneratorTestCase, cls).tearDownClass()
@@ -125,11 +125,11 @@ class SkeletonCachingTest(GeneratorTestCase):
_ast.py
sdk_skeletons/
_ast.py
""".format(hash=generator3.builtin_module_hash('_ast')[:10]))
""".format(hash=generator3.module_hash('_ast', None)))
def test_builtins_generation_mode_stores_all_skeletons_in_same_cache_directory(self):
self.run_generator(builtins=True)
builtins_hash = generator3.builtin_module_hash('sys')[:10]
builtins_hash = generator3.module_hash('sys', None)
builtins_cache_dir = os.path.join(self.temp_cache_dir, builtins_hash)
self.assertTrue(os.path.isdir(builtins_cache_dir))
builtin_mod_skeletons = os.listdir(builtins_cache_dir)
@@ -145,7 +145,7 @@ class SkeletonCachingTest(GeneratorTestCase):
mod.py
sdk_skeletons/
mod.py
""".format(hash=generator3.physical_module_hash(mod_path)[:10]))
""".format(hash=generator3.module_hash('mod', mod_path)))
def test_layout_for_physical_module_inside_package(self):
mod_path = self.get_test_data_path('pkg/subpkg/mod.py')
@@ -164,7 +164,7 @@ class SkeletonCachingTest(GeneratorTestCase):
subpkg/
__init__.py
mod.py
""".format(hash=generator3.physical_module_hash(mod_path)[:10]))
""".format(hash=generator3.module_hash('mod', mod_path)))
def test_skeleton_regenerated_for_changed_module(self):
self.check_generator_output('mod', mod_path='mod.py', mod_root='versions/v2')