Skip to content

Commit

Permalink
CLI unit tests moved to module scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
PennyHow committed Oct 6, 2023
1 parent 93c3fd9 commit 56e1898
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 59 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
'get_l0tx = pypromice.tx.get_l0tx:get_l0tx',
'get_l3 = pypromice.process.get_l3:get_l3',
'join_l3 = pypromice.process.join_l3:join_l3',
'get_watsontx = pypromice.get.get_watsontx:get_watsontx',
'get_watsontx = pypromice.tx.get_watsontx:get_watsontx',
'get_bufr = pypromice.postprocess.get_bufr:get_bufr',
'get_msg = pypromice.tx.get_msg:get_msg'
],
Expand Down
7 changes: 6 additions & 1 deletion src/pypromice/get/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import xarray as xr
import unittest, pkg_resources
from datetime import datetime
import warnings
import warnings, os

def aws_names():
'''Return PROMICE and GC-Net AWS names that can be used in get.aws_data()
Expand Down Expand Up @@ -201,6 +201,11 @@ def testWatsonDaily(self):
'''Test Wason River discharge daily data retrieval'''
wd = watson_discharge(t='day')
self.assertTrue(wd['Q']['2009-09-04 00:00:00']==4.72)

def testGetCLI(self):
'''Test get_promice_data'''
exit_status = os.system('get_promice_data -h')
self.assertEqual(exit_status, 0)

if __name__ == "__main__":
unittest.main()
9 changes: 1 addition & 8 deletions src/pypromice/get/get_promice_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,5 @@ def get_promice_data():

print(f'File saved to {outfile}')


class get_promice_data_test(unittest.TestCase):
def get_test(self):
'''Test get_promice_data'''
exit_status = os.system('get_promice_data -h')
self.assertEqual(exit_status, 0)

if __name__ == "__main__":
unittest.main()
get_promice_data()
8 changes: 1 addition & 7 deletions src/pypromice/postprocess/get_bufr.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,5 @@ def get_bufr():
print('failed_min_data_pos: {}'.format(failed_min_data_pos))
print('--------------------------------')

class get_bufr_test(unittest.TestCase):
def bufr_test(self):
'''Test get_bufr CLI'''
exit_status = os.system('get_bufr -h')
self.assertEqual(exit_status, 0)

if __name__ == "__main__":
unittest.main()
get_bufr()
10 changes: 10 additions & 0 deletions src/pypromice/process/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,16 @@ def testL0toL3(self):
self.assertIsInstance(pAWS.L3, xr.Dataset)
self.assertTrue(pAWS.L3.attrs['station_id']=='TEST1')

def testCLIgetl3(self):
'''Test get_l3 CLI'''
exit_status = os.system('get_l3 -h')
self.assertEqual(exit_status, 0)

def testCLIjoinl3(self):
'''Test join_l3 CLI'''
exit_status = os.system('join_l3 -h')
self.assertEqual(exit_status, 0)

#------------------------------------------------------------------------------

if __name__ == "__main__":
Expand Down
8 changes: 1 addition & 7 deletions src/pypromice/process/get_l3.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ def get_l3():

if args.outpath is not None:
aws.write(args.outpath)

class get_l3_test(unittest.TestCase):
def l3_test(self):
'''Test get_l3 CLI'''
exit_status = os.system('get_l3 -h')
self.assertEqual(exit_status, 0)

if __name__ == "__main__":
unittest.main()
get_l3()

10 changes: 1 addition & 9 deletions src/pypromice/process/join_l3.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,6 @@ def join_l3():
# Write to files
writeAll(out, name, l3_h, l3_d, l3_m, col_names)
print(f'Files saved to {os.path.join(out, name)}...')



class join_l3_test(unittest.TestCase):
def join_test(self):
'''Test join_l3 CLI'''
exit_status = os.system('join_l3 -h')
self.assertEqual(exit_status, 0)

if __name__ == "__main__":
unittest.main()
join_l3()
9 changes: 1 addition & 8 deletions src/pypromice/tx/get_l0tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,5 @@ def get_l0tx():

print('Finished')


class get_l0tx_test(unittest.TestCase):
def l0tx_test(self):
'''Test get_l0tx CLI'''
exit_status = os.system('get_l0tx -h')
self.assertEqual(exit_status, 0)

if __name__ == "__main__":
unittest.main()
get_l0tx()
9 changes: 1 addition & 8 deletions src/pypromice/tx/get_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ def get_msg():


print('Finished')


class get_msg_test(unittest.TestCase):
def msg_test(self):
'''Test get_msg CLI'''
exit_status = os.system('get_msg -h')
self.assertEqual(exit_status, 0)

if __name__ == "__main__":
unittest.main()
get_msg()
11 changes: 2 additions & 9 deletions src/pypromice/tx/get_watsontx.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def parse_arguments_watson():
parser = ArgumentParser(description="AWS L0 transmission fetcher")
parser = ArgumentParser(description="AWS L0 transmission fetcher for Watson River measurements")
parser.add_argument('-a', '--account', default=None, type=str, required=True, help='Email account .ini file')
parser.add_argument('-p', '--password', default=None, type=str, required=True, help='Email credentials .ini file')
parser.add_argument('-o', '--outpath', default=None, type=str, required=False, help='Path where to write output (if given)')
Expand Down Expand Up @@ -139,13 +139,6 @@ def get_watsontx():
print(f'Could not write last uid {uid} to {uid_file}')

print('Finished')


class get_watsontx_test(unittest.TestCase):
def watson_test(self):
'''Test get_watsontx CLI'''
exit_status = os.system('get_watsontx -h')
self.assertEqual(exit_status, 0)

if __name__ == "__main__":
unittest.main()
get_watsontx()
17 changes: 16 additions & 1 deletion src/pypromice/tx/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,21 @@ def testL0tx(self):
self.assertTrue('tfffffffffff' in l0.bin_format)
self.assertTrue('2022-07-25 10:00:00' in l0.msg)
self.assertFalse('?' in l0.msg)


def testCLIl0tx(self):
'''Test get_l0tx CLI'''
exit_status = os.system('get_l0tx -h')
self.assertEqual(exit_status, 0)

def testCLIwatson(self):
'''Test get_watsontx CLI'''
exit_status = os.system('get_watsontx -h')
self.assertEqual(exit_status, 0)

def testCLImsg(self):
'''Test get_msg CLI'''
exit_status = os.system('get_msg -h')
self.assertEqual(exit_status, 0)

if __name__ == "__main__":
unittest.main()

0 comments on commit 56e1898

Please sign in to comment.