Skip to content

Commit 7fa39b4

Browse files
committed
housekeeping: Remove contextlib.null_context() usages from last commit
vim macro used: qq /?null_context SHIFT-V /_main $ % << @q Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
1 parent 3f98ebc commit 7fa39b4

9 files changed

Lines changed: 305 additions & 327 deletions

File tree

model/daal4py/tests/test_lr_integration.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import csv
22
import pathlib
3-
import contextlib
43

54
from dffml.cli.cli import CLI
65
from dffml import AsyncTestCase, run_consoletest
@@ -60,24 +59,23 @@ async def test_run(self):
6059
"-source-filename",
6160
data_filename,
6261
)
63-
with contextlib.null_context():
64-
# Make prediction
65-
results = await CLI._main(
66-
"predict",
67-
"all",
68-
*model_args,
69-
"-sources",
70-
"predict_data=csv",
71-
"-source-filename",
72-
data_filename,
73-
)
74-
self.assertTrue(isinstance(results, list))
75-
self.assertEqual(len(results), 10)
76-
for i, result in enumerate(results):
77-
result = result.export()
78-
self.assertIn("prediction", result)
79-
result = result["prediction"]
80-
self.assertIn("ans", result)
81-
result = result["ans"]
82-
self.assertIn("value", result)
83-
result = result["value"]
62+
# Make prediction
63+
results = await CLI._main(
64+
"predict",
65+
"all",
66+
*model_args,
67+
"-sources",
68+
"predict_data=csv",
69+
"-source-filename",
70+
data_filename,
71+
)
72+
self.assertTrue(isinstance(results, list))
73+
self.assertEqual(len(results), 10)
74+
for i, result in enumerate(results):
75+
result = result.export()
76+
self.assertIn("prediction", result)
77+
result = result["prediction"]
78+
self.assertIn("ans", result)
79+
result = result["ans"]
80+
self.assertIn("value", result)
81+
result = result["value"]

model/scikit/tests/test_scikit_integration.py

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55
import csv
66
import pathlib
7-
import contextlib
87

98
import numpy as np
109
from sklearn.datasets import make_blobs, make_regression
@@ -87,23 +86,22 @@ async def test_run(self):
8786
"-source-filename",
8887
test_filename,
8988
)
90-
with contextlib.null_context():
91-
# Make prediction
92-
results = await CLI._main(
93-
"predict",
94-
"all",
95-
"-model",
96-
"scikitsvc",
97-
*features,
98-
"-model-predict",
99-
"true_label:int:1",
100-
"-model-location",
101-
model_dir,
102-
"-sources",
103-
"predict_data=csv",
104-
"-source-filename",
105-
predict_filename,
106-
)
89+
# Make prediction
90+
results = await CLI._main(
91+
"predict",
92+
"all",
93+
"-model",
94+
"scikitsvc",
95+
*features,
96+
"-model-predict",
97+
"true_label:int:1",
98+
"-model-location",
99+
model_dir,
100+
"-sources",
101+
"predict_data=csv",
102+
"-source-filename",
103+
predict_filename,
104+
)
107105
self.assertTrue(isinstance(results, list))
108106
self.assertTrue(results)
109107
results = results[0].export()
@@ -191,23 +189,22 @@ async def test_run(self):
191189
"-source-filename",
192190
test_filename,
193191
)
194-
with contextlib.null_context():
195-
# Make prediction
196-
results = await CLI._main(
197-
"predict",
198-
"all",
199-
"-model",
200-
"scikitridge",
201-
*features,
202-
"-model-predict",
203-
"true_label:float:1",
204-
"-model-location",
205-
model_dir,
206-
"-sources",
207-
"predict_data=csv",
208-
"-source-filename",
209-
predict_filename,
210-
)
192+
# Make prediction
193+
results = await CLI._main(
194+
"predict",
195+
"all",
196+
"-model",
197+
"scikitridge",
198+
*features,
199+
"-model-predict",
200+
"true_label:float:1",
201+
"-model-location",
202+
model_dir,
203+
"-sources",
204+
"predict_data=csv",
205+
"-source-filename",
206+
predict_filename,
207+
)
211208
self.assertTrue(isinstance(results, list))
212209
self.assertTrue(results)
213210
results = results[0]
@@ -342,21 +339,20 @@ async def test_run(self):
342339
]
343340
)
344341
)
345-
with contextlib.null_context():
346-
# Make prediction
347-
results = await CLI._main(
348-
"predict",
349-
"all",
350-
"-model",
351-
model,
352-
"-model-location",
353-
model_dir,
354-
*features,
355-
"-sources",
356-
"predict_data=csv",
357-
"-source-filename",
358-
predict_file,
359-
)
342+
# Make prediction
343+
results = await CLI._main(
344+
"predict",
345+
"all",
346+
"-model",
347+
model,
348+
"-model-location",
349+
model_dir,
350+
*features,
351+
"-sources",
352+
"predict_data=csv",
353+
"-source-filename",
354+
predict_file,
355+
)
360356
self.stdout.truncate(0)
361357
self.stdout.seek(0)
362358
self.assertTrue(isinstance(results, list))

model/scratch/tests/test_lgr_integration.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import csv
22
import pathlib
3-
import contextlib
43

54
from dffml.cli.cli import CLI
65
from dffml.util.asynctestcase import AsyncTestCase
@@ -52,24 +51,23 @@ async def test_run(self):
5251
"-source-filename",
5352
data_filename,
5453
)
55-
with contextlib.null_context():
56-
# Make prediction
57-
results = await CLI._main(
58-
"predict",
59-
"all",
60-
*model_args,
61-
"-sources",
62-
"predict_data=csv",
63-
"-source-filename",
64-
data_filename,
65-
)
66-
self.assertTrue(isinstance(results, list))
67-
self.assertEqual(len(results), 10)
68-
for i, result in enumerate(results):
69-
result = result.export()
70-
self.assertIn("prediction", result)
71-
result = result["prediction"]
72-
self.assertIn("ans", result)
73-
result = result["ans"]
74-
self.assertIn("value", result)
75-
result = result["value"]
54+
# Make prediction
55+
results = await CLI._main(
56+
"predict",
57+
"all",
58+
*model_args,
59+
"-sources",
60+
"predict_data=csv",
61+
"-source-filename",
62+
data_filename,
63+
)
64+
self.assertTrue(isinstance(results, list))
65+
self.assertEqual(len(results), 10)
66+
for i, result in enumerate(results):
67+
result = result.export()
68+
self.assertIn("prediction", result)
69+
result = result["prediction"]
70+
self.assertIn("ans", result)
71+
result = result["ans"]
72+
self.assertIn("value", result)
73+
result = result["value"]

model/scratch/tests/test_slr_integration.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import csv
22
import pathlib
3-
import contextlib
43

54
from dffml.cli.cli import CLI
65
from dffml.util.asynctestcase import AsyncTestCase
@@ -49,25 +48,24 @@ async def test_run(self):
4948
"-source-filename",
5049
data_filename,
5150
)
52-
with contextlib.null_context():
53-
# Make prediction
54-
results = await CLI._main(
55-
"predict",
56-
"all",
57-
*model_args,
58-
"-sources",
59-
"predict_data=csv",
60-
"-source-filename",
61-
data_filename,
62-
)
63-
self.assertTrue(isinstance(results, list))
64-
self.assertEqual(len(results), 6)
65-
for i, result in enumerate(results):
66-
result = result.export()
67-
self.assertIn("prediction", result)
68-
result = result["prediction"]
69-
self.assertIn("Salary", result)
70-
result = result["Salary"]
71-
self.assertIn("value", result)
72-
result = result["value"]
73-
self.assertEqual(round(result), i * 10 + 30)
51+
# Make prediction
52+
results = await CLI._main(
53+
"predict",
54+
"all",
55+
*model_args,
56+
"-sources",
57+
"predict_data=csv",
58+
"-source-filename",
59+
data_filename,
60+
)
61+
self.assertTrue(isinstance(results, list))
62+
self.assertEqual(len(results), 6)
63+
for i, result in enumerate(results):
64+
result = result.export()
65+
self.assertIn("prediction", result)
66+
result = result["prediction"]
67+
self.assertIn("Salary", result)
68+
result = result["Salary"]
69+
self.assertIn("value", result)
70+
result = result["value"]
71+
self.assertEqual(round(result), i * 10 + 30)

