Skip to content

Commit 485a794

Browse files
committed
fixed tests
1 parent 281b54e commit 485a794

File tree

4 files changed

+59
-33
lines changed

4 files changed

+59
-33
lines changed

flowcraft/tests/template_tests/test_mapping2json.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
}
2929
}
3030

31-
#
3231
plasmid_length = {
3332
"ACC1": "10",
3433
"ACC2": "10"
@@ -43,16 +42,13 @@ def fetch_file(tmpdir, request):
4342
# creates a temporary file with the json_dict
4443
json_dict = tmpdir.join("test_json_dict.json")
4544
json_dict.write('{"ACC1": 2000}')
46-
# executes the function to be tested
47-
mapping2json.main(str(depth_file), str(json_dict), "0", "test")
48-
result_dict = json.load(open("{}_mapping.json".format(str(depth_file))))
4945

5046
# finalizer statement that removes .report.json
5147
def remove_test_files():
5248
os.remove(".report.json")
5349
request.addfinalizer(remove_test_files)
5450

55-
return result_dict, str(depth_file)
51+
return json_dict, str(depth_file)
5652

5753

5854
def test_depth_file_reader(tmpdir):
@@ -62,7 +58,7 @@ def test_depth_file_reader(tmpdir):
6258

6359
# create a temporary file to make a dict from
6460
file_handle = tmpdir.join("test_depth_file.txt")
65-
file.write("seq1\t1\t30")
61+
file_handle.write("seq1\t1\t30")
6662

6763
# execute the function to get the dict
6864
result_dict = mapping2json.depth_file_reader(open(str(file)))
@@ -92,22 +88,30 @@ def test_generate_file(fetch_file):
9288
"""
9389
This function tests if the output json file is generated
9490
"""
95-
_, depth_file = fetch_file
91+
json_dict, depth_file = fetch_file
92+
# executes the function to be tested
93+
mapping2json.main(str(depth_file), str(json_dict), "0", "test")
9694
assert os.path.isfile("{}_mapping.json".format(depth_file))
9795

9896

9997
def test_generate_report(fetch_file):
10098
"""
10199
This tests if the report.json file is generated
102100
"""
101+
json_dict, depth_file = fetch_file
102+
# executes the function to be tested
103+
mapping2json.main(str(depth_file), str(json_dict), "0", "test")
103104
assert os.path.isfile(".report.json")
104105

105106

106107
def test_generated_dict(fetch_file):
107108
"""
108109
This function checks if the file contains a dict
109110
"""
110-
result_dict, _ = fetch_file
111+
json_dict, depth_file = fetch_file
112+
# executes the function to be tested
113+
mapping2json.main(str(depth_file), str(json_dict), "0", "test")
114+
result_dict = json.load(open("{}_mapping.json".format(str(depth_file))))
111115
assert isinstance(result_dict, dict)
112116

113117

@@ -116,5 +120,8 @@ def test_generated_dict_contents(fetch_file):
116120
This function tests if the dictionary in the file has the required fields
117121
"""
118122
expected_dict = {"ACC1": 0.0}
119-
result_dict, _ = fetch_file
123+
json_dict, depth_file = fetch_file
124+
# executes the function to be tested
125+
mapping2json.main(str(depth_file), str(json_dict), "0", "test")
126+
result_dict = json.load(open("{}_mapping.json".format(str(depth_file))))
120127
assert result_dict == expected_dict

flowcraft/tests/template_tests/test_mashdist2json.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,49 @@ def fetch_file(tmpdir, request):
1010
mash_file = tmpdir.join("test_depth_file.txt")
1111
mash_file.write("ACC1\tseq1\t0\t900/1000")
1212

13-
mashdist2json.main(str(mash_file), "0.5", "test", "assembly_file")
14-
result_dict = json.load(open("{}.json".format(
15-
str(mash_file).split(".")[0])))
16-
1713
# finalizer statement that removes .report.json
1814
def remove_test_files():
1915
os.remove(".report.json")
2016
request.addfinalizer(remove_test_files)
2117

22-
return result_dict, str(mash_file)
18+
return str(mash_file)
2319

2420

2521
def test_generate_file(fetch_file):
2622
"""
2723
This function tests if the files generated by this template script are
2824
created
2925
"""
30-
_, mash_file = fetch_file
26+
mash_file = fetch_file
27+
mashdist2json.main(str(mash_file), "0.5", "test", "assembly_file")
3128
assert os.path.isfile("{}.json".format(mash_file.split(".")[0]))
3229

3330

3431
def test_generate_report(fetch_file):
3532
"""
3633
This tests if the report.json file is generated
3734
"""
35+
mash_file = fetch_file
36+
mashdist2json.main(str(mash_file), "0.5", "test", "assembly_file")
3837
assert os.path.isfile(".report.json")
3938

4039

4140
def test_generated_dict(fetch_file):
4241
"""
4342
This function checks if the file contains a dict
4443
"""
45-
result_dict, _ = fetch_file
44+
mash_file = fetch_file
45+
mashdist2json.main(str(mash_file), "0.5", "test", "assembly_file")
46+
result_dict = json.load(open("{}.json".format(
47+
str(mash_file).split(".")[0])))
4648
assert isinstance(result_dict, dict)
4749

4850

4951
def test_generated_dict_contents(fetch_file):
5052
# the expected result from loading the dictionary in the generated file
5153
expected_dict = {"ACC1": [1.0, 0.9, "seq1"]}
52-
result_dict, _ = fetch_file
54+
mash_file = fetch_file
55+
mashdist2json.main(str(mash_file), "0.5", "test", "assembly_file")
56+
result_dict = json.load(open("{}.json".format(
57+
str(mash_file).split(".")[0])))
5358
assert result_dict == expected_dict

flowcraft/tests/template_tests/test_mashscreen2json.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,49 @@ def fetch_file(tmpdir, request):
1010
mash_file = tmpdir.join("test_depth_file.txt")
1111
mash_file.write("100\tNA\t30\tNA\tACC1")
1212

13-
mashscreen2json.main(str(mash_file), "test")
14-
result_dict = json.load(open("{}.json".format(
15-
str(mash_file).split(".")[0])))
16-
1713
# finalizer statement that removes .report.json
1814
def remove_test_files():
1915
os.remove(".report.json")
2016
request.addfinalizer(remove_test_files)
2117

22-
return result_dict, str(mash_file)
18+
return str(mash_file)
2319

2420

2521
def test_generate_file(fetch_file):
2622
"""
2723
This function tests if the files generated by this template script are
2824
created
2925
"""
30-
_, mash_file = fetch_file
26+
mash_file = fetch_file
27+
mashscreen2json.main(str(mash_file), "test")
3128
assert os.path.isfile("{}.json".format(mash_file.split(".")[0]))
3229

3330

3431
def test_generate_report(fetch_file):
3532
"""
3633
This tests if the report.json file is generated
3734
"""
35+
mash_file = fetch_file
36+
mashscreen2json.main(str(mash_file), "test")
3837
assert os.path.isfile(".report.json")
3938

4039

4140
def test_generated_dict(fetch_file):
4241
"""
4342
This function checks if the file contains a dict
4443
"""
45-
result_dict, _ = fetch_file
44+
mash_file = fetch_file
45+
mashscreen2json.main(str(mash_file), "test")
46+
result_dict = json.load(open("{}.json".format(
47+
str(mash_file).split(".")[0])))
4648
assert isinstance(result_dict, dict)
4749

4850

4951
def test_generated_dict_contents(fetch_file):
5052
# the expected result from loading the dictionary in the generated file
5153
expected_dict = {"ACC1": [100.0, 1]}
52-
result_dict, _ = fetch_file
54+
mash_file = fetch_file
55+
mashscreen2json.main(str(mash_file), "test")
56+
result_dict = json.load(open("{}.json".format(
57+
str(mash_file).split(".")[0])))
5358
assert result_dict == expected_dict

flowcraft/tests/template_tests/test_pATLAS_consensus_json.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,59 @@ def fetch_file(tmpdir, request):
1414

1515
list_of_files = [str(mash_file), str(depth_file)]
1616

17-
pATLAS_consensus_json.main(list_of_files)
18-
result_dict = json.load(open("consensus_file.json"))
19-
2017
# finalizer statement that removes .report.json
2118
def remove_test_files():
2219
os.remove(".report.json")
2320
request.addfinalizer(remove_test_files)
2421

25-
return result_dict
22+
return list_of_files
2623

2724

2825
def test_generate_file(fetch_file):
2926
"""
3027
Check if consensus output file is generated
3128
"""
29+
list_of_files = fetch_file
30+
pATLAS_consensus_json.main(list_of_files)
3231
assert os.path.isfile("consensus_file.json")
3332

3433

3534
def test_generate_report(fetch_file):
3635
"""
3736
This tests if the report.json file is generated
3837
"""
38+
list_of_files = fetch_file
39+
pATLAS_consensus_json.main(list_of_files)
3940
assert os.path.isfile(".report.json")
4041

4142

4243
def test_generated_dict(fetch_file):
4344
"""
4445
This function checks if the file contains a dict
4546
"""
46-
result_dict = fetch_file
47+
list_of_files = fetch_file
48+
pATLAS_consensus_json.main(list_of_files)
49+
result_dict = json.load(open("consensus_file.json"))
4750
assert isinstance(result_dict, dict)
4851

4952

5053
def test_generated_dict_contents1(fetch_file):
5154
"""
5255
Checks if accession in both expected and result dict is the same
5356
"""
54-
result_dict = fetch_file
57+
list_of_files = fetch_file
58+
pATLAS_consensus_json.main(list_of_files)
59+
result_dict = json.load(open("consensus_file.json"))
5560
assert list(result_dict.keys())[0] == "ACC1"
5661

5762

5863
def test_generated_dict_contents2(fetch_file):
5964
"""
6065
checks if the resulting values for each type of file are the proper type
6166
"""
62-
result_dict = fetch_file
67+
list_of_files = fetch_file
68+
pATLAS_consensus_json.main(list_of_files)
69+
result_dict = json.load(open("consensus_file.json"))
6370
first_file_values = list(result_dict[
6471
list(result_dict.keys())[0]].values())[0]
6572
second_file_values = list(result_dict[
@@ -74,5 +81,7 @@ def test_generated_dict_contents3(fetch_file):
7481
"""
7582
checks that the accession in dict must have two keys
7683
"""
77-
result_dict = fetch_file
84+
list_of_files = fetch_file
85+
pATLAS_consensus_json.main(list_of_files)
86+
result_dict = json.load(open("consensus_file.json"))
7887
assert len(list(result_dict[list(result_dict.keys())[0]].keys())) == 2

0 commit comments

Comments
 (0)