-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace TmpDir helper with pytest fixtures
- Loading branch information
1 parent
f122430
commit a69a706
Showing
3 changed files
with
315 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import unittest | ||
|
||
import pytest | ||
|
||
from aips import models | ||
from tests.tests_helpers import TmpDir | ||
|
||
THIS_DIR = os.path.abspath(os.path.dirname(__file__)) | ||
TMP_DIR = os.path.join(THIS_DIR, ".tmp-aips-models") | ||
DATABASE_FILE = os.path.join(TMP_DIR, "aips.db") | ||
|
||
|
||
class TestAipsModels(unittest.TestCase): | ||
def test_init_success(self): | ||
"""Test that the database, table and session are created.""" | ||
assert not os.path.isfile(DATABASE_FILE) | ||
assert not hasattr(models, "Session") | ||
with TmpDir(TMP_DIR): | ||
session = models.init(DATABASE_FILE) | ||
assert os.path.isfile(DATABASE_FILE) | ||
assert "aip" in models.Base.metadata.tables | ||
assert hasattr(session, "add") | ||
assert callable(session.add) | ||
|
||
def test_init_fail(self): | ||
"""Test that the database can't be created in a wrong path.""" | ||
self.assertRaises(IOError, models.init, "/this/should/be/a/wrong/path/to.db") | ||
|
||
|
||
def test_init_success(tmp_path): | ||
"""Test that the database, table and session are created.""" | ||
tmp_dir = tmp_path / "dir" | ||
tmp_dir.mkdir() | ||
|
||
DATABASE_FILE = (tmp_dir / "aips.db").as_posix() | ||
|
||
assert not os.path.isfile(DATABASE_FILE) | ||
assert not hasattr(models, "Session") | ||
|
||
session = models.init(DATABASE_FILE) | ||
|
||
assert os.path.isfile(DATABASE_FILE) | ||
assert "aip" in models.Base.metadata.tables | ||
assert hasattr(session, "add") | ||
assert callable(session.add) | ||
|
||
|
||
def test_init_fail(): | ||
"""Test that the database can't be created in a wrong path.""" | ||
with pytest.raises(IOError): | ||
models.init("/this/should/be/a/wrong/path/to.db") |
Oops, something went wrong.