Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetObsCommon
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor 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
MetObs
MetObsCommon
Commits
7ecbd79e
Commit
7ecbd79e
authored
7 years ago
by
Alex Diebold
Browse files
Options
Downloads
Patches
Plain Diff
fixed unit tests. fixed Instrument repr from printing description in the middle
parent
d7a9b450
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
metobscommon/archive/db.py
+1
-1
1 addition, 1 deletion
metobscommon/archive/db.py
metobscommon/tests/archive/unit_tests.py
+31
-23
31 additions, 23 deletions
metobscommon/tests/archive/unit_tests.py
with
32 additions
and
24 deletions
metobscommon/archive/db.py
+
1
−
1
View file @
7ecbd79e
...
...
@@ -79,7 +79,7 @@ class Instrument(Base):
self
.
instrument_filetypes
.
append
(
Instrument_FileType
(
instrument
=
self
,
filetype
=
filetype
))
def
__repr__
(
self
):
output
=
'
{} - {} -
{}
'
.
format
(
self
.
name
,
self
.
site
.
name
,
self
.
description
)
output
=
'
{} - {} -
'
.
format
(
self
.
name
,
self
.
site
.
name
)
if
self
.
instrument_filetypes
:
for
ft_name
in
sorted
([
i_f
.
filetype
.
name
for
i_f
in
self
.
instrument_filetypes
]):
output
+=
'
{}~
'
.
format
(
ft_name
)
...
...
This diff is collapsed.
Click to expand it.
metobscommon/tests/archive/unit_tests.py
+
31
−
23
View file @
7ecbd79e
...
...
@@ -16,8 +16,6 @@ class TestCreate(object):
"""
Test create functionary.
"""
# @pytest.fixture(autouse=True)
def
setup
(
self
):
# self.tmpdir = tmpdir.strpath
# self.database = self.tmpdir = '/' + DATABASE
if
os
.
path
.
isfile
(
DATABASE
):
os
.
remove
(
DATABASE
)
...
...
@@ -87,7 +85,7 @@ class TestCreate(object):
#run inst, site, exp, and filetype queries
queries
=
[]
for
col
in
(
db
.
Instrument
,
db
.
Site
,
db
.
Experiment
,
db
.
FileType
):
queries
.
a
d
d
(
self
.
session
.
query
(
col
).
all
())
queries
.
a
ppen
d
(
self
.
session
.
query
(
col
).
all
())
actual_names
=
[]
for
qry
in
queries
:
for
entry
in
qry
:
...
...
@@ -98,7 +96,7 @@ class TestCreate(object):
'
test_site_1.test_inst_1.qc
'
,
'
test_site_1.test_inst_2.nc
'
,
'
test_site_2.test_inst_3.png
'
]
assert
actual_names
.
sort
ed
()
==
expected_names
.
sort
ed
()
assert
actual_names
.
sort
()
==
expected_names
.
sort
()
class
TestSync
(
object
):
"""
Test sync functionality.
"""
...
...
@@ -108,6 +106,11 @@ class TestSync(object):
#simulate 'python db.py test.db create'
args
=
db
.
parse_args
([
DATABASE
,
'
create
'
])
args
.
func
(
args
)
#create session to perform queries on database
engine
=
create_engine
(
'
sqlite:///
'
+
DATABASE
)
Session
=
sessionmaker
(
bind
=
engine
)
self
.
session
=
Session
()
def
teardown
(
self
):
os
.
remove
(
DATABASE
)
...
...
@@ -128,19 +131,19 @@ class TestSync(object):
"""
Test sync by running a query before and after to ensure files are properly added.
"""
#run file query, ensure it's empty
queries
=
self
.
session
.
query
(
db
.
File
).
all
()
assert
len
(
queries
==
0
)
assert
len
(
queries
)
==
0
#simulate 'python db.py test.db sync'
args
=
db
.
parse_args
([
DATABASE
,
'
sync
'
])
args
.
func
(
args
)
#run file query
queries
=
self
.
session
.
query
(
col
).
all
()
queries
=
self
.
session
.
query
(
db
.
File
).
all
()
actual_names
=
[]
actual_filetypes
=
[]
for
qry
in
queries
:
actual_names
.
append
(
qry
.
relative_path
)
actual_file
s
types
.
append
(
qry
.
filetype
)
actual_filetypes
.
append
(
qry
.
filetype
)
expected_names
=
[
'
data/test_site1_test_exp_1/test_inst_1/111111.qc
'
,
'
data/test_site_1/test_exp_1/test_inst_1/991111.qc
'
,
'
data/test_site_1/test_exp_1/test_inst_2/991113.nc
'
,
...
...
@@ -149,7 +152,7 @@ class TestSync(object):
'
data/test_site_1/tet_inst_1/000101.qc
'
,
'
data/test_site_2/test_inst_3/111111.png
'
,
'
data/test_site_2/test_inst_3/991114.png
'
]
expected_file
nam
es
=
[
'
test_site_1.test_inst_1.qc
'
,
expected_file
typ
es
=
[
'
test_site_1.test_inst_1.qc
'
,
'
test_site_1.test_inst_1.qc
'
,
'
test_site_1.test_inst_2.nc
'
,
'
test_site_1.test_inst_1.ascii
'
,
...
...
@@ -158,8 +161,8 @@ class TestSync(object):
'
test_site_2.test_inst_3.png
'
,
'
test_site_2.test_inst_3.png
'
]
assert
actual_names
.
sort
ed
()
==
expected_names
.
sort
ed
()
assert
actual_file
nam
es
.
sort
ed
()
==
expected_
nam
es
.
sort
ed
()
assert
actual_names
.
sort
()
==
expected_names
.
sort
()
assert
actual_file
typ
es
.
sort
()
==
expected_
filetyp
es
.
sort
()
class
TestQuery
(
object
):
"""
Test query functionality.
...
...
@@ -251,13 +254,13 @@ class TestQuery(object):
for
val
in
qry
:
query_result
=
query_result
+
repr
(
val
)
+
'
\n
'
#make the expected query results in string format
query_expected
=
'''
test_inst_1 - test_site_1 - test_site_1.test_inst_1.ascii~test_site_1.test_inst_1.qc~ -
test_inst_2 - test_site_1 - test_site_1.test_inst_2.nc~ -
test_site_1 - test_exp_1~test_exp_2~ -
test_site_2 - n/a~ -
test_site_3 - test_exp_2~ -
test_exp_1 - 2000-01-01 01:02:03 - 2000-01-02 01:02:03 - test_site_1~ -
test_site_2.test_inst_3.png - None - ??????.png - {start_time:%y%m%d}.png - None - Daily - test_inst_3~ -
query_expected
=
'''
test_inst_1 - test_site_1 - test_site_1.test_inst_1.ascii~test_site_1.test_inst_1.qc~ -
test_inst_1 description
test_inst_2 - test_site_1 - test_site_1.test_inst_2.nc~ -
test_inst_2 description
test_site_1 - test_exp_1~test_exp_2~ -
test_site_1 description
test_site_2 - n/a~ -
test_site_2 description
test_site_3 - test_exp_2~ -
test_site_3 description
test_exp_1 - 2000-01-01 01:02:03 - 2000-01-02 01:02:03 - test_site_1~ -
test_exp_1 description
test_site_2.test_inst_3.png - None - ??????.png - {start_time:%y%m%d}.png - None - Daily - test_inst_3~ -
test_site_2.test_inst_3.png description
test_inst_3 - n/a - test_site_2.test_inst_3.png - data/test_site_2/test_inst_3/991114.png - None - None
'''
#remove indendation from string
...
...
@@ -279,6 +282,11 @@ class TestAdd(object):
#simulate 'python db.py test.db create'
args
=
db
.
parse_args
([
DATABASE
,
'
create
'
])
args
.
func
(
args
)
#create session to perform queries on database
engine
=
create_engine
(
'
sqlite:///
'
+
DATABASE
)
Session
=
sessionmaker
(
bind
=
engine
)
self
.
session
=
Session
()
def
teardown
(
self
):
os
.
remove
(
DATABASE
)
...
...
@@ -299,7 +307,7 @@ class TestAdd(object):
"""
Test add functionality by querying before and after adding two Files.
"""
#run file query, ensure it's empty
queries
=
self
.
session
.
query
(
db
.
File
).
all
()
assert
len
(
queries
==
0
)
assert
len
(
queries
)
==
0
#simulate 'python db.py test.db sync'
args
=
db
.
parse_args
([
DATABASE
,
'
add
'
,
'
-i
'
,
'
test_inst_1
'
,
'
-s
'
,
'
test_site_1
'
,
'
-S
'
...
...
@@ -307,12 +315,12 @@ class TestAdd(object):
args
.
func
(
args
)
#run file query
queries
=
self
.
session
.
query
(
col
).
all
()
queries
=
self
.
session
.
query
(
db
.
File
).
all
()
actual_names
=
[]
actual_filetypes
=
[]
for
qry
in
queries
:
actual_names
.
append
(
qry
.
relative_path
)
actual_file
s
types
.
append
(
qry
.
filetype
)
actual_filetypes
.
append
(
qry
.
filetype
)
expected_names
=
[
'
data/test_site1_test_exp_1/test_inst_1/111111.qc
'
,
'
data/test_site_1/test_exp_1/test_inst_1/991111.qc
'
,
'
data/test_site_1/test_exp_1/test_inst_2/991113.nc
'
,
...
...
@@ -321,7 +329,7 @@ class TestAdd(object):
'
data/test_site_1/tet_inst_1/000101.qc
'
,
'
data/test_site_2/test_inst_3/111111.png
'
,
'
data/test_site_2/test_inst_3/991114.png
'
]
expected_file
nam
es
=
[
'
test_site_1.test_inst_1.qc
'
,
expected_file
typ
es
=
[
'
test_site_1.test_inst_1.qc
'
,
'
test_site_1.test_inst_1.qc
'
,
'
test_site_1.test_inst_2.nc
'
,
'
test_site_1.test_inst_1.ascii
'
,
...
...
@@ -330,5 +338,5 @@ class TestAdd(object):
'
test_site_2.test_inst_3.png
'
,
'
test_site_2.test_inst_3.png
'
]
assert
actual_names
.
sort
ed
()
==
expected_names
.
sort
ed
()
assert
actual_file
nam
es
.
sort
ed
()
==
expected_
nam
es
.
sort
ed
()
assert
actual_names
.
sort
()
==
expected_names
.
sort
()
assert
actual_file
typ
es
.
sort
()
==
expected_
filetyp
es
.
sort
()
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