Esempio n. 1
0
def create_patch(test_case: unittest.TestCase, *args, **kwargs) -> Any:
    """Wrap asynctest.patch such that it will be unpatched as part of test case cleanup."""
    patcher = asynctest.patch(*args, **kwargs)
    mock_obj = patcher.start()
    test_case.addCleanup(patcher.stop)
    return mock_obj
Esempio n. 2
0
def use_cm(cm_factory: Callable[[], ContextManager[_T]],
           testcase: TestCase) -> _T:
    cm = cm_factory()
    ret = cm.__enter__()
    testcase.addCleanup(cm.__exit__, None, None, None)
    return ret
Esempio n. 3
0
def setup_data_path(test_class: TestCase):
    test_class.addCleanup(mock.patch.stopall)
    mock.patch("tools.bots.pi._DATA_PATH", _DATA_PATH_TEST).start()
    _remove_data_folder()
    os.mkdir(_DATA_PATH_TEST)
Esempio n. 4
0
def setup_with_context_manager(testcase: unittest.TestCase, cm: Any) -> Any:
    """Use a contextmanager to setUp a test case."""
    val = cm.__enter__()
    testcase.addCleanup(cm.__exit__, None, None, None)
    return val
Esempio n. 5
0
def setup_data_path(test_class: TestCase):
    test_class.addCleanup(mock.patch.stopall)
    mock.patch("tools.bots._DATA_PATH", _DATA_PATH_TEST).start()
    _remove_data_folder()
    os.mkdir(_DATA_PATH_TEST)