Skip to content
Snippets Groups Projects
Commit 728c4873 authored by Alex Diebold's avatar Alex Diebold
Browse files

adding tmpdir functionality to tests

parent b7e6f316
No related branches found
No related tags found
No related merge requests found
...@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment