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
728c4873
Commit
728c4873
authored
7 years ago
by
Alex Diebold
Browse files
Options
Downloads
Patches
Plain Diff
adding tmpdir functionality to tests
parent
b7e6f316
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
metobscommon/tests/archive/unit_tests.py
+13
-9
13 additions, 9 deletions
metobscommon/tests/archive/unit_tests.py
with
13 additions
and
9 deletions
metobscommon/tests/archive/unit_tests.py
+
13
−
9
View file @
728c4873
...
@@ -3,21 +3,25 @@ import db
...
@@ -3,21 +3,25 @@ import db
from
sqlalchemy
import
create_engine
from
sqlalchemy
import
create_engine
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.orm
import
sessionmaker
import
mock
import
mock
import
pytest
import
os
import
os
#test database name
#test database name
DATABASE
=
'
test.db
'
DATABASE
=
'
test.db
'
class
TestCreate
(
object
):
class
TestCreate
(
object
):
"""
Test create functionary.
"""
"""
Test create functionary.
"""
@pytest.fixture
(
autouse
=
True
)
def
setup
(
self
):
def
setup
(
self
,
tmpdir
):
if
os
.
path
.
isfile
(
DATABASE
):
self
.
tmpdir
=
tmpdir
.
strpath
os
.
remove
(
DATABASE
)
self
.
database
=
self
.
tmpdir
=
'
/
'
+
DATABASE
if
os
.
path
.
isfile
(
self
.
database
):
os
.
remove
(
self
.
database
)
def
teardown
(
self
):
def
teardown
(
self
):
os
.
remove
(
DATABASE
)
os
.
remove
(
self
.
database
)
def
setup_class
(
cls
):
def
setup_class
(
cls
):
pass
pass
...
@@ -34,15 +38,15 @@ class TestCreate(object):
...
@@ -34,15 +38,15 @@ class TestCreate(object):
def
test_create_file_exists
(
self
):
def
test_create_file_exists
(
self
):
"""
Test create functionality by checking if the database file exists.
"""
"""
Test create functionality by checking if the database file exists.
"""
#simulate 'python db.py test.db create'
#simulate 'python db.py test.db create'
args
=
db
.
parse_args
([
DATABASE
,
'
create
'
])
args
=
db
.
parse_args
([
self
.
database
,
'
create
'
])
args
.
func
(
args
)
args
.
func
(
args
)
assert
os
.
path
.
exists
(
DATABASE
)
assert
os
.
path
.
exists
(
self
.
database
)
def
test_create_query
(
self
):
def
test_create_query
(
self
):
"""
Test create functionality by querying the entire database and comparing results.
"""
"""
Test create functionality by querying the entire database and comparing results.
"""
#simulate 'python db.py test.db create'
#simulate 'python db.py test.db create'
args
=
db
.
parse_args
([
DATABASE
,
'
create
'
])
args
=
db
.
parse_args
([
self
.
database
,
'
create
'
])
args
.
func
(
args
)
args
.
func
(
args
)
#test input for querying Instrument, Site, Experiment, and FileType
#test input for querying Instrument, Site, Experiment, and FileType
...
@@ -74,7 +78,7 @@ class TestCreate(object):
...
@@ -74,7 +78,7 @@ class TestCreate(object):
with
mock
.
patch
.
object
(
db
,
'
input
'
,
lambda
x
:
next
(
test_input_generator
)):
with
mock
.
patch
.
object
(
db
,
'
input
'
,
lambda
x
:
next
(
test_input_generator
)):
#simulate 'python db.py test.db query -i -s -e -t'
#simulate 'python db.py test.db query -i -s -e -t'
args
=
db
.
parse_args
([
DATABASE
,
'
query
'
,
'
-i
'
,
'
-s
'
,
'
-e
'
,
'
-t
'
])
args
=
db
.
parse_args
([
self
.
database
,
'
query
'
,
'
-i
'
,
'
-s
'
,
'
-e
'
,
'
-t
'
])
queries
=
args
.
func
(
args
)
queries
=
args
.
func
(
args
)
#find how many query results are found total
#find how many query results are found total
...
...
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