Skip to content

Commit

Permalink
tests: Use pytest.fixture for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
ayan-b authored and yunhailuo committed Apr 30, 2019
1 parent 4a14dde commit 59682e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
28 changes: 13 additions & 15 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from io import StringIO

import pandas as pd
import pytest

from xena_gdc_etl import utils

Expand All @@ -20,43 +21,40 @@ def test_mkdir_p():
os.rmdir(input_)


@pytest.fixture
@patch("sys.stdout", new_callable=StringIO)
def test_equal_matrices(mocked_print):
utils.equal_matrices(
"tests/fixtures/df1.csv",
"tests/fixtures/df2.csv",
)
utils.equal_matrices(
"tests/fixtures/df1.csv",
"tests/fixtures/df3.csv",
)
utils.equal_matrices("df1.csv", "df2.csv")
utils.equal_matrices("df1.csv", "df3.csv")
assert mocked_print.getvalue() == "Not equal.\nEqual.\n"


@pytest.fixture
@patch.object(utils, 'time', Mock(wraps=time))
def test_metadata():
utils.time.gmtime.return_value = time.struct_time(
(2019, 4, 28, 0, 0, 0, 0, 0, 0)
)
path_to_df = "tests/fixtures/HTSeq-FPKM-UQ.csv"
path_to_df = "HTSeq-FPKM-UQ.csv"
utils.metadata(path_to_df, "htseq_fpkm-uq")
with open("tests/fixtures/HTSeq-FPKM-UQ.csv.json", "r") as actual:
with open("HTSeq-FPKM-UQ.csv.json", "r") as actual:
actual = json.load(actual)
os.unlink("tests/fixtures/HTSeq-FPKM-UQ.csv.json")
with open("tests/fixtures/HTSeq-FPKM-UQ.json", "r") as expected:
os.unlink("HTSeq-FPKM-UQ.csv.json")
with open("HTSeq-FPKM-UQ.json", "r") as expected:
expected = json.load(expected)
assert actual == expected


@pytest.fixture
def test_merge_xena():
path = "tests/fixtures/"
name = "merged_GDC_TARGET-CCSK.tsv"
filelists = [path + "merge-xena1.csv", path + "merge-xena2.csv"]
filelists = ["merge-xena1.csv", "merge-xena2.csv"]
cohort = "GDC TARGET-CCSK"
datatype = "GDC_phenotype"
path = "tests/fixtures"
outdir = path
utils.handle_merge_xena(name, filelists, cohort, datatype, outdir)
with open(path + "MergedCohort04292019.GDC_phenotype.tsv", "r") as actual:
with open("MergedCohort04292019.GDC_phenotype.tsv", "r") as actual:
actual = pd.read_csv(actual)
with open(path + name, "r") as expected:
expected = pd.read_csv(expected)
Expand Down
1 change: 0 additions & 1 deletion xena_gdc_etl/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import print_function
import argparse
from datetime import date
import os

from .utils import equal_matrices, metadata, handle_merge_xena
from .gdc_check_new import gdc_check_new
Expand Down

0 comments on commit 59682e1

Please sign in to comment.