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

add file_extractor.py

update test_config
reorganize folders
parent 3d26c3f7
No related branches found
No related tags found
No related merge requests found
.vstags 0 → 100644
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.8 //
display_version .\btl-all.pl 107;" s
entete_odv .\btl-all.pl 282;" s
get_options .\btl-all.pl 131;" s
position .\btl-all.pl 259;" s
read_config .\btl-all.pl 161;" s
read_config_string .\btl-all.pl 148;" s
usage .\btl-all.pl 115;" s
usage .\sta-fr22.pl 35;" s
write_xml_header .\btl-all.pl 211;" s
......@@ -486,5 +486,24 @@ Developpement:
Tests avec unittest:
--------------------
Voir: https://docs.python.org/3.7/library/unittest.html?highlight=unittest
Les fichiers de tests sont sous tests
> python -m unittest -v tests/test_roscop.py
Run test in single file
> python - m unittest - v tests/test_roscop.py
Run all test_ * in dir tests:
> python - m unittest discover tests - v
> python - m unittest discover - s tests - p 'test_*.py' - v
Methods name:
assertEqual()
assertNotEqual()
assertTrue()
assertFalse()
assertRaises()
assertAlmostEqual()
assertNotAlmostEqual()
assertRegex()
assertNotRegex()
assertRaisesRegex()
\ No newline at end of file
__version__ = '0.10.0'
from physicalParameter import Roscop
#from physicalParameter import Roscop
......@@ -2,18 +2,34 @@ import toml
# some examples:
# https://www.programcreek.com/python/example/93872/toml.load
cfg = toml.load('cruise.toml')
cfg = toml.load('tests/test.toml')
print(cfg['global']['author'])
d = cfg['global']
print(d, end='\n')
d = cfg['cruise']
print(d, end='\n')
d = cfg['ctd']
print(d, end='\n')
for key in cfg['cruise'].keys():
print(cfg['cruise'][key])
print(cfg['cruise'].get(key))
ctd = cfg['ctd']
s = ctd['split']
for key in s.keys():
print("{}: {}".format(key, s[key]))
s = ctd['splitAll']
for key in s.keys():
print("{}: {}".format(key, s[key]))
# print(cfg['cruise'].get(key))
d = cfg['split']['ctd']
print(d, end='\n')
for key in d.keys():
print("{}: {}".format(key, d[key]))
d = cfg['split']['ctdAll']
print(d, end='\n')
for key in d.keys():
print("{}: {}".format(key, d[key]))
d = cfg['split']['btl']
print(d, end='\n')
for key in d.keys():
print("{}: {}".format(key, d[key]))
'''
file_extractor.py
'''
import fileinput
class FileExtractor:
'''
This class read an ASCII file, extract physical parameter with ROSCOP codification from the given column
'''
# constructor with values by default
def __init__(self, file):
# attibutes
# public:
self.file = file
# private:
self.__hash = {}
# constructor build objet by reading the file
self.read()
# overloading operators
def __str__(self):
''' overload string representation '''
return 'Class FileExtractor, file: %s, size = %d' % (self.file, len(self))
# read code roscop file
def read(self):
for line in fileinput.input(
self.file, openhook=fileinput.hook_encoded("ISO-8859-1")):
# iterate over the lines of opened file "fileName"
# ------------------------------------------------
print(line)
# for testing in standalone context
# ---------------------------------
if __name__ == "__main__":
fe = FileExtractor('data/cnv/fr29001.cnv')
fe.read()
File moved
File moved
File moved
......@@ -16,7 +16,6 @@ creator = "Jacques.Grelet@ird.fr"
[ctd]
cruisePrefix = "fr29"
# profile name : fr29xxx
station = 'Station\s*:\s*\D*(\d*)'
stationPrefixLength = 3
titleSummary = "CTD profiles processed during PIRATA-FR29 cruise"
......@@ -32,47 +31,78 @@ bottomDepth = 'Bottom Depth\s*:\s*(\d*\.?\d+?)\s*\S*'
operator = 'Operator\s*:\s*(.*)'
type = 'Type\s*:\s*(.*)'
split.ETDD = 2
split.PRES = 3
split.DEPTH = 4
split.TEMP = 5
split.PSAL = 18
split.DENS = 20
split.SVEL = 22
split.DOX2 = 16
split.FLU2 = 14
split.FLU3 = 15
split.TUR3 = 13
split.NAVG = 24
splitAll.ETDD = 2
splitAll.PRES = 3
splitAll.DEPH = 4
splitAll.TE01 = 5
splitAll.TE02 = 6
splitAll.CND1 = 7
splitAll.CND2 = 8
splitAll.DOV1 = 9
splitAll.DOV2 = 10
splitAll.DVT1 = 11
splitAll.DVT2 = 12
splitAll.TUR3 = 13
splitAll.FLU2 = 14
splitAll.FLU3 = 15
splitAll.DO12 = 16
splitAll.DO22 = 17
splitAll.PSA1 = 18
splitAll.PSA2 = 19
splitAll.DEN1 = 20
splitAll.DEN2 = 21
splitAll.SVEL = 22
splitAll.NAVG = 24
[btl]
typeInstrument = "SBE32 standard 24 Niskin bottles"
instrumentNumber = "unknown"
instrumentNumber = "unknown"
titleSummary = "Water sample during PIRATA-FR29 cruise with 20 levels"
comment = "CTD bottles water sampling with temperature, salinity and oxygen from primary and secondary sensors"
split = ' BOTL,1,month,2,day,3,year,4,PSA1,5,PSA2,6,DO11,7,DO12,8,DO21,9,DO22,10,Potemp090C,11,Potemp190C,12,ETDD,13,PRES,14,DEPH,15,TE01,16,TE02,17,CND1,18,CND2,19,DOV1,20,DOV2,21,DVT1,22,DVT2,23,TUR3,24,FLU2,25'
[split]
[split.ctd]
ETDD = 2
PRES = 3
DEPTH = 4
TEMP = 5
PSAL = 18
DENS = 20
SVEL = 22
DOX2 = 16
FLU2 = 14
FLU3 = 15
TUR3 = 13
NAVG = 24
[split.ctdAll]
ETDD = 2
PRES = 3
DEPTH = 4
TE01 = 5
TE02 = 6
CND1 = 7
CND2 = 8
DOV1 = 9
DOV2 = 10
DVT1 = 11
DVT2 = 12
TUR3 = 13
FLU2 = 14
FLU3 = 15
DO12 = 16
DO22 = 17
PSA1 = 18
PSA2 = 19
DEN1 = 20
DEN2 = 21
SVEL = 22
NAVG = 24
[split.btl]
BOTL = 1
month = 2
day = 3
year = 4
PSA1 = 5
PSA2 = 6
DO11 = 7
DO12 = 8
DO21 = 9
DO22 = 10
Potemp090C = 11
Potemp190C = 12
ETDD = 13
PRES = 14
DEPH = 15
TE01 = 16
TE02 = 17
CND1 = 18
CND2 = 19
DOV1 = 20
DOV2 = 21
DVT1 = 22
DVT2 = 23
TUR3 = 24
FLU2 = 25
import unittest
import toml
'''
Run all test_* in dir test:
> python -m unittest discover tests -v
> python -m unittest discover -s tests -p 'test_*.py' -v
'''
class testConfig(unittest.TestCase):
def setUp(self):
"""Initialisation des tests."""
self.cfg = toml.load('tests/test.toml')
self.glob = {'author': 'jgrelet IRD March 2019 PIRATA-FR29 cruise',
'debug': False, 'echo': True}
self.cruise = {'cycleMesure': 'PIRATA-FR29', 'plateforme': 'THALASSA', 'callsign': 'FNFP', 'institute': 'IRD',
'timezone': 'GMT', 'beginDate': '01/03/2019', 'endDate': '04/04/2019', 'pi': 'BOURLES',
'creator': 'Jacques.Grelet@ird.fr'}
self.ctd = {'cruisePrefix': 'fr29', 'station': 'Station\\s*:\\s*\\D*(\\d*)', 'stationPrefixLength': 3,
'titleSummary': 'CTD profiles processed during PIRATA-FR29 cruise', 'typeInstrument': 'SBE911+',
'instrumentNumber': '09P1263', 'isHeader': '^[*#]', 'isDevice': ['^\\*\\s+(Sea-Bird)', '(\\*END\\*)'],
'latitude': ['Latitude\\s*:\\s*(\\d+)\\s+(\\d+.\\d+)\\s+(\\w)', 'NMEA Latitude\\s*=\\s*(\\d+\\s+\\d+.\\d+\\s+\\w)'],
'longitude': ['Longitude\\s*:\\s*(\\d+)\\s+(\\d+.\\d+)\\s+(\\w)', 'NMEA Longitude\\s*=\\s*(\\d+\\s+\\d+.\\d+\\s+\\w)'],
'date': 'Date\\s*:\\s*(\\d+)/(\\d+)/(\\d+)', 'hour': '[Heure|Hour]\\s*:\\s*(\\d+)[:hH](\\d+):(\\d+)',
'bottomDepth': 'Bottom Depth\\s*:\\s*(\\d*\\.?\\d+?)\\s*\\S*', 'operator': 'Operator\\s*:\\s*(.*)',
'type': 'Type\\s*:\\s*(.*)'}
self.splitCtd = {'ETDD': 2, 'PRES': 3, 'DEPTH': 4, 'TEMP': 5, 'PSAL': 18,
'DENS': 20, 'SVEL': 22, 'DOX2': 16, 'FLU2': 14, 'FLU3': 15, 'TUR3': 13, 'NAVG': 24}
self.splitCtdAll = {'ETDD': 2, 'PRES': 3, 'DEPTH': 4, 'TE01': 5, 'TE02': 6, 'CND1': 7, 'CND2': 8, 'DOV1': 9, 'DOV2': 10, 'DVT1': 11, 'DVT2': 12,
'TUR3': 13, 'FLU2': 14, 'FLU3': 15, 'DO12': 16, 'DO22': 17, 'PSA1': 18, 'PSA2': 19, 'DEN1': 20, 'DEN2': 21, 'SVEL': 22, 'NAVG': 24}
self.splitBtl = {'BOTL': 1, 'month': 2, 'day': 3, 'year': 4, 'PSA1': 5, 'PSA2': 6, 'DO11': 7,
'DO12': 8, 'DO21': 9, 'DO22': 10, 'Potemp090C': 11, 'Potemp190C': 12,
'ETDD': 13, 'PRES': 14, 'DEPH': 15, 'TE01': 16, 'TE02': 17, 'CND1': 18, 'CND2': 19,
'DOV1': 20, 'DOV2': 21, 'DVT1': 22, 'DVT2': 23, 'TUR3': 24, 'FLU2': 25}
def test_global(self):
''' test block [GLOBAL]'''
d = self.cfg['global']
for k in d.keys():
self.assertEqual(d[k], self.glob[k])
def test_cruise(self):
''' test block [CRUISE]'''
d = self.cfg['cruise']
for k in d.keys():
self.assertEqual(d[k], self.cruise[k])
def test_ctd(self):
''' test block [CTD]'''
d = self.cfg['ctd']
for k in d.keys():
self.assertEqual(d[k], self.ctd[k])
def test_split_ctd(self):
""" Test if all value in block [SPLIT.CTD] are correct """
d = self.cfg['split']['ctd']
for k in d.keys():
self.assertEqual(d[k], self.splitCtd[k])
def test_split_ctdAll(self):
""" Test if all value in block [SPLIT.CTDALL] are correct """
d = self.cfg['split']['ctdAll']
for k in d.keys():
self.assertEqual(d[k], self.splitCtdAll[k])
def test_split_btl(self):
""" Test if all value in block [SPLIT.BTL] are correct """
d = self.cfg['split']['btl']
for k in d.keys():
self.assertEqual(d[k], self.splitBtl[k])
if __name__ == '__main__':
unittest.main()
......@@ -3,14 +3,19 @@ import unittest
from physicalParameter import Roscop
'''
> python -m unittest -v tests/test_roscop.py
Run test in single file
> python - m unittest - v tests/test_roscop.py
Run all test_ * in dir tests:
> python - m unittest discover tests - v
> python - m unittest discover - s tests - p 'test_*.py' - v
'''
class RoscopTest(unittest.TestCase):
class testRoscop(unittest.TestCase):
def setUp(self):
"""Initialisation des tests."""
""" Test initialisation """
self.file = 'code_roscop.csv'
self.r = Roscop(self.file)
......
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