From 09365c795715c1438066c0a320c10aa3c3d2bab2 Mon Sep 17 00:00:00 2001 From: Gourav Kumar Date: Sun, 10 Apr 2022 23:51:56 +0530 Subject: [PATCH] added tests for setitem in TSC --- tests/test_core.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 72f2ee3..4bfc68e 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,6 +1,6 @@ import datetime import random -from typing import Literal, Sequence +from typing import Literal, Mapping, Sequence import pytest from fincal.core import AllFrequencies, Frequency, Series, TimeSeriesCore @@ -110,7 +110,7 @@ class TestTimeSeriesCore: def test_creation(self): ts = TimeSeriesCore(self.data, frequency="M") assert isinstance(ts, TimeSeriesCore) - # assert isinstance(ts, Mapping) + assert isinstance(ts, Mapping) class TestSlicing: @@ -179,6 +179,33 @@ class TestSlicing: assert len(ts_slice) == 2 +class TestSetitem: + data = [("2021-01-01", 220), ("2021-01-04", 230), ("2021-03-07", 240)] + + def test_setitem(self): + ts = TimeSeriesCore(self.data, frequency="D") + assert len(ts) == 3 + + ts["2021-01-02"] = 225 + assert len(ts) == 4 + assert ts["2021-01-02"][1] == 225 + + ts["2021-01-02"] = 227.6 + assert len(ts) == 4 + assert ts["2021-01-02"][1] == 227.6 + + def test_errors(self): + ts = TimeSeriesCore(self.data, frequency="D") + with pytest.raises(TypeError): + ts["2021-01-03"] = "abc" + + with pytest.raises(NotImplementedError): + ts.iloc[4] = 4 + + with pytest.raises(ValueError): + ts["abc"] = 12 + + class TestTimeSeriesCoreHeadTail: data = [ ("2021-01-01", 220),