From 129ecfe26a857c2c66a2402c9c7364b309e9f1c0 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Wed, 15 Sep 2021 16:17:30 +0300 Subject: initial test file for wgcna --- tests/unit/computations/test_wgcna.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/unit/computations/test_wgcna.py (limited to 'tests') diff --git a/tests/unit/computations/test_wgcna.py b/tests/unit/computations/test_wgcna.py new file mode 100644 index 0000000..1ce69a1 --- /dev/null +++ b/tests/unit/computations/test_wgcna.py @@ -0,0 +1,15 @@ +"""module contains python code for wgcna""" +from unittest import TestCase + + +def compute_sum(rhs_val, lhs_val): + """function to compute sum of two numbers""" + return rhs_val+lhs_val + + +class TestWgcna(TestCase): + """test class for wgcna""" + + def test_compute_sum(self): + """test for compute sum function""" + self.assertEqual(compute_sum(1, 2), 3) -- cgit v1.2.3 From ce045ec96bf965eaba077fdba99847a483281aba Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 16 Sep 2021 14:03:25 +0300 Subject: init tests for wgcna --- tests/unit/computations/test_wgcna.py | 36 +++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/unit/computations/test_wgcna.py b/tests/unit/computations/test_wgcna.py index 1ce69a1..8a68985 100644 --- a/tests/unit/computations/test_wgcna.py +++ b/tests/unit/computations/test_wgcna.py @@ -1,15 +1,35 @@ """module contains python code for wgcna""" from unittest import TestCase - - -def compute_sum(rhs_val, lhs_val): - """function to compute sum of two numbers""" - return rhs_val+lhs_val +from gn3.computations.wgcna import dump_wgcna_data +from gn3.computations.wgcna import compose_wgcna_cmd class TestWgcna(TestCase): """test class for wgcna""" - def test_compute_sum(self): - """test for compute sum function""" - self.assertEqual(compute_sum(1, 2), 3) + def test_compose_wgcna_cmd(self): + """test for composing wgcna cmd""" + wgcna_cmd = compose_wgcna_cmd("/wgcna.r", "/tmp/wgcna.json") + self.assertEqual(wgcna_cmd, f"Rscript /wgcna.r /tmp/wgcna.json") + + def test_create_json_data(self): + """test for writing the data to a csv file""" + # # All the traits we have data for (should not contain duplicates) + # All the strains we have data for (contains duplicates) + + trait_sample_data = {"1425642_at": {"129S1/SvImJ": 7.142, "A/J": 7.31, "AKR/J": 7.49, + "B6D2F1": 6.899, "BALB/cByJ": 7.172, "BALB/cJ": 7.396}, + "1457784_at": {"129S1/SvImJ": 7.071, "A/J": 7.05, "AKR/J": 7.313, + "B6D2F1": 6.999, "BALB/cByJ": 7.293, "BALB/cJ": 7.117}, + "1444351_at": {"129S1/SvImJ": 7.221, "A/J": 7.246, "AKR/J": 7.754, + "B6D2F1": 6.866, "BALB/cByJ": 6.752, "BALB/cJ": 7.269} + + } + + expected_input = { + "trait_sample_data": trait_sample_data, + "TOMtype": "unsigned", + "minModuleSize": 30 + } + + _results = dump_wgcna_data(expected_input) -- cgit v1.2.3 From ab8b53a50a601cb95dc0b54279246431c791dd70 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 16 Sep 2021 22:56:21 +0300 Subject: pylint fixes --- tests/unit/computations/test_wgcna.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/unit/computations/test_wgcna.py b/tests/unit/computations/test_wgcna.py index 8a68985..9a88515 100644 --- a/tests/unit/computations/test_wgcna.py +++ b/tests/unit/computations/test_wgcna.py @@ -9,20 +9,28 @@ class TestWgcna(TestCase): def test_compose_wgcna_cmd(self): """test for composing wgcna cmd""" - wgcna_cmd = compose_wgcna_cmd("/wgcna.r", "/tmp/wgcna.json") - self.assertEqual(wgcna_cmd, f"Rscript /wgcna.r /tmp/wgcna.json") + wgcna_cmd = compose_wgcna_cmd( + "/wgcna.r", "/tmp/wgcna.json") + self.assertEqual( + wgcna_cmd, "Rscript /wgcna.r /tmp/wgcna.json") - def test_create_json_data(self): + def test_create_json_file(self): """test for writing the data to a csv file""" # # All the traits we have data for (should not contain duplicates) # All the strains we have data for (contains duplicates) - trait_sample_data = {"1425642_at": {"129S1/SvImJ": 7.142, "A/J": 7.31, "AKR/J": 7.49, - "B6D2F1": 6.899, "BALB/cByJ": 7.172, "BALB/cJ": 7.396}, - "1457784_at": {"129S1/SvImJ": 7.071, "A/J": 7.05, "AKR/J": 7.313, - "B6D2F1": 6.999, "BALB/cByJ": 7.293, "BALB/cJ": 7.117}, - "1444351_at": {"129S1/SvImJ": 7.221, "A/J": 7.246, "AKR/J": 7.754, - "B6D2F1": 6.866, "BALB/cByJ": 6.752, "BALB/cJ": 7.269} + trait_sample_data = {"1425642_at": {"129S1/SvImJ": 7.142, + "A/J": 7.31, "AKR/J": 7.49, + "B6D2F1": 6.899, "BALB/cByJ": 7.172, + "BALB/cJ": 7.396}, + "1457784_at": {"129S1/SvImJ": 7.071, "A/J": 7.05, + "AKR/J": 7.313, + "B6D2F1": 6.999, "BALB/cByJ": 7.293, + "BALB/cJ": 7.117}, + "1444351_at": {"129S1/SvImJ": 7.221, "A/J": 7.246, + "AKR/J": 7.754, + "B6D2F1": 6.866, "BALB/cByJ": 6.752, + "BALB/cJ": 7.269} } @@ -32,4 +40,7 @@ class TestWgcna(TestCase): "minModuleSize": 30 } - _results = dump_wgcna_data(expected_input) + results = dump_wgcna_data( + expected_input) + + self.assertEqual(results, {}) -- cgit v1.2.3 From 580778386f054706086d7ab3d49f2c4f91f110e0 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Wed, 22 Sep 2021 00:48:37 +0300 Subject: init endpoint tests for wgcna --- tests/integration/test_wgcna.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/integration/test_wgcna.py (limited to 'tests') diff --git a/tests/integration/test_wgcna.py b/tests/integration/test_wgcna.py new file mode 100644 index 0000000..65763c1 --- /dev/null +++ b/tests/integration/test_wgcna.py @@ -0,0 +1,37 @@ +"""integration tests for wgcna""" + +from unittest import TestCase +from unittest import mock + +from gn3.app import create_app + + +class WgcnaIntegrationTest(TestCase): + """class contains wgcna integration tests""" + + def setUp(self): + self.app = create_app().test_client() + + @mock.patch("gn3.api.wgcna.call_wgcna_script") + def test_wgcna_endpoint(self, mock_wgcna_api): + """test /api/wgcna/run_wgcna endpoint""" + + wgcna_api_data = { + "eigengenes": ["1224_at", "121412_at", "32342342-at"], + "dendrogram_file_location": "/tmp/dend1.png" + + } + mock_wgcna_api.return_value = wgcna_api_data + + request_data = { + + "trait_sample_data": [], + + + } + + response = self.app.post("/api/wgcna/run_wgcna", + json=request_data, follow_redirects=True) + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.get_json(), wgcna_api_data) -- cgit v1.2.3 From 0f871f49e749eb625f58326adf8f80b3d3b5b932 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Wed, 22 Sep 2021 01:53:45 +0300 Subject: add init tests for call to script --- tests/unit/computations/test_wgcna.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/unit/computations/test_wgcna.py b/tests/unit/computations/test_wgcna.py index 9a88515..fd90732 100644 --- a/tests/unit/computations/test_wgcna.py +++ b/tests/unit/computations/test_wgcna.py @@ -1,12 +1,27 @@ """module contains python code for wgcna""" +from unittest import skip from unittest import TestCase +from unittest import mock + from gn3.computations.wgcna import dump_wgcna_data from gn3.computations.wgcna import compose_wgcna_cmd +from gn3.computations.wgcna import call_wgcna_script class TestWgcna(TestCase): """test class for wgcna""" + @mock.patch("gn3.computations.wgcna.dump_wgcna_data") + def test_call_wgcna_script(self, mock_dump): + """call wgcna script""" + + mock_dump.return_value = "/tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json" + + results = call_wgcna_script( + "/home/kabui/project/genenetwork3/scripts/wgcna_analysis.R", {}) + + self.assertEqual(results, "dsedf") + def test_compose_wgcna_cmd(self): """test for composing wgcna cmd""" wgcna_cmd = compose_wgcna_cmd( @@ -14,6 +29,7 @@ class TestWgcna(TestCase): self.assertEqual( wgcna_cmd, "Rscript /wgcna.r /tmp/wgcna.json") + @skip("to update tests") def test_create_json_file(self): """test for writing the data to a csv file""" # # All the traits we have data for (should not contain duplicates) -- cgit v1.2.3 From 7dbb0e6d27cdb0923e94685cf44d244dd8a2e105 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Sat, 25 Sep 2021 18:33:12 +0300 Subject: minor fixes for unittests --- tests/integration/test_wgcna.py | 2 +- tests/unit/computations/test_wgcna.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/integration/test_wgcna.py b/tests/integration/test_wgcna.py index 65763c1..39dabb2 100644 --- a/tests/integration/test_wgcna.py +++ b/tests/integration/test_wgcna.py @@ -33,5 +33,5 @@ class WgcnaIntegrationTest(TestCase): response = self.app.post("/api/wgcna/run_wgcna", json=request_data, follow_redirects=True) - self.assertEqual(response.status_code, 200) + self.assertEqual(response.status_code, 401) self.assertEqual(response.get_json(), wgcna_api_data) diff --git a/tests/unit/computations/test_wgcna.py b/tests/unit/computations/test_wgcna.py index fd90732..64f6c14 100644 --- a/tests/unit/computations/test_wgcna.py +++ b/tests/unit/computations/test_wgcna.py @@ -25,9 +25,9 @@ class TestWgcna(TestCase): def test_compose_wgcna_cmd(self): """test for composing wgcna cmd""" wgcna_cmd = compose_wgcna_cmd( - "/wgcna.r", "/tmp/wgcna.json") + "wgcna.r", "/tmp/wgcna.json") self.assertEqual( - wgcna_cmd, "Rscript /wgcna.r /tmp/wgcna.json") + wgcna_cmd, "Rscript ./scripts/wgcna.r /tmp/wgcna.json") @skip("to update tests") def test_create_json_file(self): -- cgit v1.2.3 From 0d60b01476e49b094944c1ba4136e4cc8c28aaba Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Mon, 27 Sep 2021 17:30:32 +0300 Subject: add tests for calling wgcna_script --- tests/unit/computations/test_wgcna.py | 96 ++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/unit/computations/test_wgcna.py b/tests/unit/computations/test_wgcna.py index 64f6c14..57224b3 100644 --- a/tests/unit/computations/test_wgcna.py +++ b/tests/unit/computations/test_wgcna.py @@ -11,16 +11,98 @@ from gn3.computations.wgcna import call_wgcna_script class TestWgcna(TestCase): """test class for wgcna""" + @mock.patch("gn3.computations.wgcna.run_cmd") + @mock.patch("gn3.computations.wgcna.compose_wgcna_cmd") @mock.patch("gn3.computations.wgcna.dump_wgcna_data") - def test_call_wgcna_script(self, mock_dump): - """call wgcna script""" + def test_call_wgcna_script(self, mock_dumping_data, mock_compose_wgcna, mock_run_cmd): + """test for calling wgcna script""" + mock_dumping_data.return_value = "/tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json" - mock_dump.return_value = "/tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json" + mock_compose_wgcna.return_value = "Rscript/GUIX_PATH/scripts/r_file.R /tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json" - results = call_wgcna_script( - "/home/kabui/project/genenetwork3/scripts/wgcna_analysis.R", {}) + request_data = { + "trait_names": ["1455537_at", "1425637_at", "1449593_at", "1421945_a_at", "1450423_s_at", "1423841_at", "1451144_at"], + "trait_sample_data": [ + { + "129S1/SvImJ": 7.142, + "A/J": 7.31, + "AKR/J": 7.49, + "B6D2F1": 6.899, + "BALB/cByJ": 7.172, + "BALB/cJ": 7.396 + }, + { + "129S1/SvImJ": 7.071, + "A/J": 7.05, + "AKR/J": 7.313, + "B6D2F1": 6.999, + "BALB/cByJ": 7.293, + "BALB/cJ": 7.117 + }]} - self.assertEqual(results, "dsedf") + mock_run_cmd_results = { + + "code": 0, + "output": "Flagging genes and samples with too many missing values...\n ..step 1\nAllowing parallel execution with up to 3 working processes.\npickSoftThreshold: will use block size 7.\n pickSoftThreshold: calculating connectivity for given powers...\n ..working on genes 1 through 7 of 7\n Flagging genes and samples with too many missing values...\n ..step 1\n ..Working on block 1 .\n TOM calculation: adjacency..\n ..will not use multithreading.\nclustering..\n ....detecting modules..\n ....calculating module eigengenes..\n ....checking kME in modules..\n ..merging modules that are too close..\n mergeCloseModules: Merging modules whose distance is less than 0.15\n mergeCloseModules: less than two proper modules.\n ..color levels are turquoise\n ..there is nothing to merge.\n Calculating new MEs...\n" + } + + json_output = "{\"inputdata\":{\"trait_sample_data \":{},\"minModuleSize\":30,\"TOMtype\":\"unsigned\"},\"outputdata\":{\"eigengenes\":[],\"colors\":[]}}" + + expected_output = { + + "data": { + "inputdata": { + "trait_sample_data ": {}, + "minModuleSize": 30, + "TOMtype": "unsigned" + }, + + "outputdata": { + "eigengenes": [], + "colors": [] + } + }, + + **mock_run_cmd_results + + } + + with mock.patch("builtins.open", mock.mock_open(read_data=json_output)) as mock_file: + + mock_run_cmd.return_value = mock_run_cmd_results + + results = call_wgcna_script( + "Rscript/GUIX_PATH/scripts/r_file.R", request_data) + + mock_dumping_data.assert_called_once_with(request_data) + + mock_compose_wgcna.assert_called_once_with( + "Rscript/GUIX_PATH/scripts/r_file.R", "/tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json") + + mock_run_cmd.assert_called_once_with( + "Rscript/GUIX_PATH/scripts/r_file.R /tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json") + + self.assertEqual(results, expected_output) + + @mock.patch("gn3.computations.wgcna.run_cmd") + @mock.patch("gn3.computations.wgcna.compose_wgcna_cmd") + @mock.patch("gn3.computations.wgcna.dump_wgcna_data") + def test_call_wgcna_script_fails(self, mock_dumping_data, mock_compose_wgcna, mock_run_cmd): + """test for calling wgcna script fails and generates the expected error""" + mock_dumping_data.return_value = "/tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json" + + mock_compose_wgcna.return_value = "Rscript/GUIX_PATH/scripts/r_file.R /tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json" + + expected_error = { + "code": 127, + "output": "could not read the json file" + } + + with mock.patch("builtins.open", mock.mock_open(read_data="")) as mock_file: + + mock_run_cmd.return_value = expected_error + self.assertEqual(call_wgcna_script( + "input_file.R", ""), expected_error) def test_compose_wgcna_cmd(self): """test for composing wgcna cmd""" @@ -29,7 +111,7 @@ class TestWgcna(TestCase): self.assertEqual( wgcna_cmd, "Rscript ./scripts/wgcna.r /tmp/wgcna.json") - @skip("to update tests") + @ skip("to update tests") def test_create_json_file(self): """test for writing the data to a csv file""" # # All the traits we have data for (should not contain duplicates) -- cgit v1.2.3 From a2da1f5dbc49b0137ef6b8ee9e234178521935f3 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Mon, 27 Sep 2021 19:15:23 +0300 Subject: modify integration tests --- tests/integration/test_wgcna.py | 60 ++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/integration/test_wgcna.py b/tests/integration/test_wgcna.py index 39dabb2..078449d 100644 --- a/tests/integration/test_wgcna.py +++ b/tests/integration/test_wgcna.py @@ -13,25 +13,61 @@ class WgcnaIntegrationTest(TestCase): self.app = create_app().test_client() @mock.patch("gn3.api.wgcna.call_wgcna_script") - def test_wgcna_endpoint(self, mock_wgcna_api): + def test_wgcna_endpoint(self, mock_wgcna_script): """test /api/wgcna/run_wgcna endpoint""" - wgcna_api_data = { - "eigengenes": ["1224_at", "121412_at", "32342342-at"], - "dendrogram_file_location": "/tmp/dend1.png" - + wgcna_output_data = { + "code": 0, + "output": "run script successfully", + "data": { + "ModEigens": { + "MEturquoise": [ + 0.0646677768085351, + 0.137200224277058, + 0.63451113720732, + -0.544002665501479, + -0.489487590361863, + 0.197111117570427 + ] + }, + "net_colors": { + "X1": "turquoise", + "X2": "turquoise", + "X3": "turquoise", + "X4": "turquoise" + }, + "imageLoc": "/WGCNAoutput_1uujpTIpC.png" + } } - mock_wgcna_api.return_value = wgcna_api_data request_data = { - - "trait_sample_data": [], - - + "trait_names": [ + "1455537_at", + "1425637_at" + ], + "trait_sample_data": [ + { + "129S1/SvImJ": 6.142, + "A/J": 5.31, + "AKR/J": 3.49, + "B6D2F1": 2.899, + "BALB/cByJ": 1.172, + "BALB/cJ": 7.396 + }, + { + "129S1/SvImJ": 1.42, + "A/J": 2.31, + "AKR/J": 5.49, + "B6D2F1": 3.899, + "BALB/cByJ": 1.172, + "BALB/cJ": 7.396 + } + ] } + mock_wgcna_script.return_value = wgcna_output_data response = self.app.post("/api/wgcna/run_wgcna", json=request_data, follow_redirects=True) - self.assertEqual(response.status_code, 401) - self.assertEqual(response.get_json(), wgcna_api_data) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.get_json(), wgcna_output_data) -- cgit v1.2.3 From 16235188d4ee2ad21a667832baf6cbbea6d8856a Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Mon, 27 Sep 2021 19:15:46 +0300 Subject: modify unittests --- tests/unit/computations/test_wgcna.py | 40 ++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/unit/computations/test_wgcna.py b/tests/unit/computations/test_wgcna.py index 57224b3..ec81d94 100644 --- a/tests/unit/computations/test_wgcna.py +++ b/tests/unit/computations/test_wgcna.py @@ -1,5 +1,4 @@ """module contains python code for wgcna""" -from unittest import skip from unittest import TestCase from unittest import mock @@ -14,8 +13,13 @@ class TestWgcna(TestCase): @mock.patch("gn3.computations.wgcna.run_cmd") @mock.patch("gn3.computations.wgcna.compose_wgcna_cmd") @mock.patch("gn3.computations.wgcna.dump_wgcna_data") - def test_call_wgcna_script(self, mock_dumping_data, mock_compose_wgcna, mock_run_cmd): + def test_call_wgcna_script(self, + mock_dumping_data, + mock_compose_wgcna, + mock_run_cmd): """test for calling wgcna script""" + + # pylint: disable = line-too-long mock_dumping_data.return_value = "/tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json" mock_compose_wgcna.return_value = "Rscript/GUIX_PATH/scripts/r_file.R /tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json" @@ -67,7 +71,7 @@ class TestWgcna(TestCase): } - with mock.patch("builtins.open", mock.mock_open(read_data=json_output)) as mock_file: + with mock.patch("builtins.open", mock.mock_open(read_data=json_output)): mock_run_cmd.return_value = mock_run_cmd_results @@ -77,7 +81,8 @@ class TestWgcna(TestCase): mock_dumping_data.assert_called_once_with(request_data) mock_compose_wgcna.assert_called_once_with( - "Rscript/GUIX_PATH/scripts/r_file.R", "/tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json") + "Rscript/GUIX_PATH/scripts/r_file.R", + "/tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json") mock_run_cmd.assert_called_once_with( "Rscript/GUIX_PATH/scripts/r_file.R /tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json") @@ -88,17 +93,19 @@ class TestWgcna(TestCase): @mock.patch("gn3.computations.wgcna.compose_wgcna_cmd") @mock.patch("gn3.computations.wgcna.dump_wgcna_data") def test_call_wgcna_script_fails(self, mock_dumping_data, mock_compose_wgcna, mock_run_cmd): - """test for calling wgcna script fails and generates the expected error""" + """test for calling wgcna script\ + fails and generates the expected error""" + # pylint: disable = line-too-long, mock_dumping_data.return_value = "/tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json" mock_compose_wgcna.return_value = "Rscript/GUIX_PATH/scripts/r_file.R /tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json" expected_error = { - "code": 127, + "code": 2, "output": "could not read the json file" } - with mock.patch("builtins.open", mock.mock_open(read_data="")) as mock_file: + with mock.patch("builtins.open", mock.mock_open(read_data="")): mock_run_cmd.return_value = expected_error self.assertEqual(call_wgcna_script( @@ -111,8 +118,9 @@ class TestWgcna(TestCase): self.assertEqual( wgcna_cmd, "Rscript ./scripts/wgcna.r /tmp/wgcna.json") - @ skip("to update tests") - def test_create_json_file(self): + @mock.patch("gn3.computations.wgcna.TMPDIR", "/tmp") + @mock.patch("gn3.computations.wgcna.uuid.uuid4") + def test_create_json_file(self, file_name_generator): """test for writing the data to a csv file""" # # All the traits we have data for (should not contain duplicates) # All the strains we have data for (contains duplicates) @@ -138,7 +146,15 @@ class TestWgcna(TestCase): "minModuleSize": 30 } - results = dump_wgcna_data( - expected_input) + with mock.patch("builtins.open", mock.mock_open()) as file_handler: + + file_name_generator.return_value = "facb73ff-7eef-4053-b6ea-e91d3a22a00c" + + results = dump_wgcna_data( + expected_input) + + file_handler.assert_called_once_with( + "/tmp/facb73ff-7eef-4053-b6ea-e91d3a22a00c.json", 'w') - self.assertEqual(results, {}) + self.assertEqual( + results, "/tmp/facb73ff-7eef-4053-b6ea-e91d3a22a00c.json") -- cgit v1.2.3