From 0f0386f14a48d979ae09ea1f560628fc742fdabe Mon Sep 17 00:00:00 2001 From: Thor77 Date: Thu, 1 Feb 2018 21:17:23 +0100 Subject: [PATCH] Rewrite needs_parsing-test it now copies the testlog to a tmpfile first and adds a line to check if Cache.needs_parsing is working correctly --- tsstats/tests/test_cache.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tsstats/tests/test_cache.py b/tsstats/tests/test_cache.py index d759ba4..3d9d272 100644 --- a/tsstats/tests/test_cache.py +++ b/tsstats/tests/test_cache.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- import os + +import shutil + import pytest from tsstats.cache import Cache, CachedLog, _calculate_hash @@ -48,10 +51,17 @@ def test_cache_read_write(cache): ) -def test_cache_needs_parsing(cache): - cache[testlog_path] = [] - assert not cache.needs_parsing(testlog_path) - assert cache.needs_parsing(testlog_path + '.nl') +def test_cache_needs_parsing(cache, tmpdir): + tmplog_path = str(tmpdir.mkdir('cache').join('test.log')) + # copy logfile to temporary location + shutil.copy(testlog_path, tmplog_path) + + assert cache.needs_parsing(tmplog_path) + cache[tmplog_path] = [] + assert not cache.needs_parsing(tmplog_path) + with open(tmplog_path, 'a') as f: + f.writelines(['content']) + assert cache.needs_parsing(tmplog_path) # INTEGRATION