Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Oceano2python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
US191
Oceano2python
Commits
9acb42df
Commit
9acb42df
authored
6 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
works with 3 tests
parent
4dcb3bd7
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Readme-python.txt
+5
-0
5 additions, 0 deletions
Readme-python.txt
__init__.py
+3
-0
3 additions, 0 deletions
__init__.py
physicalParameter.py
+19
-11
19 additions, 11 deletions
physicalParameter.py
tests/test_roscop.py
+33
-0
33 additions, 0 deletions
tests/test_roscop.py
with
60 additions
and
11 deletions
Readme-python.txt
+
5
−
0
View file @
9acb42df
...
@@ -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
This diff is collapsed.
Click to expand it.
__init__.py
0 → 100644
+
3
−
0
View file @
9acb42df
__version__
=
'
0.10.0
'
from
physicalParameter
import
Roscop
This diff is collapsed.
Click to expand it.
roscop
.py
→
physicalParameter
.py
+
19
−
11
View file @
9acb42df
...
@@ -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
.
disp
layCode
(
k
)
# r.disp('TEMP'
)
print
(
r
.
returnCode
(
key
[
0
])[
'
key
'
]
)
# print(r[key])
# print(r[key])
This diff is collapsed.
Click to expand it.
tests/test_roscop.py
0 → 100644
+
33
−
0
View file @
9acb42df
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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment