Skip to content

Commit 353293c

Browse files
committed
fixing mock issues, adding random string to avoid dirname collisions
1 parent 35ec2bb commit 353293c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

ingest/dot_plot_genes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import multiprocessing
88
import sys
99
import datetime
10+
import string
11+
import random
1012
from dateutil.relativedelta import relativedelta
1113
from functools import partial
1214
from bson.objectid import ObjectId
@@ -68,7 +70,9 @@ def __init__(
6870
self.mongo_connection = MongoConnection()
6971

7072
# the cluster name here is not important, it is only used for directory names
71-
self.cluster_name = f"cluster_entry_{self.cluster_group_id}"
73+
# a random 6-letter slug is appended to the end to avoid directory collisions when running in CI
74+
random_slug = ''.join(random.sample(string.ascii_letters, 6))
75+
self.cluster_name = f"cluster_entry_{self.cluster_group_id}_{random_slug}"
7276
self.output_path = f"{self.cluster_name}/dot_plot_genes"
7377
self.exp_writer = ExpressionWriter(
7478
self.matrix_file_path, self.matrix_file_type, self.cluster_file, self.cluster_name, self.genes_path,

tests/test_dot_plot_genes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import glob
77
from shutil import rmtree
88
from bson.objectid import ObjectId
9+
from unittest.mock import patch
910

1011
sys.path.append("../ingest")
1112
from dot_plot_genes import DotPlotGenes
@@ -210,7 +211,8 @@ def test_process_all_genes(self):
210211
rendered_gene = json.loads(gzip.open(rendered_path).read())
211212
self.assertEqual(self.SERGEF_METRICS, rendered_gene['exp_scores'])
212213

213-
def test_run_transform(self):
214+
@patch("dot_plot_genes.bypass_mongo_writes", return_value=True)
215+
def test_run_transform(self, mock_bypass):
214216
dot_plot = self.setup_sparse()
215217
dot_plot.transform()
216218
total_genes = os.listdir(f"{dot_plot.cluster_name}/dot_plot_genes")
@@ -219,3 +221,4 @@ def test_run_transform(self):
219221
self.assertTrue(os.path.exists(rendered_path))
220222
rendered_gene = json.loads(gzip.open(rendered_path).read())
221223
self.assertEqual(self.OXCT2_METRICS, rendered_gene['exp_scores'])
224+
mock_bypass.assert_called_once()

tests/test_ingest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,8 @@ def test_execute_de_anndata(self):
979979
except:
980980
print(f"Error while deleting file : {file}")
981981

982-
def test_ingest_dot_plot(self):
982+
@patch("dot_plot_genes.bypass_mongo_writes", return_value=True)
983+
def test_ingest_dot_plot(self, mock_bypass):
983984
args = [
984985
"--study-id",
985986
"5d276a50421aa9117c982845",
@@ -1006,6 +1007,7 @@ def test_ingest_dot_plot(self):
10061007

10071008
self.assertEqual(len(status), 1)
10081009
self.assertEqual(status[0], 0)
1010+
mock_bypass.assert_called_once()
10091011

10101012
def test_get_action_from_args(self):
10111013
args = [

0 commit comments

Comments
 (0)