def test_folder_handler(): with temp_value_setting.TempValueSetter((cute_profile.profile_handling, 'threading'), dummy_threading): with temp_file_tools.TemporaryFolder(suffix='_python_toolbox_testing')\ as temp_folder: f = cute_profile.profile_ready(profile_handler=temp_folder)(func) f(1, 2) assert len(os.listdir(temp_folder)) == 0 f(1, 2) assert len(os.listdir(temp_folder)) == 0 f.profiling_on = True f(1, 2) assert len(os.listdir(temp_folder)) == 1 f(1, 2) assert len(os.listdir(temp_folder)) == 1 time.sleep(0.01) # To make for a different filename. f.profiling_on = True f(1, 2) assert len(os.listdir(temp_folder)) == 2 f(1, 2) assert len(os.listdir(temp_folder)) == 2
def test_polite_wrapper(): ''' Test that `profile_ready` decorator produces a polite function wrapper. e.g. that the name, documentation and signature of the original function are used in the wrapper function, and a few other things. ''' cute_testing.assert_polite_wrapper( cute_profile.profile_ready()(func), func )
def test_simple(): '''Test the basic workings of `profile_ready`.''' f = cute_profile.profile_ready()(func) assert call_and_check_if_profiled(lambda: f(1, 2)) is False assert call_and_check_if_profiled(lambda: f(1, 2)) is False f.profiling_on = True assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is False f = cute_profile.profile_ready(condition=True)(func) assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is False f.profiling_on = False assert call_and_check_if_profiled(lambda: f(1, 2)) is False assert call_and_check_if_profiled(lambda: f(1, 2)) is False f = cute_profile.profile_ready(condition=True, off_after=False)(func) assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is True f.profiling_on = True assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is True f = cute_profile.profile_ready(off_after=True)(func) assert call_and_check_if_profiled(lambda: f(1, 2)) is False assert call_and_check_if_profiled(lambda: f(1, 2)) is False f.profiling_on = True assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is False assert call_and_check_if_profiled(lambda: f(1, 2)) is False f.profiling_on = True assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is False assert call_and_check_if_profiled(lambda: f(1, 2)) is False f.condition = lambda f, *args, **kwargs: True assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is False assert call_and_check_if_profiled(lambda: f(1, 2)) is False
def test_simple(): '''Test the basic workings of `profile_ready`.''' f = cute_profile.profile_ready()(func) assert call_and_check_if_profiled(lambda: f(1, 2)) is False assert call_and_check_if_profiled(lambda: f(1, 2)) is False f.profiling_on = True assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is False f = cute_profile.profile_ready(condition=True)(func) assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is False f.profiling_on = False assert call_and_check_if_profiled(lambda: f(1, 2)) is False assert call_and_check_if_profiled(lambda: f(1, 2)) is False f = cute_profile.profile_ready(condition=True, off_after=False)(func) assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is True f.profiling_on = True assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is True f = cute_profile.profile_ready(off_after=True)(func) assert call_and_check_if_profiled(lambda: f(1, 2)) is False assert call_and_check_if_profiled(lambda: f(1, 2)) is False f.profiling_on = True assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is False assert call_and_check_if_profiled(lambda: f(1, 2)) is False f.profiling_on = True assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is False assert call_and_check_if_profiled(lambda: f(1, 2)) is False f.condition = lambda f, *args, **kwargs: True assert call_and_check_if_profiled(lambda: f(1, 2)) is True assert call_and_check_if_profiled(lambda: f(1, 2)) is False assert call_and_check_if_profiled(lambda: f(1, 2)) is False