Skip to content

Commit

Permalink
Basic unittesting added for CLI scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
PennyHow committed Oct 6, 2023
1 parent 2ee4ce1 commit 93c3fd9
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 51 deletions.
16 changes: 8 additions & 8 deletions src/pypromice/get/get_promice_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ 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'''
# d = os.system('get_promice_data -n KPC_U -f csv -o None')

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

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()
16 changes: 9 additions & 7 deletions src/pypromice/postprocess/get_bufr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import glob, os
import argparse
from datetime import datetime, timedelta
import pickle
import pickle, unittest

from pypromice.postprocess.wmo_config import ibufr_settings, stid_to_skip, positions_seed, positions_update_timestamp_only
from pypromice.postprocess.csv2bufr import getBUFR, linear_fit, rolling_window, round_values, \
Expand Down Expand Up @@ -287,9 +287,11 @@ def get_bufr():
print('failed_min_data_pos: {}'.format(failed_min_data_pos))
print('--------------------------------')

if __name__ == '__main__':
"""Executed from the command line"""
get_bufr()
else:
"""Executed on import"""
pass
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()
18 changes: 9 additions & 9 deletions src/pypromice/process/get_l3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python
import logging
import os
import sys
import logging, os, sys, unittest
from argparse import ArgumentParser
from pypromice.process.aws import AWS

Expand Down Expand Up @@ -43,10 +41,12 @@ def get_l3():
if args.outpath is not None:
aws.write(args.outpath)

if __name__ == '__main__':
"""Executed from the command line"""
get_l3()
else:
"""Executed on import"""
pass
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()

16 changes: 9 additions & 7 deletions src/pypromice/process/join_l3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
import os
import os, unittest
import pandas as pd
import xarray as xr
from argparse import ArgumentParser
Expand Down Expand Up @@ -128,9 +128,11 @@ def join_l3():



if __name__ == '__main__':
"""Executed from the command line"""
join_l3()
else:
"""Executed on import"""
pass
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()
17 changes: 10 additions & 7 deletions src/pypromice/tx/get_l0tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from argparse import ArgumentParser

from configparser import ConfigParser
import os, imaplib, email, toml, re
import os, imaplib, email, toml, re, unittest
from glob import glob
from datetime import datetime, timedelta

Expand Down Expand Up @@ -172,9 +172,12 @@ def get_l0tx():

print('Finished')

if __name__ == '__main__':
"""Executed from the command line"""
get_l0tx()
else:
"""Executed on import"""
pass

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()
17 changes: 10 additions & 7 deletions src/pypromice/tx/get_msg.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
from argparse import ArgumentParser
from configparser import ConfigParser
import os, imaplib, email
import os, imaplib, email, unittest
from glob import glob
from pypromice.tx import getMail

Expand Down Expand Up @@ -99,9 +99,12 @@ def get_msg():

print('Finished')

if __name__ == '__main__':
"""Executed from the command line"""
get_msg()
else:
"""Executed on import"""
pass

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()
16 changes: 10 additions & 6 deletions src/pypromice/tx/get_watsontx.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from argparse import ArgumentParser

from configparser import ConfigParser
import os, imaplib, email
import os, imaplib, email, unittest
from glob import glob
from datetime import datetime

Expand Down Expand Up @@ -140,8 +140,12 @@ def get_watsontx():

print('Finished')

if __name__ == '__main__':
get_watsontx()
else:
"""Executed on import"""
pass

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()

0 comments on commit 93c3fd9

Please sign in to comment.