-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added custom fixtures to plasmid templates tests
- Loading branch information
1 parent
3d6b664
commit 0271f13
Showing
4 changed files
with
151 additions
and
241 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
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,73 +1,53 @@ | ||
import os | ||
import json | ||
import pytest | ||
import flowcraft.templates.mashdist2json as mashdist2json | ||
|
||
|
||
def test_generate_file(tmpdir): | ||
""" | ||
This function tests if the files generated by this template script are | ||
created | ||
""" | ||
|
||
@pytest.fixture | ||
def fetch_file(tmpdir, request): | ||
# create a temporary file mash screen txt file | ||
mash_file = tmpdir.join("test_depth_file.txt") | ||
mash_file.write("ACC1\tseq1\t0\t900/1000") | ||
|
||
mashdist2json.main(str(mash_file), "0.5", "test", "assembly_file") | ||
result_dict = json.load(open("{}.json".format( | ||
str(mash_file).split(".")[0]))) | ||
|
||
assert_message = [] | ||
# conditions to check that files are generated | ||
if not os.path.isfile("{}.json".format( | ||
str(mash_file).split(".")[0])): | ||
assert_message.append("mash dist json not created") | ||
if not os.path.isfile(".report.json"): | ||
assert_message.append(".report.json file was not created") | ||
|
||
# remove the .report.json file | ||
os.remove(".report.json") | ||
# finalizer statement that removes .report.json | ||
def remove_test_files(): | ||
os.remove(".report.json") | ||
request.addfinalizer(remove_test_files) | ||
|
||
assert not assert_message, "errors occurred:\n{}".format( | ||
"\n".join(assert_message) | ||
) | ||
return result_dict, str(mash_file) | ||
|
||
|
||
def test_generated_dict(tmpdir): | ||
def test_generate_file(fetch_file): | ||
""" | ||
This function tests if the files generated by this template script are | ||
created | ||
""" | ||
_, mash_file = fetch_file | ||
assert os.path.isfile("{}.json".format(mash_file.split(".")[0])) | ||
|
||
# create a temporary file mash screen txt file | ||
mash_file = tmpdir.join("test_depth_file.txt") | ||
mash_file.write("ACC1\tseq1\t0\t900/1000") | ||
|
||
# the expected result from loading the dictionary in the generated file | ||
expected_dict = {"ACC1": [1.0, 0.9, "seq1"]} | ||
|
||
mashdist2json.main(str(mash_file), "0.5", "test", "assembly_file") | ||
|
||
result_dict = json.load(open("{}.json".format( | ||
str(mash_file).split(".")[0]))) | ||
|
||
assert_message = [] | ||
def test_generate_report(fetch_file): | ||
""" | ||
This tests if the report.json file is generated | ||
""" | ||
assert os.path.isfile(".report.json") | ||
|
||
# checks if result_dict is indeed a dictionary | ||
if not isinstance(result_dict, dict): | ||
assert_message.append("Contents of the generated file must be a " | ||
"dictionary.") | ||
|
||
if not result_dict == expected_dict: | ||
assert_message.append("The expected dictionary must be equal to the " | ||
"one present in the generated file.\n" | ||
"Expected: {}\n" | ||
"Result: {}". format( | ||
json.dumps(expected_dict), | ||
json.dumps(result_dict) | ||
)) | ||
def test_generated_dict(fetch_file): | ||
""" | ||
This function checks if the file contains a dict | ||
""" | ||
result_dict, _ = fetch_file | ||
assert isinstance(result_dict, dict) | ||
|
||
# remove the .report.json file | ||
os.remove(".report.json") | ||
|
||
assert not assert_message, "Errors occurred:\n{}".format( | ||
"\n".join(assert_message) | ||
) | ||
def test_generated_dict_contents(fetch_file): | ||
# the expected result from loading the dictionary in the generated file | ||
expected_dict = {"ACC1": [1.0, 0.9, "seq1"]} | ||
result_dict, _ = fetch_file | ||
assert result_dict == expected_dict |
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,74 +1,53 @@ | ||
import os | ||
import json | ||
import pytest | ||
import flowcraft.templates.mashscreen2json as mashscreen2json | ||
|
||
|
||
def test_generate_file(tmpdir): | ||
""" | ||
This function tests if the files generated by this template script are | ||
created | ||
""" | ||
|
||
@pytest.fixture | ||
def fetch_file(tmpdir, request): | ||
# create a temporary file mash screen txt file | ||
mash_file = tmpdir.join("test_depth_file.txt") | ||
mash_file.write("100\tNA\t30\tNA\tACC1") | ||
|
||
mashscreen2json.main(str(mash_file), "test") | ||
result_dict = json.load(open("{}.json".format( | ||
str(mash_file).split(".")[0]))) | ||
|
||
assert_message = [] | ||
# conditions to check that files are generated | ||
if not os.path.isfile("{}.json".format( | ||
str(mash_file).split(".")[0])): | ||
assert_message.append("mash screen json not created") | ||
if not os.path.isfile(".report.json"): | ||
assert_message.append(".report.json file was not created") | ||
|
||
# remove the .report.json file | ||
os.remove(".report.json") | ||
# finalizer statement that removes .report.json | ||
def remove_test_files(): | ||
os.remove(".report.json") | ||
request.addfinalizer(remove_test_files) | ||
|
||
assert not assert_message, "errors occurred:\n{}".format( | ||
"\n".join(assert_message) | ||
) | ||
return result_dict, str(mash_file) | ||
|
||
|
||
def test_generated_dict(tmpdir): | ||
def test_generate_file(fetch_file): | ||
""" | ||
This function tests if the files generated by this template script are | ||
created | ||
""" | ||
_, mash_file = fetch_file | ||
assert os.path.isfile("{}.json".format(mash_file.split(".")[0])) | ||
|
||
# create a temporary file mash screen txt file | ||
mash_file = tmpdir.join("test_depth_file.txt") | ||
mash_file.write("100\tNA\t30\tNA\tACC1") | ||
|
||
# the expected result from loading the dictionary in the generated file | ||
expected_dict = {"ACC1": [100.0, 1]} | ||
|
||
mashscreen2json.main(str(mash_file), "test") | ||
|
||
result_dict = json.load(open("{}.json".format( | ||
str(mash_file).split(".")[0]))) | ||
|
||
assert_message = [] | ||
|
||
# checks if result_dict is indeed a dictionary | ||
if not isinstance(result_dict, dict): | ||
assert_message.append("Contents of the generated file must be a " | ||
"dictionary.") | ||
def test_generate_report(fetch_file): | ||
""" | ||
This tests if the report.json file is generated | ||
""" | ||
assert os.path.isfile(".report.json") | ||
|
||
if not result_dict == expected_dict: | ||
assert_message.append("The expected dictionary must be equal to the " | ||
"one present in the generated file.\n" | ||
"Expected: {}\n" | ||
"Result: {}". format( | ||
json.dumps(expected_dict), | ||
json.dumps(result_dict) | ||
)) | ||
|
||
# remove the .report.json file | ||
os.remove(".report.json") | ||
def test_generated_dict(fetch_file): | ||
""" | ||
This function checks if the file contains a dict | ||
""" | ||
result_dict, _ = fetch_file | ||
assert isinstance(result_dict, dict) | ||
|
||
assert not assert_message, "Errors occurred:\n{}".format( | ||
"\n".join(assert_message) | ||
) | ||
|
||
def test_generated_dict_contents(fetch_file): | ||
# the expected result from loading the dictionary in the generated file | ||
expected_dict = {"ACC1": [100.0, 1]} | ||
result_dict, _ = fetch_file | ||
assert result_dict == expected_dict |
Oops, something went wrong.