コード例 #1
0
def test_cached_object_with_list_returns_correct_type():
    def make_a_list():
        return [1, 2, 3]
    with tempfile.NamedTemporaryFile() as f:
        # call repeatedly to test the cold and hot cache logic
        for _ in range(2):
            df = compute_cache.cached_object(
                f.name, compute_fn=make_a_list)
            assert isinstance(df, list), \
                "Expected list, got %s : %s" % (df, type(df))
コード例 #2
0
def test_cached_object_with_tempfile():
    """
    test_cached_object_with_tempfile : A temporary file exists before
    calling into compute_cache.cached_object but is empty, should be treated
    as if result has never been computed before (rather than trying to load
    the empty file).
    """
    counter = Counter()
    with tempfile.NamedTemporaryFile() as f:
        # call repeatedly to test the hot and cold cache logic
        result = compute_cache.cached_object(
            f.name, compute_fn=counter.increment)
        assert result == 1, "Expected result=1, got %s" % (result,)
        assert counter.count == 1, \
            "Expected compute_fn to be called once, got %s" % (counter.count,)