def test_unavailable_source(): with temp_file_tools.create_temp_folder(prefix='pysnooper') as folder, \ sys_tools.TempSysPathAdder(str(folder)): module_name = 'iaerojajsijf' python_file_path = folder / ('%s.py' % (module_name, )) content = textwrap.dedent(u''' import pysnooper @pysnooper.snoop() def f(x): return x ''') with python_file_path.open('w') as python_file: python_file.write(content) module = __import__(module_name) python_file_path.unlink() with sys_tools.OutputCapturer(stdout=False, stderr=True) as output_capturer: result = getattr(module, 'f')(7) assert result == 7 output = output_capturer.output assert_output(output, ( VariableEntry(stage='starting'), CallEntry('SOURCE IS UNAVAILABLE'), LineEntry('SOURCE IS UNAVAILABLE'), ReturnEntry('SOURCE IS UNAVAILABLE'), ReturnValueEntry('7'), ))
def test_zip(): '''Test `exists` works on zip-imported modules.''' assert not exists('zip_imported_module_bla_bla') with temp_file_tools.create_temp_folder( prefix='test_python_toolbox_') as temp_folder: temp_zip_path = temp_folder / 'archive_with_module.zip' with temp_zip_path.open('wb') as temp_zip_file: temp_zip_file.write(zip_string) assert not exists('zip_imported_module_bla_bla') with sys_tools.TempSysPathAdder(temp_zip_path): assert exists('zip_imported_module_bla_bla') import zip_imported_module_bla_bla assert zip_imported_module_bla_bla.__doc__ == \ ('Module for testing `import_tools.exists` on zip-archived ' 'modules.')