From 56e1898fb0d08394b245ec8dc6851a0aa5ff034d Mon Sep 17 00:00:00 2001 From: PennyHow Date: Fri, 6 Oct 2023 14:58:52 -0200 Subject: [PATCH] CLI unit tests moved to module scripts --- setup.py | 2 +- src/pypromice/get/get.py | 7 ++++++- src/pypromice/get/get_promice_data.py | 9 +-------- src/pypromice/postprocess/get_bufr.py | 8 +------- src/pypromice/process/aws.py | 10 ++++++++++ src/pypromice/process/get_l3.py | 8 +------- src/pypromice/process/join_l3.py | 10 +--------- src/pypromice/tx/get_l0tx.py | 9 +-------- src/pypromice/tx/get_msg.py | 9 +-------- src/pypromice/tx/get_watsontx.py | 11 ++--------- src/pypromice/tx/tx.py | 17 ++++++++++++++++- 11 files changed, 41 insertions(+), 59 deletions(-) diff --git a/setup.py b/setup.py index 2f0a6ee2..6a7a5111 100644 --- a/setup.py +++ b/setup.py @@ -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' ], diff --git a/src/pypromice/get/get.py b/src/pypromice/get/get.py index b9ae4944..8ac0dbe4 100644 --- a/src/pypromice/get/get.py +++ b/src/pypromice/get/get.py @@ -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() @@ -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() diff --git a/src/pypromice/get/get_promice_data.py b/src/pypromice/get/get_promice_data.py index 56b51489..c43228d3 100755 --- a/src/pypromice/get/get_promice_data.py +++ b/src/pypromice/get/get_promice_data.py @@ -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() diff --git a/src/pypromice/postprocess/get_bufr.py b/src/pypromice/postprocess/get_bufr.py index 673bdd53..702dca33 100644 --- a/src/pypromice/postprocess/get_bufr.py +++ b/src/pypromice/postprocess/get_bufr.py @@ -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() diff --git a/src/pypromice/process/aws.py b/src/pypromice/process/aws.py index 61ba6a5d..7fa1e3de 100644 --- a/src/pypromice/process/aws.py +++ b/src/pypromice/process/aws.py @@ -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__": diff --git a/src/pypromice/process/get_l3.py b/src/pypromice/process/get_l3.py index 73b1a14c..4cc18436 100755 --- a/src/pypromice/process/get_l3.py +++ b/src/pypromice/process/get_l3.py @@ -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() diff --git a/src/pypromice/process/join_l3.py b/src/pypromice/process/join_l3.py index 7ba89c79..2e0d3fe3 100644 --- a/src/pypromice/process/join_l3.py +++ b/src/pypromice/process/join_l3.py @@ -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() diff --git a/src/pypromice/tx/get_l0tx.py b/src/pypromice/tx/get_l0tx.py index 62430680..05a9051e 100644 --- a/src/pypromice/tx/get_l0tx.py +++ b/src/pypromice/tx/get_l0tx.py @@ -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() diff --git a/src/pypromice/tx/get_msg.py b/src/pypromice/tx/get_msg.py index feefac58..9de195f4 100644 --- a/src/pypromice/tx/get_msg.py +++ b/src/pypromice/tx/get_msg.py @@ -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() \ No newline at end of file diff --git a/src/pypromice/tx/get_watsontx.py b/src/pypromice/tx/get_watsontx.py index ad9128bf..c0693f7a 100644 --- a/src/pypromice/tx/get_watsontx.py +++ b/src/pypromice/tx/get_watsontx.py @@ -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)') @@ -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() diff --git a/src/pypromice/tx/tx.py b/src/pypromice/tx/tx.py index 085c3575..a83b3099 100644 --- a/src/pypromice/tx/tx.py +++ b/src/pypromice/tx/tx.py @@ -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()