11"""Tests for VirtualEnvironment class."""
22
3- import os
3+ from pathlib import Path
44from unittest .mock import patch
55
66import pytest
@@ -21,7 +21,7 @@ def venv(self, tmp_path):
2121 ):
2222 venv = VirtualEnvironment (str (venv_path ))
2323 # Create the site-packages directory
24- os . makedirs (venv .site_packages_path , exist_ok = True )
24+ Path (venv .site_packages_path ). mkdir ( parents = True , exist_ok = True )
2525 return venv
2626
2727 def test_import_package_bundle_plain_path (self , venv ):
@@ -30,9 +30,8 @@ def test_import_package_bundle_plain_path(self, venv):
3030
3131 venv .import_package_bundle (bundle_path )
3232
33- pth_file = os .path .join (venv .site_packages_path , "deepnote.pth" )
34- with open (pth_file , "r" ) as f :
35- content = f .read ()
33+ pth_file = Path (venv .site_packages_path ) / "deepnote.pth"
34+ content = pth_file .read_text ()
3635
3736 assert content == f"{ bundle_path } \n "
3837
@@ -43,9 +42,8 @@ def test_import_package_bundle_with_condition_env(self, venv):
4342
4443 venv .import_package_bundle (bundle_path , condition_env = condition_env )
4544
46- pth_file = os .path .join (venv .site_packages_path , "deepnote.pth" )
47- with open (pth_file , "r" ) as f :
48- content = f .read ()
45+ pth_file = Path (venv .site_packages_path ) / "deepnote.pth"
46+ content = pth_file .read_text ()
4947
5048 assert "import os, sys" in content
5149 assert f"sys.path.insert(0, '{ bundle_path } ')" in content
@@ -57,9 +55,8 @@ def test_import_package_bundle_with_priority(self, venv):
5755
5856 venv .import_package_bundle (bundle_path , priority = True )
5957
60- pth_file = os .path .join (venv .site_packages_path , "deepnote.pth" )
61- with open (pth_file , "r" ) as f :
62- content = f .read ()
58+ pth_file = Path (venv .site_packages_path ) / "deepnote.pth"
59+ content = pth_file .read_text ()
6360
6461 assert "import sys" in content
6562 assert f"sys.path.insert(0, '{ bundle_path } ')" in content
@@ -77,9 +74,8 @@ def test_import_package_bundle_ordering(self, venv):
7774 venv .import_package_bundle (system_site , priority = True )
7875 venv .import_package_bundle (kernel_libs )
7976
80- pth_file = os .path .join (venv .site_packages_path , "deepnote.pth" )
81- with open (pth_file , "r" ) as f :
82- lines = f .readlines ()
77+ pth_file = Path (venv .site_packages_path ) / "deepnote.pth"
78+ lines = pth_file .read_text ().splitlines ()
8379
8480 assert len (lines ) == 3
8581 # Line 1: server-libs conditional
@@ -89,3 +85,16 @@ def test_import_package_bundle_ordering(self, venv):
8985 assert f"sys.path.insert(0, '{ system_site } ')" in lines [1 ]
9086 # Line 3: kernel plain path
9187 assert lines [2 ].strip () == kernel_libs
88+
89+ def test_import_package_bundle_condition_env_and_priority_mutually_exclusive (
90+ self , venv
91+ ):
92+ """Test that condition_env and priority cannot be used together."""
93+ bundle_path = "/some/bundle/site-packages"
94+
95+ with pytest .raises (ValueError , match = "mutually exclusive" ):
96+ venv .import_package_bundle (
97+ bundle_path ,
98+ condition_env = "SOME_ENV_VAR" ,
99+ priority = True ,
100+ )
0 commit comments