Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #17 from JacksonBurns/bugs-dev
Browse files Browse the repository at this point in the history
Fixing bugs with the legend, empty wells, and memory leaks in `Present`.
  • Loading branch information
JacksonBurns authored Mar 14, 2022
2 parents 2adefe4 + dabe99e commit 7bccc10
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 165 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/run_extended_present_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run Extended Present Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Dependencies
run: |
sudo apt-get install python3-tk
conda install python=3.8
python -m pip install -r requirements.txt
python -m pip install -e .
python -m pip install coverage
- name: Run Tests
uses: GabrielBB/xvfb-action@v1
with:
run: |
coverage run --source=. --omit=test/*,setup.py,crow/__main__.py -m unittest test/test_Present_2.py
- name: Show Coverage
run: |
coverage report -m
31 changes: 31 additions & 0 deletions .github/workflows/run_present_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run Present Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Dependencies
run: |
sudo apt-get install python3-tk
conda install python=3.8
python -m pip install -r requirements.txt
python -m pip install -e .
python -m pip install coverage
- name: Run Tests
uses: GabrielBB/xvfb-action@v1
with:
run: |
coverage run --source=. --omit=test/*,setup.py,crow/__main__.py -m unittest test/test_Present.py
- name: Show Coverage
run: |
coverage report -m
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: GabrielBB/xvfb-action@v1
with:
run: |
coverage run --source=. --omit=test/*,setup.py,crow/__main__.py -m unittest discover
coverage run --source=. --omit=test/*,setup.py,crow/__main__.py -m unittest test/test_Crow.py
- name: Show Coverage
run: |
coverage report -m
2 changes: 1 addition & 1 deletion crow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import uitabs
from . import utils

__version__ = "2.0.0"
__version__ = "2.0.1"
51 changes: 37 additions & 14 deletions crow/uitabs/Present.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
from crow.utils.popupwindows.numberofcutoffs import numberofcutoffsPopup
from crow.utils.popupwindows.shadebyyield import shadebyyieldPopup

import matplotlib as mpl

mpl.rcParams.update({'figure.max_open_warning': 0})


class Present(tk.Frame):
"""
Expand Down Expand Up @@ -204,6 +208,8 @@ def presentdatacallback():
)
else:
messagebox.showerror("Error!", "Please select a layout.")
# regardless of what happened, close active plots
plot.close('all')

def draw_empty(subplt, row, col, wellnum, e): # pragma: no cover
"""Draws an epty pie when an error is encountered.
Expand All @@ -215,7 +221,7 @@ def draw_empty(subplt, row, col, wellnum, e): # pragma: no cover
wellnum (int): Index of well.
e (exception): exception that was raised to get here.
"""
subplt[row, col].pie([0])
subplt[row, col].pie([0], normalize=False)
warningmessage = (
"Issue displaying well "
+ str(wellnum + 1)
Expand Down Expand Up @@ -343,7 +349,9 @@ def graphic_generator(exceldata, subplotdims, totalcolormap, dims):
)
else:
myfig, subplt = plot.subplots(
subplotdims[0], subplotdims[1], figsize=dims
subplotdims[0],
subplotdims[1],
figsize=(dims[1] * 2 * 12, dims[0] * 10),
)
for wellnum in range(0, subplotdims[0] * subplotdims[1]):
# go to position
Expand Down Expand Up @@ -392,16 +400,30 @@ def graphic_generator(exceldata, subplotdims, totalcolormap, dims):
except Exception as e:
draw_empty(subplt, row, col, wellnum, e)
else:
draw_filled(
totalcolormap,
welldata,
subplt,
row,
col,
)
if not (any(i < 0 for i in welldata) or all(i == 0 for i in welldata)):
draw_filled(
totalcolormap,
welldata,
subplt,
row,
col,
)
else:
draw_empty(
subplt,
row,
col,
wellnum,
RuntimeWarning(
"Well {wellnum} is blank or contains a negative number.",
),
)
# write numbers accross the top
if row == 0:
subplt[row, col].set_title(str(wellnum + 1))
subplt[row, col].set_title(
str(wellnum + 1),
fontsize=90,
)
# write letters across the left side
if col == 0:
subplt[row, col].set_ylabel(
Expand All @@ -410,6 +432,7 @@ def graphic_generator(exceldata, subplotdims, totalcolormap, dims):
],
rotation=0,
labelpad=10,
fontsize=90,
)
# draw the image over the well
if self.image_overlay.get():
Expand All @@ -428,12 +451,12 @@ def graphic_generator(exceldata, subplotdims, totalcolormap, dims):
end = len(headers)
for header in headers[:end]:
myfig.text(
0.2 + 0.1 * count,
0.98,
1.05,
0.8 - 0.05 * count,
header.replace("\n", ""),
ha="center",
ha="left",
va="bottom",
size=12,
size=90,
color=totalcolormap[count],
path_effects=[pe.withStroke(
linewidth=1, foreground='black')],
Expand Down
149 changes: 0 additions & 149 deletions test/test_Crow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from crow.utils.popupwindows.shadebyyield import shadebyyieldPopup
from crow.uitabs.PrePull import PrePull
from crow.uitabs.Pull import Pull
from crow.uitabs.Present import Present


class TestCrow(unittest.TestCase):
Expand Down Expand Up @@ -533,154 +532,6 @@ def test_Pull(self):
os.remove("blank.xml")
os.remove(".csv")

def test_Present(self):
"""
Methods of the Present class.
"""
# test all layouts
cg = crow_globals()
cg.datafiles = ["test/data/processed_96-well_data.csv"]
pres = Present("test present", cg)
pres.colorscheme.set(1)
pres.write_to_file.set(False)
for layout in range(1, 7):
pres.layout.set(layout)
with patch("crow.uitabs.Present.plot.show") as test_plot:
pres.presentbutton.invoke()
self.assertTrue(test_plot.called)
pres.layout.set(3)

# test all colormaps
for colormap in range(1, 4):
pres.colorscheme.set(colormap)
with patch("crow.uitabs.Present.plot.show") as test_plot:
pres.presentbutton.invoke()
self.assertTrue(test_plot.called)

# test image overlay
cg = crow_globals()
with open("test/data/processed_24-well_data_images.csv", "r") as file:
procdata = file.readlines()
with open("temp.csv", "w") as file2:
file2.write(procdata[0])
for line in procdata[1:]:
file2.write(
line.replace(
'\n',
"," + os.path.join(os.getcwd(), 'test', 'data', 'blank.png') + '\n'),
)
cg.datafiles = ["temp.csv"]
pres = Present("test present", cg)
pres.colorscheme.set(1)
pres.write_to_file.set(False)
pres.layout.set(3)
pres.image_overlay.set(True)
with patch("crow.uitabs.Present.plot.show") as test_plot:
with open(os.devnull, 'w') as devnull:
with contextlib.redirect_stderr(devnull):
# ignore resource warning
pres.presentbutton.invoke()
self.assertTrue(test_plot.called)
os.remove("temp.csv")

# no colorscheme selected
cg = crow_globals()
cg.datafiles = ["test/data/processed_96-well_data.csv"]
pres = Present("test present", cg)
pres.write_to_file.set(False)
pres.layout.set(1)
with patch("crow.uitabs.Present.messagebox.showerror") as test_error:
pres.presentbutton.invoke()
self.assertTrue(test_error.called)

# save to file
cg = crow_globals()
cg.datafiles = ["test/data/processed_96-well_data.csv"]
pres = Present("test present", cg)
pres.write_to_file.set(True)
pres.colorscheme.set(1)
pres.layout.set(3)
with patch("crow.uitabs.Present.messagebox.showinfo") as test_info:
with patch("crow.uitabs.Present.savefig") as test_save:
with patch("crow.uitabs.Present.webbrowser.open") as test_open:
pres.presentbutton.invoke()
self.assertTrue(test_info.called)
self.assertTrue(test_save.called)
self.assertTrue(test_open.called)

# no layout selected
cg = crow_globals()
cg.datafiles = ["test/data/processed_96-well_data.csv"]
pres = Present("test present", cg)
pres.write_to_file.set(False)
pres.colorscheme.set(1)
with patch("crow.uitabs.Present.messagebox.showerror") as test_error:
pres.presentbutton.invoke()
self.assertTrue(test_error.called)

# test all layouts with error
cg = crow_globals()
cg.datafiles = ["test/data/processed_96-well_data_with_errors.csv"]
pres = Present("test present", cg)
pres.colorscheme.set(1)
pres.write_to_file.set(False)
for layout in range(1, 7):
pres.layout.set(layout)
with patch("crow.uitabs.Present.messagebox.showerror") as test_error:
with patch("crow.uitabs.Present.mylog") as test_logger:
pres.presentbutton.invoke()
self.assertTrue(test_error.called)
self.assertTrue(test_logger.called)

# wrong data type
cg = crow_globals()
cg.datafiles = ["test/data/raw_data_1.xml"]
pres = Present("test present", cg)
pres.write_to_file.set(False)
pres.layout.set(1)
pres.colorscheme.set(1)
with patch("crow.uitabs.Present.messagebox.showerror") as test_error:
pres.presentbutton.invoke()
self.assertTrue(test_error.called)

# no data selected
cg = crow_globals()
cg.datafiles = []
pres = Present("test present", cg)
pres.write_to_file.set(False)
pres.layout.set(1)
pres.colorscheme.set(1)
with patch("crow.uitabs.Present.messagebox.showerror") as test_error:
pres.presentbutton.invoke()
self.assertTrue(test_error.called)

# too many input files
cg = crow_globals()
cg.datafiles = [
"test/data/processed_96-well_data_with_errors.csv",
"test/data/processed_96-well_data.csv",
]
pres = Present("test present", cg)
pres.write_to_file.set(False)
pres.layout.set(1)
pres.colorscheme.set(1)
with patch("crow.uitabs.Present.messagebox.showerror") as test_error:
pres.presentbutton.invoke()
self.assertTrue(test_error.called)

# input file too big
cg = crow_globals()
cg.datafiles = [
"test/data/processed_too_big.csv"
]
pres = Present("test present", cg)
pres.write_to_file.set(False)
pres.layout.set(1)
pres.colorscheme.set(1)
with patch("crow.uitabs.Present.messagebox.showerror") as test_error:
pres.presentbutton.invoke()
self.assertTrue(test_error.called)

def test_cutoff(self):
"""
Launch the popup for getting the cutoff value in present
Expand Down
Loading

0 comments on commit 7bccc10

Please sign in to comment.