Skip to content

Commit

Permalink
Merge pull request #10 from Semi-ATE/nerohmot
Browse files Browse the repository at this point in the history
raise exeption on negative epoch number beyond 43200.0
  • Loading branch information
nerohmot authored Feb 23, 2021
2 parents 4c5db95 + 486a435 commit 7a1a193
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Semi_ATE/TnD/TnD.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import datetime
import os
import time
import platform


def is_date(stamp):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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" % (
Expand Down
1 change: 0 additions & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ check-manifest
pip
setuptools
twine
tree
38 changes: 31 additions & 7 deletions tests/test_DT.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import platform

from Semi_ATE.TnD import DT, DTError


Expand All @@ -10,15 +12,33 @@ 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():
assert DT(1570484799.123).epoch == 1570484799


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
Expand All @@ -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():
Expand Down Expand Up @@ -236,7 +264,3 @@ def test__ge__():

def test__str__():
assert True


def test_is_date_ok():
assert DT("01101969")

0 comments on commit 7a1a193

Please sign in to comment.