Пример #1
0
def test_frozen():
    code = mock_code('foo')
    stats = RecordingStatistics(code)
    stats.deep_time = 10
    frozen_stats = FrozenStatistics(stats)
    assert frozen_stats.name == 'foo'
    assert frozen_stats.deep_time == 10
    restored_frozen_stats = pickle.loads(pickle.dumps(frozen_stats))
    assert restored_frozen_stats.name == 'foo'
    assert restored_frozen_stats.deep_time == 10
Пример #2
0
def test_sorting():
    stats = RecordingStatistics(mock_code('foo'))
    stats1 = RecordingStatistics(mock_code('bar'))
    stats2 = RecordingStatistics(mock_code('baz'))
    stats3 = RecordingStatistics(mock_code('qux'))
    stats.add_child(stats1.code, stats1)
    stats.add_child(stats2.code, stats2)
    stats.add_child(stats3.code, stats3)
    stats.deep_time = 100
    stats1.deep_time = 20
    stats1.own_hits = 3
    stats2.deep_time = 30
    stats2.own_hits = 2
    stats3.deep_time = 40
    stats3.own_hits = 4
    assert stats.sorted() == [stats3, stats2, stats1]
    assert stats.sorted(by_own_hits) == [stats3, stats1, stats2]
    assert stats.sorted(~by_own_hits) == [stats2, stats1, stats3]
    assert stats.sorted(by_deep_time_per_call) == [stats2, stats3, stats1]
    assert stats.sorted(by_own_time_per_call) == [stats2, stats3, stats1]
    assert stats.sorted(by_name) == [stats1, stats2, stats3]
Пример #3
0
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
Пример #4
0
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