MilesCranmer commited on
Commit
2128884
1 Parent(s): 597782a

Attempt to create temp depot for test env

Browse files
Files changed (1) hide show
  1. test/test_env.py +16 -9
test/test_env.py CHANGED
@@ -2,17 +2,24 @@
2
 
3
  import unittest
4
  from pysr import julia_helpers
 
5
 
6
 
7
  class TestJuliaProject(unittest.TestCase):
8
  def test_custom_shared_env(self):
9
  """Test that we can use PySR in a custom shared env"""
10
- test_env_name = "@pysr_test_env"
11
- julia_helpers.install(julia_project=test_env_name, quiet=True)
12
- Main = julia_helpers.init_julia(julia_project=test_env_name)
13
- Main.eval("using SymbolicRegression")
14
- Main.eval("using Pkg")
15
- cur_project_dir = Main.eval("splitdir(dirname(Base.active_project()))[1]")
16
- potential_shared_project_dirs = Main.eval("Pkg.envdir.(DEPOT_PATH)")
17
- self.assertIn(cur_project_dir, potential_shared_project_dirs)
18
- # TODO: Delete the env at the end.
 
 
 
 
 
 
 
2
 
3
  import unittest
4
  from pysr import julia_helpers
5
+ from tempfile import TemporaryDirectory
6
 
7
 
8
  class TestJuliaProject(unittest.TestCase):
9
  def test_custom_shared_env(self):
10
  """Test that we can use PySR in a custom shared env"""
11
+ with TemporaryDirectory() as tmpdir:
12
+ # Create a temp depot to store julia packages (and our custom env)
13
+ Main = julia_helpers.init_julia()
14
+ Main.eval(
15
+ f'pushfirst!(DEPOT_PATH, "{julia_helpers._escape_filename(tmpdir)}")'
16
+ )
17
+ test_env_name = "@pysr_test_env"
18
+ julia_helpers.install(julia_project=test_env_name, quiet=True)
19
+ Main = julia_helpers.init_julia(julia_project=test_env_name)
20
+ Main.eval("using SymbolicRegression")
21
+ Main.eval("using Pkg")
22
+ cur_project_dir = Main.eval("splitdir(dirname(Base.active_project()))[1]")
23
+ potential_shared_project_dirs = Main.eval("Pkg.envdir(DEPOT_PATH[1])")
24
+ self.assertEqual(cur_project_dir, potential_shared_project_dirs)
25
+ Main.eval("pop!(DEPOT_PATH)")