From 7f6d68f244c8e6de89b3ebeefca0126371286898 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 12:06:35 -0400 Subject: [PATCH 01/20] Update Present.py wrap call to draw in try/except with backup call to draw_empty --- crow/uitabs/Present.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/crow/uitabs/Present.py b/crow/uitabs/Present.py index 9388682..fff66d6 100644 --- a/crow/uitabs/Present.py +++ b/crow/uitabs/Present.py @@ -364,13 +364,16 @@ 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, - ) + try: + draw_filled( + totalcolormap, + welldata, + subplt, + row, + col, + ) + except ValueError as ve: + draw_empty(subplt, row, col, wellnum, ve) # write numbers accross the top if row == 0: subplt[row, col].set_title(str(wellnum + 1)) From c72b27e8c3608657bacc3bd0edeb761f3318d817 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 15:46:55 -0400 Subject: [PATCH 02/20] test runner not termianting --- .github/workflows/run_tests.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index d39e765..a038024 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -22,10 +22,8 @@ jobs: 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 discover + run: | + coverage run --source=. --omit=test/*,setup.py,crow/__main__.py -m unittest discover - name: Show Coverage run: | coverage report -m From 1bbf83cba3538155e9bd0e5444d5e76d62d74011 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 16:19:35 -0400 Subject: [PATCH 03/20] fix CI testing unexpected behavior when trying to avoid unhelpful errors in empty wells --- .github/workflows/run_tests.yml | 6 ++++-- crow/uitabs/Present.py | 20 ++++++++++++++++---- test/test_Crow.py | 26 ++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index a038024..d39e765 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -22,8 +22,10 @@ jobs: python -m pip install coverage - name: Run Tests - run: | - coverage run --source=. --omit=test/*,setup.py,crow/__main__.py -m unittest discover + uses: GabrielBB/xvfb-action@v1 + with: + run: | + coverage run --source=. --omit=test/*,setup.py,crow/__main__.py -m unittest discover - name: Show Coverage run: | coverage report -m diff --git a/crow/uitabs/Present.py b/crow/uitabs/Present.py index fff66d6..15bb36a 100644 --- a/crow/uitabs/Present.py +++ b/crow/uitabs/Present.py @@ -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): """ @@ -200,7 +204,7 @@ def presentdatacallback(): messagebox.showerror("Error!", "Please select a layout.") def draw_empty(subplt, row, col, wellnum, e): # pragma: no cover - subplt[row, col].pie([0]) + subplt[row, col].pie([0], normalize=False) warningmessage = ( "Issue displaying well " + str(wellnum + 1) @@ -364,7 +368,7 @@ def graphic_generator(exceldata, subplotdims, totalcolormap, dims): except Exception as e: draw_empty(subplt, row, col, wellnum, e) else: - try: + if not (any([i < 0 for i in welldata]) or all(i == 0 for i in welldata)): draw_filled( totalcolormap, welldata, @@ -372,8 +376,16 @@ def graphic_generator(exceldata, subplotdims, totalcolormap, dims): row, col, ) - except ValueError as ve: - draw_empty(subplt, row, col, wellnum, ve) + 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)) diff --git a/test/test_Crow.py b/test/test_Crow.py index 9cf0c73..8b98e4f 100644 --- a/test/test_Crow.py +++ b/test/test_Crow.py @@ -626,11 +626,29 @@ def test_Present(self): 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.messagebox.showwarning") as test_warning: with patch("crow.uitabs.Present.mylog") as test_logger: - pres.presentbutton.invoke() - self.assertTrue(test_error.called) - self.assertTrue(test_logger.called) + with patch("crow.uitabs.Present.plot.show") as test_plot: + pres.presentbutton.invoke() + self.assertTrue(test_plot.called) + self.assertTrue(test_warning.called) + self.assertTrue(test_logger.called) + + # test all layouts with zeros + cg = crow_globals() + cg.datafiles = ["test/data/processed_96-well_data_with_zeros.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.showwarning") as test_warning: + with patch("crow.uitabs.Present.mylog") as test_logger: + with patch("crow.uitabs.Present.plot.show") as test_plot: + pres.presentbutton.invoke() + self.assertTrue(test_plot.called) + self.assertTrue(test_warning.called) + self.assertTrue(test_logger.called) # wrong data type cg = crow_globals() From 17adff40821a1264e1e52d469f0859c0835d5239 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 16:28:04 -0400 Subject: [PATCH 04/20] deepsource antipattern fix --- crow/uitabs/Present.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crow/uitabs/Present.py b/crow/uitabs/Present.py index aae6bce..8ee5a6b 100644 --- a/crow/uitabs/Present.py +++ b/crow/uitabs/Present.py @@ -396,7 +396,7 @@ def graphic_generator(exceldata, subplotdims, totalcolormap, dims): except Exception as e: draw_empty(subplt, row, col, wellnum, e) else: - if not (any([i < 0 for i in welldata]) or all(i == 0 for i in welldata)): + if not (any(i < 0 for i in welldata) or all(i == 0 for i in welldata)): draw_filled( totalcolormap, welldata, From 693fe7f4e9ebeb75cac0053b34a4172fc4d24931 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 17:09:05 -0400 Subject: [PATCH 05/20] legend fixed --- crow/uitabs/Present.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/crow/uitabs/Present.py b/crow/uitabs/Present.py index 8ee5a6b..0273423 100644 --- a/crow/uitabs/Present.py +++ b/crow/uitabs/Present.py @@ -347,7 +347,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 @@ -416,7 +418,10 @@ def graphic_generator(exceldata, subplotdims, totalcolormap, dims): ) # 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( @@ -425,6 +430,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(): @@ -443,12 +449,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')], From 6aa9b555d4c119bb084654916da76f0dd5e2c542 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 17:17:44 -0400 Subject: [PATCH 06/20] xvfb running out of memory, close plots --- test/test_Crow.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/test_Crow.py b/test/test_Crow.py index 8b98e4f..3e8767e 100644 --- a/test/test_Crow.py +++ b/test/test_Crow.py @@ -2,6 +2,7 @@ import os import contextlib import tkinter +import matplotlib.pyplot as plt import unittest from unittest.mock import patch @@ -549,6 +550,7 @@ def test_Present(self): pres.presentbutton.invoke() self.assertTrue(test_plot.called) pres.layout.set(3) + plt.close('all') # test all colormaps for colormap in range(1, 4): @@ -556,6 +558,7 @@ def test_Present(self): with patch("crow.uitabs.Present.plot.show") as test_plot: pres.presentbutton.invoke() self.assertTrue(test_plot.called) + plt.close('all') # test image overlay cg = crow_globals() @@ -582,6 +585,7 @@ def test_Present(self): pres.presentbutton.invoke() self.assertTrue(test_plot.called) os.remove("temp.csv") + plt.close('all') # no colorscheme selected cg = crow_globals() @@ -592,6 +596,7 @@ def test_Present(self): with patch("crow.uitabs.Present.messagebox.showerror") as test_error: pres.presentbutton.invoke() self.assertTrue(test_error.called) + plt.close('all') # save to file cg = crow_globals() @@ -607,6 +612,7 @@ def test_Present(self): self.assertTrue(test_info.called) self.assertTrue(test_save.called) self.assertTrue(test_open.called) + plt.close('all') # no layout selected cg = crow_globals() @@ -617,6 +623,7 @@ def test_Present(self): with patch("crow.uitabs.Present.messagebox.showerror") as test_error: pres.presentbutton.invoke() self.assertTrue(test_error.called) + plt.close('all') # test all layouts with error cg = crow_globals() @@ -633,6 +640,7 @@ def test_Present(self): self.assertTrue(test_plot.called) self.assertTrue(test_warning.called) self.assertTrue(test_logger.called) + plt.close('all') # test all layouts with zeros cg = crow_globals() @@ -649,6 +657,7 @@ def test_Present(self): self.assertTrue(test_plot.called) self.assertTrue(test_warning.called) self.assertTrue(test_logger.called) + plt.close('all') # wrong data type cg = crow_globals() @@ -660,6 +669,7 @@ def test_Present(self): with patch("crow.uitabs.Present.messagebox.showerror") as test_error: pres.presentbutton.invoke() self.assertTrue(test_error.called) + plt.close('all') # no data selected cg = crow_globals() @@ -671,6 +681,7 @@ def test_Present(self): with patch("crow.uitabs.Present.messagebox.showerror") as test_error: pres.presentbutton.invoke() self.assertTrue(test_error.called) + plt.close('all') # too many input files cg = crow_globals() @@ -685,6 +696,7 @@ def test_Present(self): with patch("crow.uitabs.Present.messagebox.showerror") as test_error: pres.presentbutton.invoke() self.assertTrue(test_error.called) + plt.close('all') # input file too big cg = crow_globals() @@ -698,6 +710,7 @@ def test_Present(self): with patch("crow.uitabs.Present.messagebox.showerror") as test_error: pres.presentbutton.invoke() self.assertTrue(test_error.called) + plt.close('all') def test_cutoff(self): """ From 5ec35dd12ff829c72dcb58cfb184d16172ddff83 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 17:38:08 -0400 Subject: [PATCH 07/20] bump version --- crow/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crow/__init__.py b/crow/__init__.py index 1bd3fb2..16042f9 100644 --- a/crow/__init__.py +++ b/crow/__init__.py @@ -1,4 +1,4 @@ from . import uitabs from . import utils -__version__ = "2.0.0" +__version__ = "2.0.1" From f116a1cd89f277b32526e98d13d130942a6de065 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 17:42:36 -0400 Subject: [PATCH 08/20] manually close plots after showing them --- crow/uitabs/Present.py | 1 + test/test_Crow.py | 12 ------------ 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/crow/uitabs/Present.py b/crow/uitabs/Present.py index 0273423..30cabc7 100644 --- a/crow/uitabs/Present.py +++ b/crow/uitabs/Present.py @@ -476,6 +476,7 @@ def graphic_generator(exceldata, subplotdims, totalcolormap, dims): webbrowser.open(fname) else: plot.show() + plot.close() def pickcolor(colormap, cutoffcol, cutoffvalues, cutoffcolors, currentwell): # pragma: no cover """Based on user inputs, choose which color the well should be. diff --git a/test/test_Crow.py b/test/test_Crow.py index 3e8767e..4731f80 100644 --- a/test/test_Crow.py +++ b/test/test_Crow.py @@ -550,7 +550,6 @@ def test_Present(self): pres.presentbutton.invoke() self.assertTrue(test_plot.called) pres.layout.set(3) - plt.close('all') # test all colormaps for colormap in range(1, 4): @@ -558,7 +557,6 @@ def test_Present(self): with patch("crow.uitabs.Present.plot.show") as test_plot: pres.presentbutton.invoke() self.assertTrue(test_plot.called) - plt.close('all') # test image overlay cg = crow_globals() @@ -585,7 +583,6 @@ def test_Present(self): pres.presentbutton.invoke() self.assertTrue(test_plot.called) os.remove("temp.csv") - plt.close('all') # no colorscheme selected cg = crow_globals() @@ -596,7 +593,6 @@ def test_Present(self): with patch("crow.uitabs.Present.messagebox.showerror") as test_error: pres.presentbutton.invoke() self.assertTrue(test_error.called) - plt.close('all') # save to file cg = crow_globals() @@ -612,7 +608,6 @@ def test_Present(self): self.assertTrue(test_info.called) self.assertTrue(test_save.called) self.assertTrue(test_open.called) - plt.close('all') # no layout selected cg = crow_globals() @@ -623,7 +618,6 @@ def test_Present(self): with patch("crow.uitabs.Present.messagebox.showerror") as test_error: pres.presentbutton.invoke() self.assertTrue(test_error.called) - plt.close('all') # test all layouts with error cg = crow_globals() @@ -640,7 +634,6 @@ def test_Present(self): self.assertTrue(test_plot.called) self.assertTrue(test_warning.called) self.assertTrue(test_logger.called) - plt.close('all') # test all layouts with zeros cg = crow_globals() @@ -657,7 +650,6 @@ def test_Present(self): self.assertTrue(test_plot.called) self.assertTrue(test_warning.called) self.assertTrue(test_logger.called) - plt.close('all') # wrong data type cg = crow_globals() @@ -669,7 +661,6 @@ def test_Present(self): with patch("crow.uitabs.Present.messagebox.showerror") as test_error: pres.presentbutton.invoke() self.assertTrue(test_error.called) - plt.close('all') # no data selected cg = crow_globals() @@ -681,7 +672,6 @@ def test_Present(self): with patch("crow.uitabs.Present.messagebox.showerror") as test_error: pres.presentbutton.invoke() self.assertTrue(test_error.called) - plt.close('all') # too many input files cg = crow_globals() @@ -696,7 +686,6 @@ def test_Present(self): with patch("crow.uitabs.Present.messagebox.showerror") as test_error: pres.presentbutton.invoke() self.assertTrue(test_error.called) - plt.close('all') # input file too big cg = crow_globals() @@ -710,7 +699,6 @@ def test_Present(self): with patch("crow.uitabs.Present.messagebox.showerror") as test_error: pres.presentbutton.invoke() self.assertTrue(test_error.called) - plt.close('all') def test_cutoff(self): """ From 88803d5a3cf4313dcc94dc4bf94d40aa0f3820db Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 17:46:23 -0400 Subject: [PATCH 09/20] attempt memory leak fix --- crow/uitabs/Present.py | 1 + 1 file changed, 1 insertion(+) diff --git a/crow/uitabs/Present.py b/crow/uitabs/Present.py index 30cabc7..d63fc0d 100644 --- a/crow/uitabs/Present.py +++ b/crow/uitabs/Present.py @@ -476,6 +476,7 @@ def graphic_generator(exceldata, subplotdims, totalcolormap, dims): webbrowser.open(fname) else: plot.show() + subplt.close() plot.close() def pickcolor(colormap, cutoffcol, cutoffvalues, cutoffcolors, currentwell): # pragma: no cover From 7c09d55d7a37d6adc615ab9d296fb26075ce439e Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 17:49:21 -0400 Subject: [PATCH 10/20] bad change in previous commit, revert --- crow/uitabs/Present.py | 1 - 1 file changed, 1 deletion(-) diff --git a/crow/uitabs/Present.py b/crow/uitabs/Present.py index d63fc0d..30cabc7 100644 --- a/crow/uitabs/Present.py +++ b/crow/uitabs/Present.py @@ -476,7 +476,6 @@ def graphic_generator(exceldata, subplotdims, totalcolormap, dims): webbrowser.open(fname) else: plot.show() - subplt.close() plot.close() def pickcolor(colormap, cutoffcol, cutoffvalues, cutoffcolors, currentwell): # pragma: no cover From 1f76b74d7268f2f63723dfe3fc33c9fe8e90c083 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 17:54:33 -0400 Subject: [PATCH 11/20] change plot clearing --- crow/uitabs/Present.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crow/uitabs/Present.py b/crow/uitabs/Present.py index 30cabc7..3d34e79 100644 --- a/crow/uitabs/Present.py +++ b/crow/uitabs/Present.py @@ -208,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. @@ -476,7 +478,6 @@ def graphic_generator(exceldata, subplotdims, totalcolormap, dims): webbrowser.open(fname) else: plot.show() - plot.close() def pickcolor(colormap, cutoffcol, cutoffvalues, cutoffcolors, currentwell): # pragma: no cover """Based on user inputs, choose which color the well should be. From 11dc497abf5a94d9fa02841fbeddce6177eb5071 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 18:01:04 -0400 Subject: [PATCH 12/20] remove memory intensive test --- test/test_Crow.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/test_Crow.py b/test/test_Crow.py index 4731f80..35a4472 100644 --- a/test/test_Crow.py +++ b/test/test_Crow.py @@ -635,21 +635,21 @@ def test_Present(self): self.assertTrue(test_warning.called) self.assertTrue(test_logger.called) - # test all layouts with zeros - cg = crow_globals() - cg.datafiles = ["test/data/processed_96-well_data_with_zeros.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.showwarning") as test_warning: - with patch("crow.uitabs.Present.mylog") as test_logger: - with patch("crow.uitabs.Present.plot.show") as test_plot: - pres.presentbutton.invoke() - self.assertTrue(test_plot.called) - self.assertTrue(test_warning.called) - self.assertTrue(test_logger.called) + # # test all layouts with zeros + # cg = crow_globals() + # cg.datafiles = ["test/data/processed_96-well_data_with_zeros.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.showwarning") as test_warning: + # with patch("crow.uitabs.Present.mylog") as test_logger: + # with patch("crow.uitabs.Present.plot.show") as test_plot: + # pres.presentbutton.invoke() + # self.assertTrue(test_plot.called) + # self.assertTrue(test_warning.called) + # self.assertTrue(test_logger.called) # wrong data type cg = crow_globals() From 6acfa06aa8ca72e1bb69e54164fe9831bf9f5817 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 18:06:14 -0400 Subject: [PATCH 13/20] remove import, split up tests --- test/test_Crow.py | 65 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/test/test_Crow.py b/test/test_Crow.py index 35a4472..0e89dfa 100644 --- a/test/test_Crow.py +++ b/test/test_Crow.py @@ -2,7 +2,6 @@ import os import contextlib import tkinter -import matplotlib.pyplot as plt import unittest from unittest.mock import patch @@ -534,7 +533,7 @@ def test_Pull(self): os.remove("blank.xml") os.remove(".csv") - def test_Present(self): + def test_Present_1(self): """ Methods of the Present class. """ @@ -558,6 +557,10 @@ def test_Present(self): pres.presentbutton.invoke() self.assertTrue(test_plot.called) + def test_Present_2(self): + """ + Methods of the Present class. + """ # test image overlay cg = crow_globals() with open("test/data/processed_24-well_data_images.csv", "r") as file: @@ -584,6 +587,10 @@ def test_Present(self): self.assertTrue(test_plot.called) os.remove("temp.csv") + def test_Present_3(self): + """ + Methods of the Present class. + """ # no colorscheme selected cg = crow_globals() cg.datafiles = ["test/data/processed_96-well_data.csv"] @@ -594,6 +601,10 @@ def test_Present(self): pres.presentbutton.invoke() self.assertTrue(test_error.called) + def test_Present_4(self): + """ + Methods of the Present class. + """ # save to file cg = crow_globals() cg.datafiles = ["test/data/processed_96-well_data.csv"] @@ -609,6 +620,10 @@ def test_Present(self): self.assertTrue(test_save.called) self.assertTrue(test_open.called) + def test_Present_5(self): + """ + Methods of the Present class. + """ # no layout selected cg = crow_globals() cg.datafiles = ["test/data/processed_96-well_data.csv"] @@ -619,6 +634,10 @@ def test_Present(self): pres.presentbutton.invoke() self.assertTrue(test_error.called) + def test_Present_6(self): + """ + Methods of the Present class. + """ # test all layouts with error cg = crow_globals() cg.datafiles = ["test/data/processed_96-well_data_with_errors.csv"] @@ -635,22 +654,30 @@ def test_Present(self): self.assertTrue(test_warning.called) self.assertTrue(test_logger.called) - # # test all layouts with zeros - # cg = crow_globals() - # cg.datafiles = ["test/data/processed_96-well_data_with_zeros.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.showwarning") as test_warning: - # with patch("crow.uitabs.Present.mylog") as test_logger: - # with patch("crow.uitabs.Present.plot.show") as test_plot: - # pres.presentbutton.invoke() - # self.assertTrue(test_plot.called) - # self.assertTrue(test_warning.called) - # self.assertTrue(test_logger.called) + def test_Present_7(self): + """ + Methods of the Present class. + """ + # test all layouts with zeros + cg = crow_globals() + cg.datafiles = ["test/data/processed_96-well_data_with_zeros.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.showwarning") as test_warning: + with patch("crow.uitabs.Present.mylog") as test_logger: + with patch("crow.uitabs.Present.plot.show") as test_plot: + pres.presentbutton.invoke() + self.assertTrue(test_plot.called) + self.assertTrue(test_warning.called) + self.assertTrue(test_logger.called) + def test_Present_8(self): + """ + Methods of the Present class. + """ # wrong data type cg = crow_globals() cg.datafiles = ["test/data/raw_data_1.xml"] @@ -662,6 +689,10 @@ def test_Present(self): pres.presentbutton.invoke() self.assertTrue(test_error.called) + def test_Present_9(self): + """ + Methods of the Present class. + """ # no data selected cg = crow_globals() cg.datafiles = [] From b3bd750c5e9cbe3414df90a221f9274624cf8298 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 18:15:09 -0400 Subject: [PATCH 14/20] remove memory intensive test --- test/test_Crow.py | 58 +++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/test/test_Crow.py b/test/test_Crow.py index 0e89dfa..d80db45 100644 --- a/test/test_Crow.py +++ b/test/test_Crow.py @@ -557,35 +557,35 @@ def test_Present_1(self): pres.presentbutton.invoke() self.assertTrue(test_plot.called) - def test_Present_2(self): - """ - Methods of the Present class. - """ - # 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") + # def test_Present_2(self): + # """ + # Methods of the Present class. + # """ + # # 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") def test_Present_3(self): """ From 7d694a15418d64d064d3520daa69ff3ddac7421d Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 18:28:18 -0400 Subject: [PATCH 15/20] separate present tests --- .github/workflows/run_tests.yml | 2 +- test/test_Crow.py | 199 ------------------------------ test/test_Present.py | 211 ++++++++++++++++++++++++++++++++ 3 files changed, 212 insertions(+), 200 deletions(-) create mode 100644 test/test_Present.py diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index d39e765..bdccacc 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -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 diff --git a/test/test_Crow.py b/test/test_Crow.py index d80db45..a5aa298 100644 --- a/test/test_Crow.py +++ b/test/test_Crow.py @@ -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): @@ -533,204 +532,6 @@ def test_Pull(self): os.remove("blank.xml") os.remove(".csv") - def test_Present_1(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) - - # def test_Present_2(self): - # """ - # Methods of the Present class. - # """ - # # 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") - - def test_Present_3(self): - """ - Methods of the Present class. - """ - # 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) - - def test_Present_4(self): - """ - Methods of the Present class. - """ - # 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) - - def test_Present_5(self): - """ - Methods of the Present class. - """ - # 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) - - def test_Present_6(self): - """ - Methods of the Present class. - """ - # 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.showwarning") as test_warning: - with patch("crow.uitabs.Present.mylog") as test_logger: - with patch("crow.uitabs.Present.plot.show") as test_plot: - pres.presentbutton.invoke() - self.assertTrue(test_plot.called) - self.assertTrue(test_warning.called) - self.assertTrue(test_logger.called) - - def test_Present_7(self): - """ - Methods of the Present class. - """ - # test all layouts with zeros - cg = crow_globals() - cg.datafiles = ["test/data/processed_96-well_data_with_zeros.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.showwarning") as test_warning: - with patch("crow.uitabs.Present.mylog") as test_logger: - with patch("crow.uitabs.Present.plot.show") as test_plot: - pres.presentbutton.invoke() - self.assertTrue(test_plot.called) - self.assertTrue(test_warning.called) - self.assertTrue(test_logger.called) - - def test_Present_8(self): - """ - Methods of the Present class. - """ - # 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) - - def test_Present_9(self): - """ - Methods of the Present class. - """ - # 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 diff --git a/test/test_Present.py b/test/test_Present.py new file mode 100644 index 0000000..ecd3ff9 --- /dev/null +++ b/test/test_Present.py @@ -0,0 +1,211 @@ +import unittest +import contextlib +import os +from unittest.mock import patch + +from crow.utils.crow_globals import crow_globals +from crow.uitabs.Present import Present + + +class TestCrow(unittest.TestCase): + """ + Test the various functionalities of Crow. + """ + + def test_Present_1(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) + + def test_Present_2(self): + """ + Methods of the Present class. + """ + # 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") + + def test_Present_3(self): + """ + Methods of the Present class. + """ + # 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) + + def test_Present_4(self): + """ + Methods of the Present class. + """ + # 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) + + def test_Present_5(self): + """ + Methods of the Present class. + """ + # 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) + + def test_Present_6(self): + """ + Methods of the Present class. + """ + # 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.showwarning") as test_warning: + with patch("crow.uitabs.Present.mylog") as test_logger: + with patch("crow.uitabs.Present.plot.show") as test_plot: + pres.presentbutton.invoke() + self.assertTrue(test_plot.called) + self.assertTrue(test_warning.called) + self.assertTrue(test_logger.called) + + def test_Present_7(self): + """ + Methods of the Present class. + """ + # test all layouts with zeros + cg = crow_globals() + cg.datafiles = ["test/data/processed_96-well_data_with_zeros.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.showwarning") as test_warning: + with patch("crow.uitabs.Present.mylog") as test_logger: + with patch("crow.uitabs.Present.plot.show") as test_plot: + pres.presentbutton.invoke() + self.assertTrue(test_plot.called) + self.assertTrue(test_warning.called) + self.assertTrue(test_logger.called) + + def test_Present_8(self): + """ + Methods of the Present class. + """ + # 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) + + def test_Present_9(self): + """ + Methods of the Present class. + """ + # 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) From 57a8938ad8a831db739343e52cbb0aca45138890 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 18:33:05 -0400 Subject: [PATCH 16/20] Create run_present_tests.yml --- .github/workflows/run_present_tests.yml | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/run_present_tests.yml diff --git a/.github/workflows/run_present_tests.yml b/.github/workflows/run_present_tests.yml new file mode 100644 index 0000000..5df0ffb --- /dev/null +++ b/.github/workflows/run_present_tests.yml @@ -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 From 85bd34c3a869ea50f89be32d3debcd0ee6ae601f Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 18:50:09 -0400 Subject: [PATCH 17/20] split present tests to deal with memory errors --- .github/workflows/run_present_tests.yml | 2 +- test/test_Present.py | 99 +--------------------- test/test_Present_2.py | 108 ++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 99 deletions(-) create mode 100644 test/test_Present_2.py diff --git a/.github/workflows/run_present_tests.yml b/.github/workflows/run_present_tests.yml index 5df0ffb..f7cc60e 100644 --- a/.github/workflows/run_present_tests.yml +++ b/.github/workflows/run_present_tests.yml @@ -25,7 +25,7 @@ jobs: uses: GabrielBB/xvfb-action@v1 with: run: | - coverage run --source=. --omit=test/*,setup.py,crow/__main__.py -m unittest test/test_Present.py + coverage run --source=. --omit=test/*,setup.py,crow/__main__.py -m unittest test/test_Present.py test/test_Present_2.py - name: Show Coverage run: | coverage report -m diff --git a/test/test_Present.py b/test/test_Present.py index ecd3ff9..6fab149 100644 --- a/test/test_Present.py +++ b/test/test_Present.py @@ -7,7 +7,7 @@ from crow.uitabs.Present import Present -class TestCrow(unittest.TestCase): +class TestPresent(unittest.TestCase): """ Test the various functionalities of Crow. """ @@ -112,100 +112,3 @@ def test_Present_5(self): with patch("crow.uitabs.Present.messagebox.showerror") as test_error: pres.presentbutton.invoke() self.assertTrue(test_error.called) - - def test_Present_6(self): - """ - Methods of the Present class. - """ - # 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.showwarning") as test_warning: - with patch("crow.uitabs.Present.mylog") as test_logger: - with patch("crow.uitabs.Present.plot.show") as test_plot: - pres.presentbutton.invoke() - self.assertTrue(test_plot.called) - self.assertTrue(test_warning.called) - self.assertTrue(test_logger.called) - - def test_Present_7(self): - """ - Methods of the Present class. - """ - # test all layouts with zeros - cg = crow_globals() - cg.datafiles = ["test/data/processed_96-well_data_with_zeros.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.showwarning") as test_warning: - with patch("crow.uitabs.Present.mylog") as test_logger: - with patch("crow.uitabs.Present.plot.show") as test_plot: - pres.presentbutton.invoke() - self.assertTrue(test_plot.called) - self.assertTrue(test_warning.called) - self.assertTrue(test_logger.called) - - def test_Present_8(self): - """ - Methods of the Present class. - """ - # 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) - - def test_Present_9(self): - """ - Methods of the Present class. - """ - # 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) diff --git a/test/test_Present_2.py b/test/test_Present_2.py new file mode 100644 index 0000000..c0fd7f5 --- /dev/null +++ b/test/test_Present_2.py @@ -0,0 +1,108 @@ +import unittest +from unittest.mock import patch + +from crow.utils.crow_globals import crow_globals +from crow.uitabs.Present import Present + + +class TestPresent2(unittest.TestCase): + """ + Test the various functionalities of Crow. + """ + + def test_Present_6(self): + """ + Methods of the Present class. + """ + # 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.showwarning") as test_warning: + with patch("crow.uitabs.Present.mylog") as test_logger: + with patch("crow.uitabs.Present.plot.show") as test_plot: + pres.presentbutton.invoke() + self.assertTrue(test_plot.called) + self.assertTrue(test_warning.called) + self.assertTrue(test_logger.called) + + def test_Present_7(self): + """ + Methods of the Present class. + """ + # test all layouts with zeros + cg = crow_globals() + cg.datafiles = ["test/data/processed_96-well_data_with_zeros.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.showwarning") as test_warning: + with patch("crow.uitabs.Present.mylog") as test_logger: + with patch("crow.uitabs.Present.plot.show") as test_plot: + pres.presentbutton.invoke() + self.assertTrue(test_plot.called) + self.assertTrue(test_warning.called) + self.assertTrue(test_logger.called) + + def test_Present_8(self): + """ + Methods of the Present class. + """ + # 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) + + def test_Present_9(self): + """ + Methods of the Present class. + """ + # 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) From 3866469b357498dbbd2944cc4f5c1faccd684099 Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 18:52:54 -0400 Subject: [PATCH 18/20] Update run_present_tests.yml --- .github/workflows/run_present_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_present_tests.yml b/.github/workflows/run_present_tests.yml index f7cc60e..5df0ffb 100644 --- a/.github/workflows/run_present_tests.yml +++ b/.github/workflows/run_present_tests.yml @@ -25,7 +25,7 @@ jobs: uses: GabrielBB/xvfb-action@v1 with: run: | - coverage run --source=. --omit=test/*,setup.py,crow/__main__.py -m unittest test/test_Present.py test/test_Present_2.py + coverage run --source=. --omit=test/*,setup.py,crow/__main__.py -m unittest test/test_Present.py - name: Show Coverage run: | coverage report -m From a4ff50ad5f1f56003c1386875af1cf1049ac97bd Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 18:55:47 -0400 Subject: [PATCH 19/20] Create run_extended_present_tests.yml --- .../workflows/run_extended_present_tests.yml | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/run_extended_present_tests.yml diff --git a/.github/workflows/run_extended_present_tests.yml b/.github/workflows/run_extended_present_tests.yml new file mode 100644 index 0000000..99e58c9 --- /dev/null +++ b/.github/workflows/run_extended_present_tests.yml @@ -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_2.py + - name: Show Coverage + run: | + coverage report -m From dabe99e37ea12ad73235a127ceb5d1e29a5ccdbe Mon Sep 17 00:00:00 2001 From: JacksonBurns Date: Mon, 14 Mar 2022 18:57:25 -0400 Subject: [PATCH 20/20] Update run_extended_present_tests.yml --- .github/workflows/run_extended_present_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_extended_present_tests.yml b/.github/workflows/run_extended_present_tests.yml index 99e58c9..c60a359 100644 --- a/.github/workflows/run_extended_present_tests.yml +++ b/.github/workflows/run_extended_present_tests.yml @@ -1,4 +1,4 @@ -name: Run Present Tests +name: Run Extended Present Tests on: push: branches: [ main ]