class TestModulePathExtractorWithCurrentPath: @before def before(self): self.current_path = str(Path().absolute()) self.subject = ProfileEncoder( gzip=False, environment=environment).ModulePathExtractor(sys_path=[]) def test_it_removes_current_path_and_slash_and_dot(self): file_path = self.current_path + '/./polls/views.py' if platform.system() == "Windows": import os # This ignores the first D:. # This test just asserts the current behaviour, though the "/./" removal is not set for Windows. expected = self.current_path.replace(os.sep, ".")[3:] + ".polls.views" else: expected = "polls.views" assert self.subject.get_module_path(file_path) == expected def test_it_removes_slash_and_dot(self): file_path = '/./polls/views.py' assert self.subject.get_module_path(file_path) == "polls.views" def test_it_does_nothing_when_file_path_has_no_current_path(self): file_path = '/polls/views.py' assert self.subject.get_module_path(file_path) == "polls.views"
class TestModulePathExtractor: @before def before(self): self.subject = ProfileEncoder( gzip=False, environment=environment).ModulePathExtractor(sys_path=[ "/tmp/TestPythonAgent/site-package/", "\\tmp\\TestPythonAgent\\site-package\\" ]) def test_it_removes_root_path(self): assert self.subject \ .get_module_path("/tmp/TestPythonAgent/site-package/DummyPackage/dummy") == \ "DummyPackage.dummy" def test_it_returns_same_path_if_no_match_from_sys_paths(self): assert self.subject \ .get_module_path("this/is/clearly/not/in/sys/path/dummy.py") == \ "this.is.clearly.not.in.sys.path.dummy" def test_it_removes_longest_root_path_matched_from_sys_path(self): subject = ProfileEncoder( gzip=False, environment=environment).ModulePathExtractor(sys_path=[ "/tmp/TestPythonAgent/site-package/", "/tmp/TestPythonAgent/site-package/threading/", "\\tmp\\TestPythonAgent\\site-package\\", "\\tmp\\TestPythonAgent\\site-package\\threading\\" ]) assert subject.get_module_path("/tmp/TestPythonAgent/site-package/threading/DummyPackage/dummy") == \ "DummyPackage.dummy" def test_it_caches_result(self): self.dummy_module_extract = MagicMock("dummy_module_extractor") self.subject = ProfileEncoder( gzip=False, environment=environment).ModulePathExtractor( sys_path=["/tmp/TestPythonAgent/site-package/"], extractor_fun=self.dummy_module_extract) some_path = "/tmp/TestPythonAgent/site-package/DummyPackage/dummy.py" self.subject.get_module_path(some_path) self.subject.get_module_path(some_path) self.dummy_module_extract.assert_called_once_with( "/tmp/TestPythonAgent/site-package/DummyPackage/dummy.py", ["/tmp/TestPythonAgent/site-package/"]) def test_debug_pretty_encode_it_returns_a_json_representation_for_a_profile( self): result = ProfileEncoder.debug_pretty_encode(profile=example_profile(), environment=environment) assert (json.loads(result)["start"] == 1514764800000)
class TestModulePathExtractorWithCurrentPath: @before def before(self): self.current_path = str(Path().absolute()) self.subject = ProfileEncoder( gzip=False, environment=environment).ModulePathExtractor(sys_path=[]) def test_it_removes_current_path(self): file_path = self.current_path + '/polls/views.py' assert self.subject.get_module_path(file_path) == "polls.views" def test_it_removes_current_path_and_slash_and_dot(self): file_path = self.current_path + '/./polls/views.py' assert self.subject.get_module_path(file_path) == "polls.views" def test_it_does_nothing_when_file_path_has_no_current_path(self): file_path = '/polls/views.py' assert self.subject.get_module_path(file_path) == "polls.views"
def test_it_removes_longest_root_path_matched_from_sys_path(self): subject = ProfileEncoder( gzip=False, environment=environment).ModulePathExtractor(sys_path=[ "/tmp/TestPythonAgent/site-package/", "/tmp/TestPythonAgent/site-package/threading/", "\\tmp\\TestPythonAgent\\site-package\\", "\\tmp\\TestPythonAgent\\site-package\\threading\\" ]) assert subject.get_module_path("/tmp/TestPythonAgent/site-package/threading/DummyPackage/dummy") == \ "DummyPackage.dummy"