Skip to content
Snippets Groups Projects
Commit 9acb42df authored by jacques.grelet_ird.fr's avatar jacques.grelet_ird.fr
Browse files

works with 3 tests

parent 4dcb3bd7
No related branches found
No related tags found
No related merge requests found
...@@ -96,3 +96,8 @@ Developpement: ...@@ -96,3 +96,8 @@ Developpement:
> pip install netCDF4 > pip install netCDF4
> pip install seawater > pip install seawater
> pip install numpy > pip install numpy
Tests avec unittest:
--------------------
Les fichiers de tests sont sous tests
> python -m unittest -v tests/test_roscop.py
\ No newline at end of file
__version__ = '0.10.0'
from physicalParameter import Roscop
...@@ -14,25 +14,33 @@ class Roscop: ...@@ -14,25 +14,33 @@ class Roscop:
# constructor with values by default # constructor with values by default
def __init__(self, file): def __init__(self, file):
self.file = file self.file = file
self.hash = {} self.__hash = {}
self.read()
# call by print() # call by print()
def __str__(self): def __str__(self):
return 'Class Roscop, file: %s, size = %d' % (self.file, len(self.hash)) ''' overload string representation '''
return 'Class Roscop, file: %s, size = %d' % (self.file, len(self))
def __getitem__(self, name): def __getitem__(self, name):
''' ''' overload r[key] '''
overload r[key] return self.__hash[name]
'''
return self.hash[name]
def __repr__(self): def __repr__(self):
''' overload print() '''
return super().__repr__() return super().__repr__()
def disp(self, theKey): def __len__(self):
''' overload len() '''
return len(self.__hash)
def displayCode(self, theKey):
print("%s :" % theKey) print("%s :" % theKey)
print(self[theKey]) print(self[theKey])
def returnCode(self, theKey):
return(self[theKey])
# read code roscop file # read code roscop file
def read(self): def read(self):
with open(self.file, 'rt') as f: with open(self.file, 'rt') as f:
...@@ -49,7 +57,7 @@ class Roscop: ...@@ -49,7 +57,7 @@ class Roscop:
#logging.debug(" %s -> %s: %s" % (theKey, k, row[k])) #logging.debug(" %s -> %s: %s" % (theKey, k, row[k]))
logging.debug( logging.debug(
" {} -> {}: {}".format(theKey, k, row[k])) " {} -> {}: {}".format(theKey, k, row[k]))
self.hash[theKey] = row self.__hash[theKey] = row
return return
...@@ -77,7 +85,7 @@ if __name__ == "__main__": ...@@ -77,7 +85,7 @@ if __name__ == "__main__":
r = Roscop(args.file) r = Roscop(args.file)
# r = Roscop("code_roscop.csv") # r = Roscop("code_roscop.csv")
r.read() # r.read()
print(r) print(r)
# get -k arg(s) list # get -k arg(s) list
...@@ -85,7 +93,7 @@ if __name__ == "__main__": ...@@ -85,7 +93,7 @@ if __name__ == "__main__":
# if args list is empty, key contain NoneType # if args list is empty, key contain NoneType
if key is not None: if key is not None:
for k in key: for k in key:
r.disp(k) r.displayCode(k)
# r.disp('TEMP') print(r.returnCode(key[0])['key'])
# print(r[key]) # print(r[key])
import unittest
from physicalParameter import Roscop
'''
> python -m unittest -v tests/test_roscop.py
'''
class RoscopTest(unittest.TestCase):
def setUp(self):
"""Initialisation des tests."""
self.file = 'code_roscop.csv'
self.r = Roscop(self.file)
def test_file(self):
"""
Test if filename is correct
"""
self.assertEqual(self.r.file, self.file)
def test_entries(self):
self.assertEqual(len(self.r), 68)
def test_key(self):
self.assertEqual(self.r.returnCode('TEMP')['key'], 'TEMP')
if __name__ == '__main__':
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment