MilesCranmer commited on
Commit
58e25a9
1 Parent(s): 214744b

Test both with and without `bkup` file

Browse files
Files changed (1) hide show
  1. test/test.py +17 -17
test/test.py CHANGED
@@ -290,24 +290,24 @@ class TestPipeline(unittest.TestCase):
290
  4|0.104823045|pow_abs(2.2683423, cos(f3))"""
291
  # Strip the indents:
292
  csv_file_data = "\n".join([l.strip() for l in csv_file_data.split("\n")])
293
- rand_dir = Path(tempfile.mkdtemp())
294
- equation_filename = rand_dir / "equation.csv"
295
- with open(equation_filename, "w") as f:
296
- f.write(csv_file_data)
297
- with open(str(equation_filename) + ".bkup", "w") as f:
298
- f.write(csv_file_data)
299
- model = load(
300
- equation_filename,
301
- n_features_in=5,
302
- feature_names_in=["f0", "f1", "f2", "f3", "f4"],
303
- binary_operators=["+", "*", "/", "-", "^"],
304
- unary_operators=["cos"],
305
- )
306
- X = self.rstate.rand(100, 5)
307
- y_truth = 2.2683423 ** np.cos(X[:, 3])
308
- y_test = model.predict(X, 2)
309
 
310
- np.testing.assert_allclose(y_truth, y_test)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
 
312
  def test_load_model_simple(self):
313
  # Test that we can simply load a model from its equation file.
 
290
  4|0.104823045|pow_abs(2.2683423, cos(f3))"""
291
  # Strip the indents:
292
  csv_file_data = "\n".join([l.strip() for l in csv_file_data.split("\n")])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
 
294
+ for from_backup in [False, True]:
295
+ rand_dir = Path(tempfile.mkdtemp())
296
+ equation_filename = str(rand_dir / "equation.csv")
297
+ with open(equation_filename + (".bkup" if from_backup else ""), "w") as f:
298
+ f.write(csv_file_data)
299
+ model = load(
300
+ equation_filename,
301
+ n_features_in=5,
302
+ feature_names_in=["f0", "f1", "f2", "f3", "f4"],
303
+ binary_operators=["+", "*", "/", "-", "^"],
304
+ unary_operators=["cos"],
305
+ )
306
+ X = self.rstate.rand(100, 5)
307
+ y_truth = 2.2683423 ** np.cos(X[:, 3])
308
+ y_test = model.predict(X, 2)
309
+
310
+ np.testing.assert_allclose(y_truth, y_test)
311
 
312
  def test_load_model_simple(self):
313
  # Test that we can simply load a model from its equation file.