From 486a4357cccf0663bc794a09898205118614bd7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20H=C3=B6ren?= Date: Tue, 23 Feb 2021 01:02:11 +0100 Subject: [PATCH] raise exeption on negative epoch number beyond 43200.0 --- .github/workflows/CI.yml | 4 ++-- Semi_ATE/TnD/TnD.py | 4 ++++ requirements/test.txt | 1 - tests/test_DT.py | 38 +++++++++++++++++++++++++++++++------- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index dfe78b6..d78c986 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -37,8 +37,8 @@ jobs: run: | pip install -r requirements/run.txt pip install -r requirements/test.txt -# - name: Run tests -# run: pytest tests/ --cov=Semi_ATE + - name: Run tests + run: pytest tests/ --cov=Semi_ATE - name: Create package run: python setup.py sdist - name: Check package diff --git a/Semi_ATE/TnD/TnD.py b/Semi_ATE/TnD/TnD.py index e3eb4fd..73463f3 100644 --- a/Semi_ATE/TnD/TnD.py +++ b/Semi_ATE/TnD/TnD.py @@ -10,6 +10,7 @@ import datetime import os import time +import platform def is_date(stamp): @@ -233,6 +234,7 @@ def __init__(self, stamp=None): loct = int(time.time()) self.tz = (time.mktime(time.gmtime(loct)) - loct) / 3600 self.dst = time.localtime()[8] + self.os = platform.system() self.__call__(stamp) def __call__(self, stamp=None): @@ -276,6 +278,8 @@ def __call__(self, stamp=None): self._populate() def _populate(self): + if self.os == "Windows" and self.epoch < -43200: + raise DTError("Windows doesn't support negative epoch times beyond -43200 (12 hours prior)") t = time.gmtime(self.epoch) d = datetime.date(t.tm_year, t.tm_mon, t.tm_mday) self.datecode = "%4d%02d%1d" % ( diff --git a/requirements/test.txt b/requirements/test.txt index 54eadce..d344c06 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -4,4 +4,3 @@ check-manifest pip setuptools twine -tree diff --git a/tests/test_DT.py b/tests/test_DT.py index be92588..4bbb023 100644 --- a/tests/test_DT.py +++ b/tests/test_DT.py @@ -1,3 +1,5 @@ +import platform + from Semi_ATE.TnD import DT, DTError @@ -10,7 +12,16 @@ def test_init_int_pos(): def test_init_int_neg(): - assert DT(-7948800).epoch == -7948800 + if platform.system() == "Windows": + try: + DT(-43201) + except DTError: + assert True + else: + assert False + assert DT(-43200).epoch == -43200 + else: + assert DT(-7948800).epoch == -7948800 def test_init_float_pos(): @@ -18,7 +29,16 @@ def test_init_float_pos(): def test_init_float_neg(): - assert DT(-7948800.663).epoch == -7948800 + if platform.system() == "Windows": + try: + DT(-43201.0) + except DTError: + assert True + else: + assert False + assert DT(-43200.0).epoch == -43200 + else: + assert DT(-7948800.663).epoch == -7948800 def test_init_str_datecode_post_epoch(): # YYWWD @@ -43,7 +63,15 @@ def test_init_str_date_post_epoch(): # DDMMYYYY def test_init_str_date_pre_epoch(): - assert DT("01101969").date == "01101969" + if platform.system() == "Windows": + try: + DT("01101969") + except DTError: + assert True + else: + assert False + else: + assert DT("01101969").date == "01101969" def test_init_str_invalid(): @@ -236,7 +264,3 @@ def test__ge__(): def test__str__(): assert True - - -def test_is_date_ok(): - assert DT("01101969")