Example #1
0
def test_repr():
    stats = Statistics(name='foo', own_hits=4, deep_time=128)
    assert repr(stats) == "<Statistics 'foo' hits=4 time=128.000000>"
    frozen = FrozenStatistics(stats)
    frozen._children.append(Statistics(name='baz', own_hits=1, deep_time=120))
    assert \
        repr(frozen) == \
        "<FrozenStatistics 'foo' hits=4/5 time=8.000000/128.000000>"
Example #2
0
def test_stats():
    stats = Statistics(name='foo', filename='bar', lineno=42)
    assert stats.regular_name == 'foo'
    stats.module = 'baz'
    assert stats.regular_name == 'baz:foo'
    assert stats.deep_time_per_call == 0
    assert stats.own_time_per_call == 0
    stats.deep_time = 128
    stats.own_hits = 4
    assert stats.deep_time_per_call == 32
    assert stats.own_time_per_call == 32
    assert len(stats) == 0
    assert not list(stats)
Example #3
0
def test_stats():
    stats = Statistics(name="foo", filename="bar", lineno=42)
    assert stats.regular_name == "foo"
    stats.module = "baz"
    assert stats.regular_name == "baz:foo"
    assert stats.deep_time_per_call == 0
    assert stats.own_time_per_call == 0
    stats.deep_time = 128
    stats.own_hits = 4
    assert stats.deep_time_per_call == 32
    assert stats.own_time_per_call == 32
    assert len(stats) == 0
    assert not list(stats)
Example #4
0
def test_hash():
    stats1 = Statistics(name='foo', filename='bar', lineno=42)
    stats2 = Statistics(name='baz', filename='bar', lineno=89)
    stats_dics = {stats1: 1, stats2: 2}
    assert stats_dics[stats1] == 1
    assert stats_dics[stats2] == 2
Example #5
0
def test_pickle():
    stats = Statistics(name='ok')
    for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
        assert pickle.loads(pickle.dumps(stats, protocol)).name == 'ok'