model/spacy/tests/test_ner_integration.py

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -137,39 +137,38 @@ async def test_run(self):
137137
"-scorer",
138138
"sner",
139139
)
140-
with contextlib.null_context():
141-
# Make prediction
142-
results = await CLI._main(
143-
"predict",
144-
"all",
145-
"-model",
146-
"spacyner",
147-
"-sources",
148-
"s=op",
149-
"-source-opimp",
150-
"model.spacy.dffml_model_spacy.ner.utils:parser",
151-
"-source-args",
152-
test_data_filename,
153-
"True",
154-
"-log",
155-
"debug",
156-
"-model-model_name",
157-
"en_core_web_sm",
158-
"-model-location",
159-
directory,
160-
"-model-n_iter",
161-
"5",
162-
)
163-
self.assertTrue(isinstance(results, list))
164-
self.assertTrue(results)
165-
results = results[0].export()
166-
self.assertIn("prediction", results)
167-
results = results["prediction"]
168-
self.assertIn("Tag", results)
169-
results = results["Tag"]
170-
self.assertIn("value", results)
171-
results = results["value"]
172-
self.assertIn(results[0][1], ["ORG", "PERSON"])
140+
# Make prediction
141+
results = await CLI._main(
142+
"predict",
143+
"all",
144+
"-model",
145+
"spacyner",
146+
"-sources",
147+
"s=op",
148+
"-source-opimp",
149+
"model.spacy.dffml_model_spacy.ner.utils:parser",
150+
"-source-args",
151+
test_data_filename,
152+
"True",
153+
"-log",
154+
"debug",
155+
"-model-model_name",
156+
"en_core_web_sm",
157+
"-model-location",
158+
directory,
159+
"-model-n_iter",
160+
"5",
161+
)
162+
self.assertTrue(isinstance(results, list))
163+
self.assertTrue(results)
164+
results = results[0].export()
165+
self.assertIn("prediction", results)
166+
results = results["prediction"]
167+
self.assertIn("Tag", results)
168+
results = results["Tag"]
169+
self.assertIn("value", results)
170+
results = results["value"]
171+
self.assertIn(results[0][1], ["ORG", "PERSON"])
173172

174173
# Make prediction using dffml.operations.predict
175174
result = await Develop.cli(
@@ -243,15 +242,14 @@ def clean_args(fd, directory):
243242
"r",
244243
) as f:
245244
predict_cmnd = clean_args(f, tempdir)
246-
with contextlib.null_context():
247-
results = await CLI._main(*predict_cmnd[1:])
248-
self.assertTrue(isinstance(results, list))
249-
self.assertTrue(results)
250-
results = results[0]
251-
self.assertIn("prediction", results)
252-
results = results["prediction"]
253-
self.assertIn("Tag", results)
254-
results = results["Tag"]
255-
self.assertIn("value", results)
256-
results = results["value"]
257-
self.assertIn(result[0][1], ["ORG", "PERSON"])
245+
results = await CLI._main(*predict_cmnd[1:])
246+
self.assertTrue(isinstance(results, list))
247+
self.assertTrue(results)
248+
results = results[0].export()
249+
self.assertIn("prediction", results)
250+
results = results["prediction"]
251+
self.assertIn("Tag", results)
252+
results = results["Tag"]
253+
self.assertIn("value", results)
254+
results = results["value"]
255+
self.assertIn(result[0][1], ["ORG", "PERSON"])

0 commit comments

Comments
 (0)