-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
381 additions
and
716 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,13 +1,18 @@ | ||
#! /bin/bash | ||
#!/bin/bash | ||
|
||
set -xue | ||
|
||
# Run code style checks | ||
pycodestyle | ||
|
||
# Run the template pipeline script with the `make all` command | ||
python tests/template_pipeline.py make all | ||
nosetests -v tests/test_import.py | ||
nosetests -v tests/test_iotools.py | ||
nosetests -v tests/test_pipeline_cluster.py | ||
nosetests -v tests/test_pipeline_control.py | ||
nosetests -v tests/test_pipeline_execution.py | ||
pytest tests/test_pipeline_cli.py | ||
pytest tests/test_pipeline_actions.py | ||
|
||
# Run tests using pytest | ||
pytest -v tests/test_import.py | ||
pytest -v tests/test_iotools.py | ||
pytest -v tests/test_pipeline_cluster.py | ||
pytest -v tests/test_pipeline_control.py | ||
pytest -v tests/test_pipeline_execution.py | ||
pytest -v tests/test_pipeline_cli.py | ||
pytest -v tests/test_pipeline_actions.py |
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
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,85 +1,94 @@ | ||
"""Test cases for the cgatcore.iotools module.""" | ||
|
||
import unittest | ||
import os | ||
import shutil | ||
import tempfile | ||
import time | ||
import cgatcore.iotools as iotools | ||
|
||
|
||
class TestiotoolsTouchFile(unittest.TestCase): | ||
|
||
basename = "test_iotools_touch_file.txt" | ||
|
||
def setUp(self): | ||
self.tempdir = tempfile.mkdtemp() | ||
self.filename = os.path.join(self.tempdir, | ||
self.basename) | ||
|
||
def tearDown(self): | ||
shutil.rmtree(self.tempdir) | ||
|
||
def test_touch_file_creates_empty_file(self): | ||
self.assertFalse(os.path.exists(self.filename)) | ||
iotools.touch_file(self.filename) | ||
self.assertTrue(os.path.exists(self.filename)) | ||
if self.filename.endswith(".gz"): | ||
self.assertFalse(iotools.is_empty(self.filename)) | ||
else: | ||
self.assertTrue(iotools.is_empty(self.filename)) | ||
|
||
with iotools.open_file(self.filename) as inf: | ||
data = inf.read() | ||
self.assertEqual(len(data), 0) | ||
|
||
def test_touch_file_updates_existing_file(self): | ||
with iotools.open_file(self.filename, "w") as outf: | ||
outf.write("some data\n") | ||
created = os.stat(self.filename).st_mtime | ||
time.sleep(1) | ||
iotools.touch_file(self.filename) | ||
modified = os.stat(self.filename).st_mtime | ||
self.assertGreater(modified, created) | ||
with iotools.open_file(self.filename) as inf: | ||
data = inf.read() | ||
self.assertEqual(data, "some data\n") | ||
|
||
|
||
class TestiotoolsTouchFileCompressed(TestiotoolsTouchFile): | ||
|
||
basename = "test_iotools_touch_file.txt.gz" | ||
|
||
|
||
class TestiottoolsIsNested(unittest.TestCase): | ||
|
||
def test_is_nested_with_dict(self): | ||
test_data = { | ||
"key1": { | ||
"nested_key1": "nested_key1" | ||
} | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def temp_file(): | ||
"""Fixture to create and clean up a temporary file.""" | ||
tempdir = tempfile.mkdtemp() | ||
filename = os.path.join(tempdir, "test_iotools_touch_file.txt") | ||
yield filename | ||
shutil.rmtree(tempdir) | ||
|
||
|
||
@pytest.fixture | ||
def temp_file_compressed(): | ||
"""Fixture to create and clean up a temporary compressed file.""" | ||
tempdir = tempfile.mkdtemp() | ||
filename = os.path.join(tempdir, "test_iotools_touch_file.txt.gz") | ||
yield filename | ||
shutil.rmtree(tempdir) | ||
|
||
|
||
def test_touch_file_creates_empty_file(temp_file): | ||
assert not os.path.exists(temp_file) | ||
iotools.touch_file(temp_file) | ||
assert os.path.exists(temp_file) | ||
if temp_file.endswith(".gz"): | ||
assert not iotools.is_empty(temp_file) | ||
else: | ||
assert iotools.is_empty(temp_file) | ||
|
||
with iotools.open_file(temp_file) as inf: | ||
data = inf.read() | ||
assert len(data) == 0 | ||
|
||
|
||
def test_touch_file_updates_existing_file(temp_file): | ||
with iotools.open_file(temp_file, "w") as outf: | ||
outf.write("some data\n") | ||
created = os.stat(temp_file).st_mtime | ||
time.sleep(1) | ||
iotools.touch_file(temp_file) | ||
modified = os.stat(temp_file).st_mtime | ||
assert modified > created | ||
with iotools.open_file(temp_file) as inf: | ||
data = inf.read() | ||
assert data == "some data\n" | ||
|
||
|
||
def test_touch_file_compressed_creates_empty_file(temp_file_compressed): | ||
assert not os.path.exists(temp_file_compressed) | ||
iotools.touch_file(temp_file_compressed) | ||
assert os.path.exists(temp_file_compressed) | ||
if temp_file_compressed.endswith(".gz"): | ||
assert not iotools.is_empty(temp_file_compressed) | ||
else: | ||
assert iotools.is_empty(temp_file_compressed) | ||
|
||
with iotools.open_file(temp_file_compressed) as inf: | ||
data = inf.read() | ||
assert len(data) == 0 | ||
|
||
|
||
def test_is_nested_with_dict(): | ||
test_data = { | ||
"key1": { | ||
"nested_key1": "nested_key1" | ||
} | ||
self.assertTrue(iotools.is_nested(test_data)) | ||
|
||
} | ||
assert iotools.is_nested(test_data) | ||
|
||
class TestiottoolsNestedIter(unittest.TestCase): | ||
|
||
def test_nested_iter_with_dict_of_dicts(self): | ||
test_data = { | ||
"key1": { | ||
"nested_key1": "nested_key1" | ||
} | ||
def test_nested_iter_with_dict_of_dicts(): | ||
test_data = { | ||
"key1": { | ||
"nested_key1": "nested_key1" | ||
} | ||
list(iotools.nested_iter(test_data)) | ||
} | ||
list(iotools.nested_iter(test_data)) | ||
|
||
def test_nested_iter_with_list_of_dicts(self): | ||
test_data = [ | ||
{ | ||
"nested_key1": "nested_key1" | ||
} | ||
] | ||
list(iotools.nested_iter(test_data)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
def test_nested_iter_with_list_of_dicts(): | ||
test_data = [ | ||
{ | ||
"nested_key1": "nested_key1" | ||
} | ||
] | ||
list(iotools.nested_iter(test_data)) |
Oops, something went wrong.