def test_recording(): # profiling is a module not code. # but inspect.getmodule() works like with code of a module. assert RecordingStatistics(profiling).module == 'profiling' # use discard_child. stats = RecordingStatistics() assert None not in stats stats.ensure_child(None) assert None in stats stats.discard_child(None) assert None not in stats stats.discard_child(None) assert None not in stats
def test_frozen(): code = mock_code('foo') stats = RecordingStatistics(code) stats.deep_time = 10 stats.ensure_child(None) # RecordingStatistics are frozen at pickling. frozen_stats = pickle.loads(pickle.dumps(stats)) assert frozen_stats.name == 'foo' assert frozen_stats.deep_time == 10 assert len(frozen_stats) == 1 restored_frozen_stats = pickle.loads(pickle.dumps(frozen_stats)) assert restored_frozen_stats.name == 'foo' assert restored_frozen_stats.deep_time == 10 assert len(restored_frozen_stats) == 1
def test_recording(): # profiling is a module not code. # but inspect.getmodule() works like with code of a module. assert RecordingStatistics(profiling).module == 'profiling' # use discard_child. stats = RecordingStatistics() assert None not in stats stats.ensure_child(None) assert None in stats stats.discard_child(None) assert None not in stats stats.discard_child(None) assert None not in stats # cannot be pickled. with pytest.raises(TypeError): pickle.dumps(stats)