Skip to content

Commit

Permalink
Merge pull request #3 from rosalindfranklininstitute/bug-issue001
Browse files Browse the repository at this point in the history
Bugfix: Issue #2
  • Loading branch information
elainehoml committed Aug 3, 2022
2 parents 06d76a5 + ccfa1b0 commit 2ca848e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 116 deletions.
5 changes: 4 additions & 1 deletion src/quoll/io/tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ def create_patches(Image, tile_size, tiles_output, pad=True):
os.mkdir(tiles_output)
if len(os.listdir(tiles_output)) != 0:
for f in list(os.listdir(tiles_output)):
os.remove(os.path.join(tiles_output, f) )
try:
os.remove(os.path.join(tiles_output, f))
except:
print(f"Could not remove {f}")
for i, tile in enumerate(tiles):
tile_fn = os.path.join(tiles_output, f"{i:03}.tif")
tifffile.imwrite(
Expand Down
115 changes: 0 additions & 115 deletions tests/test_frc_oneimg_cli.py

This file was deleted.

81 changes: 81 additions & 0 deletions tests/test_frc_oneimg_cli_mock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright 2022 Rosalind Franklin Institute
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the License.


from unittest import mock
import unittest
import shutil
import os
import sys
from quoll.ui import frc_oneimg_ui

class OneImgFRCCLIMockTest(unittest.TestCase):
"""
Tests the one image FRC CLI
Test image = ChargeSuppression/SerialFIB-79, Tile 42
"""

@mock.patch(
'sys.argv',
["oneimgfrc",
"./data/042.tif",
"3.3724",
"--save_csv"],
)
def test_oneimgfrc_notiles_savecsv(self):
frc_oneimg_ui.oneimgfrc()
self.assertTrue(os.path.exists("./data/042_oneimgfrc.csv"))
os.remove("./data/042_oneimgfrc.csv")

@mock.patch(
'sys.argv',
["oneimgFRC",
"./data/SerialFIB57_2048x2048.tif",
"3.3724",
"-ts",
"512",
"-td",
"./data/tiles",
"--save_csv"
]
)
def test_oneimgfrc_tiles_savecsv(self):
frc_oneimg_ui.oneimgfrc()
self.assertTrue(os.path.exists("./data/SerialFIB57_2048x2048_oneimgfrc.csv"))
os.remove("./data/SerialFIB57_2048x2048_oneimgfrc.csv")
shutil.rmtree("./data/tiles", ignore_errors=True)

@mock.patch(
'sys.argv',
["oneimgFRC",
"./data/SerialFIB57_2048x2048.tif",
"3.3724",
"-ts",
"512",
"-td",
"./data/tiles",
"--save_heatmap",
"--save_overlay",]
)
def test_oneimgfrc_tiles_saveplots(self):
frc_oneimg_ui.oneimgfrc()
self.assertTrue(os.path.exists("./data/SerialFIB57_2048x2048_overlay.svg"))
self.assertTrue(os.path.exists("./data/SerialFIB57_2048x2048_heatmap.tif"))
os.remove("./data/SerialFIB57_2048x2048_overlay.svg")
os.remove("./data/SerialFIB57_2048x2048_heatmap.tif")
shutil.rmtree("./data/tiles", ignore_errors=True)


if __name__ == "__main__":
unittest.main()
8 changes: 8 additions & 0 deletions tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# Utility imports
import unittest
import sys
import os
import quoll


Expand All @@ -29,6 +30,13 @@ def test_quoll_version_string(self):
Tests that the version string can be correctly accessed from the root of the quoll project.
"""
self.assertTrue("quoll" in sys.modules.keys())

def test_frc_oneimg_entrypoint(self):
"""
Tests that the entry point for oneimgfrc works
"""
exit_status = os.system("oneimgfrc -h")
self.assertEqual(exit_status, 0)


if __name__ == '__main__':
Expand Down

0 comments on commit 2ca848e

Please sign in to comment.