Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bethac07 committed Nov 20, 2024
1 parent 2dc91ba commit 42df56b
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 53 deletions.
55 changes: 55 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pytest

@pytest.fixture(scope="module",
params=[
(
'tests/data/Version1/images/',
'tests/data/Version1/images/Index.idx.xml',
'tests/data/Version1/config_v1.yml',
'tests/data/Version1/load_data_version1.csv',
{
"488 long": "OrigRNA",
"Alexa 488": "OrigER",
"Alexa 568": "OrigAGP",
"Alexa 647": "OrigMito",
"HOECHST 33342": "OrigDNA",
"Brightfield": "OrigBrightfield"
},
),
(
'tests/data/Version5/images/',
'tests/data/Version5/images/Index.idx.xml',
'tests/data/Version5/config_v5.yml',
'tests/data/Version5/load_data_version5.csv',
{
"Brightfield high": "OrigBrightfield",
"Alexa 568": "OrigAGP",
"Alexa 647": "OrigMito",
"Alexa 488": "OrigER",
"488 650": "OrigRNA",
"Digital Phase Contrast": "OrigDPC"
},
),
(
'tests/data/Version7/images/',
'tests/data/Version7/images/Index.xml',
'tests/data/Version7/config_v7.yml',
'tests/data/Version7/load_data_version7.csv',
{
"HOECHST 33342": "OrigDNA",
"Alexa 568": "OrigAGP",
"Alexa 647": "OrigMito",
"Alexa 488": "OrigER",
"Alexa 488 Em 650": "OrigRNA",
"Brightfield": "OrigBrightfield",
"405ex, 570-630-em)": "OrigActin"
},
),
],
ids=["v1", "v5", "v7"],)
def test_files(request):
index_directory, index_file, config_file, output_file, expected_channels = request.param
test_dict = {'index_directory':index_directory,'index_file':index_file,
'config_file':config_file,'output_file':output_file,
'expected_channels':expected_channels}
return test_dict
17 changes: 8 additions & 9 deletions tests/test___main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import src.pe2loaddata.__main__


def test_with_file():
def test_with_file(test_files):
runner = click.testing.CliRunner()

command = src.pe2loaddata.__main__.main

result = runner.invoke(command, [
"tests/data/config.yml",
test_files["config_file"],
"--index-file",
"tests/data/images/Index.idx.xml",
test_files["index_file"],
"test.csv"

])
Expand All @@ -20,23 +19,23 @@ def test_with_file():

os.remove("test.csv")

def test_with_directory():
def test_with_directory(test_files):
runner = click.testing.CliRunner()

command = src.pe2loaddata.__main__.main

result = runner.invoke(command, [
"tests/data/config.yml",
test_files["config_file"],
"--index-directory",
"tests/data/images/",
test_files["index_directory"],
"test.csv"
])
assert result.exit_code == 0

os.remove("test.csv")

def test_with_import():
def test_with_import(test_files):
assert not os.path.exists("test.csv")
src.pe2loaddata.__main__.headless("tests/data/config.yml","test.csv",index_file="tests/data/images/Index.idx.xml",index_directory=os.curdir)
src.pe2loaddata.__main__.headless(test_files["config_file"],"test.csv",index_file=test_files["index_file"],index_directory=test_files["index_directory"])
assert os.path.exists("test.csv")
os.remove("test.csv")
44 changes: 14 additions & 30 deletions tests/test_append_illum_cols.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,14 @@ def test_check_dir_arg():
except ArgumentTypeError:
assert True

def test_load_config():
pathname = "./tests/data/config.yml"
def test_load_config(test_files):
pathname = test_files["config_file"]

assert os.path.exists(pathname)

channels = load_config(pathname)

expected_channels = {
"488 long": "OrigRNA",
"Alexa 488": "OrigER",
"Alexa 568": "OrigAGP",
"Alexa 647": "OrigMito",
"HOECHST 33342": "OrigDNA",
"Brightfield": "OrigBrightfield"
}
expected_channels = test_files["expected_channels"]

assert channels == expected_channels

Expand All @@ -69,27 +62,18 @@ def test_parse_args():
pass


def test_main():
config_file = "./tests/data/config.yml"
input_csv = "./tests/data/load_data.csv"
illum_filetype = ".mat"
def test_main(test_files):
config_file = test_files["config_file"]
input_csv = test_files["output_file"]
illum_filetype = ".npy"
nrows = sum(1 for _ in open(input_csv)) - 1



expected_channels = {
"488 long": "OrigRNA",
"Alexa 488": "OrigER",
"Alexa 568": "OrigAGP",
"Alexa 647": "OrigMito",
"HOECHST 33342": "OrigDNA",
"Brightfield": "OrigBrightfield"
}
expected_channels = test_files["expected_channels"]

assert os.path.exists(config_file)
channels = load_config(config_file)
illum_directory = "tests/data/illum/"
plate_id = "BR00100044"
plate_id = "BR00121482"

assert nrows != {}
assert channels == expected_channels
Expand All @@ -102,16 +86,16 @@ def test_main():

os.remove('illum.csv')

def test_write_csv():
config_file = "./tests/data/config.yml"
input_csv = "tests/data/load_data.csv"
illum_filetype = ".mat"
def test_write_csv(test_files):
config_file = test_files["config_file"]
input_csv = test_files["output_file"]
illum_filetype = ".npy"

nrows = sum(1 for _ in open(input_csv)) - 1

channels = load_config(config_file)
illum_directory = "tests/data/illum/"
plate_id = "BR00100044"
plate_id = "BR00121482"

with open('illum.csv', 'w') as fd:
writer = csv.writer(fd, lineterminator='\n')
Expand Down
36 changes: 22 additions & 14 deletions tests/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,14 @@ def test_parse_args():
pass


def test_load_config():
pathname = "./tests/data/config.yml"
def test_load_config(test_files):
pathname = test_files["config_file"]

assert os.path.exists(pathname)

channels, metadata = load_config(pathname)

expected_channels = {
"488 long": "OrigRNA",
"Alexa 488": "OrigER",
"Alexa 568": "OrigAGP",
"Alexa 647": "OrigMito",
"HOECHST 33342": "OrigDNA",
"Brightfield": "OrigBrightfield"
}
expected_channels = test_files["expected_channels"]

expected_metadata = {
"AbsPositionZ": "AbsPositionZ",
Expand Down Expand Up @@ -95,16 +88,16 @@ def test_load_config():
assert metadata == expected_metadata


def test_write_csv():
config_file = "./tests/data/config.yml"
def test_write_csv(test_files):
config_file = test_files["config_file"]

assert os.path.exists(config_file)

channels, metadata = load_config(config_file)

channels = dict([(str(k).replace(" ", ""), v) for (k, v) in channels.items()])

index_file = "./tests/data/images/Index.idx.xml"
index_file = test_files["index_file"]

handler = Handler()

Expand All @@ -117,7 +110,7 @@ def test_write_csv():

paths = {}

index_directory = "./tests/data/images"
index_directory = test_files["index_directory"]

for filename in os.listdir(index_directory):
paths[filename] = index_directory
Expand All @@ -126,5 +119,20 @@ def test_write_csv():
writer = csv.writer(fd, lineterminator='\n')

write_csv(writer, images, plates, wells, maps, channels, metadata, paths)

gt = []
created = []

with open(test_files["output_file"]) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
gt.append(row)

with open("example.csv") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
created.append(row)

assert gt == created

os.remove("example.csv")

0 comments on commit 42df56b

Please sign in to comment.