Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofilipe12 committed Nov 16, 2018
1 parent 281b54e commit 485a794
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 33 deletions.
25 changes: 16 additions & 9 deletions flowcraft/tests/template_tests/test_mapping2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
}
}

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

# finalizer statement that removes .report.json
def remove_test_files():
os.remove(".report.json")
request.addfinalizer(remove_test_files)

return result_dict, str(depth_file)
return json_dict, str(depth_file)


def test_depth_file_reader(tmpdir):
Expand All @@ -62,7 +58,7 @@ def test_depth_file_reader(tmpdir):

# create a temporary file to make a dict from
file_handle = tmpdir.join("test_depth_file.txt")
file.write("seq1\t1\t30")
file_handle.write("seq1\t1\t30")

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


def test_generate_report(fetch_file):
"""
This tests if the report.json file is generated
"""
json_dict, depth_file = fetch_file
# executes the function to be tested
mapping2json.main(str(depth_file), str(json_dict), "0", "test")
assert os.path.isfile(".report.json")


def test_generated_dict(fetch_file):
"""
This function checks if the file contains a dict
"""
result_dict, _ = fetch_file
json_dict, depth_file = fetch_file
# executes the function to be tested
mapping2json.main(str(depth_file), str(json_dict), "0", "test")
result_dict = json.load(open("{}_mapping.json".format(str(depth_file))))
assert isinstance(result_dict, dict)


Expand All @@ -116,5 +120,8 @@ def test_generated_dict_contents(fetch_file):
This function tests if the dictionary in the file has the required fields
"""
expected_dict = {"ACC1": 0.0}
result_dict, _ = fetch_file
json_dict, depth_file = fetch_file
# executes the function to be tested
mapping2json.main(str(depth_file), str(json_dict), "0", "test")
result_dict = json.load(open("{}_mapping.json".format(str(depth_file))))
assert result_dict == expected_dict
21 changes: 13 additions & 8 deletions flowcraft/tests/template_tests/test_mashdist2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,49 @@ def fetch_file(tmpdir, request):
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])))

# finalizer statement that removes .report.json
def remove_test_files():
os.remove(".report.json")
request.addfinalizer(remove_test_files)

return result_dict, str(mash_file)
return str(mash_file)


def test_generate_file(fetch_file):
"""
This function tests if the files generated by this template script are
created
"""
_, mash_file = fetch_file
mash_file = fetch_file
mashdist2json.main(str(mash_file), "0.5", "test", "assembly_file")
assert os.path.isfile("{}.json".format(mash_file.split(".")[0]))


def test_generate_report(fetch_file):
"""
This tests if the report.json file is generated
"""
mash_file = fetch_file
mashdist2json.main(str(mash_file), "0.5", "test", "assembly_file")
assert os.path.isfile(".report.json")


def test_generated_dict(fetch_file):
"""
This function checks if the file contains a dict
"""
result_dict, _ = fetch_file
mash_file = fetch_file
mashdist2json.main(str(mash_file), "0.5", "test", "assembly_file")
result_dict = json.load(open("{}.json".format(
str(mash_file).split(".")[0])))
assert isinstance(result_dict, dict)


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
mash_file = fetch_file
mashdist2json.main(str(mash_file), "0.5", "test", "assembly_file")
result_dict = json.load(open("{}.json".format(
str(mash_file).split(".")[0])))
assert result_dict == expected_dict
21 changes: 13 additions & 8 deletions flowcraft/tests/template_tests/test_mashscreen2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,49 @@ def fetch_file(tmpdir, request):
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])))

# finalizer statement that removes .report.json
def remove_test_files():
os.remove(".report.json")
request.addfinalizer(remove_test_files)

return result_dict, str(mash_file)
return str(mash_file)


def test_generate_file(fetch_file):
"""
This function tests if the files generated by this template script are
created
"""
_, mash_file = fetch_file
mash_file = fetch_file
mashscreen2json.main(str(mash_file), "test")
assert os.path.isfile("{}.json".format(mash_file.split(".")[0]))


def test_generate_report(fetch_file):
"""
This tests if the report.json file is generated
"""
mash_file = fetch_file
mashscreen2json.main(str(mash_file), "test")
assert os.path.isfile(".report.json")


def test_generated_dict(fetch_file):
"""
This function checks if the file contains a dict
"""
result_dict, _ = fetch_file
mash_file = fetch_file
mashscreen2json.main(str(mash_file), "test")
result_dict = json.load(open("{}.json".format(
str(mash_file).split(".")[0])))
assert isinstance(result_dict, dict)


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
mash_file = fetch_file
mashscreen2json.main(str(mash_file), "test")
result_dict = json.load(open("{}.json".format(
str(mash_file).split(".")[0])))
assert result_dict == expected_dict
25 changes: 17 additions & 8 deletions flowcraft/tests/template_tests/test_pATLAS_consensus_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,59 @@ def fetch_file(tmpdir, request):

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

pATLAS_consensus_json.main(list_of_files)
result_dict = json.load(open("consensus_file.json"))

# finalizer statement that removes .report.json
def remove_test_files():
os.remove(".report.json")
request.addfinalizer(remove_test_files)

return result_dict
return list_of_files


def test_generate_file(fetch_file):
"""
Check if consensus output file is generated
"""
list_of_files = fetch_file
pATLAS_consensus_json.main(list_of_files)
assert os.path.isfile("consensus_file.json")


def test_generate_report(fetch_file):
"""
This tests if the report.json file is generated
"""
list_of_files = fetch_file
pATLAS_consensus_json.main(list_of_files)
assert os.path.isfile(".report.json")


def test_generated_dict(fetch_file):
"""
This function checks if the file contains a dict
"""
result_dict = fetch_file
list_of_files = fetch_file
pATLAS_consensus_json.main(list_of_files)
result_dict = json.load(open("consensus_file.json"))
assert isinstance(result_dict, dict)


def test_generated_dict_contents1(fetch_file):
"""
Checks if accession in both expected and result dict is the same
"""
result_dict = fetch_file
list_of_files = fetch_file
pATLAS_consensus_json.main(list_of_files)
result_dict = json.load(open("consensus_file.json"))
assert list(result_dict.keys())[0] == "ACC1"


def test_generated_dict_contents2(fetch_file):
"""
checks if the resulting values for each type of file are the proper type
"""
result_dict = fetch_file
list_of_files = fetch_file
pATLAS_consensus_json.main(list_of_files)
result_dict = json.load(open("consensus_file.json"))
first_file_values = list(result_dict[
list(result_dict.keys())[0]].values())[0]
second_file_values = list(result_dict[
Expand All @@ -74,5 +81,7 @@ def test_generated_dict_contents3(fetch_file):
"""
checks that the accession in dict must have two keys
"""
result_dict = fetch_file
list_of_files = fetch_file
pATLAS_consensus_json.main(list_of_files)
result_dict = json.load(open("consensus_file.json"))
assert len(list(result_dict[list(result_dict.keys())[0]].keys())) == 2

0 comments on commit 485a794

Please sign in to comment.