Skip to content

Commit

Permalink
Add initial test code (#149)
Browse files Browse the repository at this point in the history
* Add initial test code

EPIC time convert tests

* Update EPIC_timeconvert.py

mistype

* Update test_epic.py

more spacing - isort

* Update test_epic.py

more white space
  • Loading branch information
shaunwbell authored Feb 2, 2022
1 parent 55bd27a commit 3aa4b7e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
1 change: 1 addition & 0 deletions ci/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ mysql-connector-python==8.0.28
ctd==1.1.1 #python-ctd
seawater==3.3.4
#geomag cmweis github version... part of package
pytest
32 changes: 3 additions & 29 deletions src/EcoFOCIpy/epic/EPIC_timeconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def EPIC2Datetime( timeword_1, timeword_2):
ref_time_dt = datetime.datetime(1968, 5, 23)
ref_time_epic = 2440000

delta_days = [x - ref_time_epic for x in timeword_1]
delta_seconds = [x/1000 for x in timeword_2]
delta_days = timeword_1 - ref_time_epic
delta_seconds = timeword_2/1000

epic_dt = [ref_time_dt + datetime.timedelta(a,c) for a,c in zip(delta_days,delta_seconds)]
epic_dt = [ref_time_dt + datetime.timedelta(int(a),int(c)) for a,c in zip(delta_days,delta_seconds)]

return(epic_dt)

Expand Down Expand Up @@ -163,31 +163,5 @@ def Datetime2EPIC(epic_dt):
def main():
pass

def test_1d():
testdate = EPIC2Datetime([2440000,],[43200000+3600*1000,])
print(f"\n{testdate}\n")
for time_format in ['days','hours','seconds']:
time_since_str = time_format + ' since 1900-1-1'
print(f"{testdate}:value \n{time_since_str}:units\n")

def test_2d():
testdate = EPIC2Datetime([2440000,2450000],[43200000,0])
print(f"\n{testdate}\n")
for time_format in ['days','hours','seconds']:
time_since_str = time_format + ' since 1900-1-1'
print(f"{testdate}:value \n{time_since_str}:units\n")

def test_1d_EPIC():
testdate = EPIC2Datetime([2440000,],[43200000+3600*1000,])
print(f'{testdate}')
testdate1 = Datetime2EPIC(testdate)
print(f'{testdate1}')

def test_2d_EPIC():
testdate = EPIC2Datetime([2440000,2450000],[43200000,0])
print(f'{testdate}')
testdate1 = Datetime2EPIC(testdate)
print(f'{testdate1}')

if __name__ == "__main__":
main()
23 changes: 23 additions & 0 deletions tests/test_epic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import datetime

import pytest
from EcoFOCIpy.epic import EPIC_timeconvert as EPIC


class TestClassEPICTime:
def test_1d(self):
testdate = EPIC.EPIC2Datetime([2440000,],[43200000+3600*1000,])
assert testdate == [datetime.datetime(1968, 5, 23, 13, 0)]

def test_2d(self):
testdate = EPIC.EPIC2Datetime([2440000,2450000],[43200000,0])
assert testdate == [datetime.datetime(1968, 5, 23, 12, 0), datetime.datetime(1995, 10, 9, 0, 0)]

def test_1d_EPIC(self):
testdate = EPIC.Datetime2EPIC(EPIC.EPIC2Datetime([2440000,],[43200000+3600*1000,]))
assert testdate == ([2440000], [46800000])

def test_2d_EPIC(self):
testdate = EPIC.Datetime2EPIC(EPIC.EPIC2Datetime([2440000,2450000],[43200000,0]))
assert testdate == ([2440000,2450000],[43200000,0])

0 comments on commit 3aa4b7e

Please sign in to comment.