From 7ad8210f992307a2c641dfe1de23c5f11230f979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Fri, 9 Jul 2021 16:09:59 +0200 Subject: [PATCH] extra unit tests --- tempsdb/series.pyx | 8 ++------ tests/test_series.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tempsdb/series.pyx b/tempsdb/series.pyx index c33cc2c..e288eeb 100644 --- a/tempsdb/series.pyx +++ b/tempsdb/series.pyx @@ -129,12 +129,8 @@ cdef class TimeSeries: self.page_size = metadata['page_size'] self.metadata = metadata.get('metadata') self.gzip_level = metadata.get('gzip_level', 0) - except ValueError: - raise Corruption('Corrupted series') - except (OSError, ValueError) as e: - raise Corruption('Corrupted series: %s' % (e, )) - except KeyError: - raise Corruption('Could not read metadata item') + except (OSError, ValueError, KeyError) as e: + raise Corruption('Corrupted series: %s' % (e, )) from e self.open_chunks = {} # tp.Dict[int, Chunk] self.chunks = [] # type: tp.List[tp.Tuple[int, bool, bool]] # sorted by ASC diff --git a/tests/test_series.py b/tests/test_series.py index fb72cdc..65f08c7 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -1,6 +1,10 @@ import os import unittest +from satella.json import write_json_to_file + +from tempsdb.exceptions import Corruption + class TestSeries(unittest.TestCase): @@ -23,6 +27,13 @@ class TestSeries(unittest.TestCase): self.assertNotEqual(ts, 0) series.close() + def test_corrupted_metadata(self): + from tempsdb.series import create_series, TimeSeries + series = create_series('test10', 'test10', 10, 4096) + series.close() + write_json_to_file('test10/metadata.txt', {}) + self.assertRaises(Corruption, TimeSeries('test10', 'test10')) + def test_trim_multiple_chunks_with_close(self): from tempsdb.series import create_series, TimeSeries series = create_series('test8', 'test8', 10, 4096) -- GitLab