Skip to content

Commit

Permalink
Add test for prefix_name
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen committed Jun 25, 2024
1 parent 4117e74 commit 2c62093
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions tests/test_conda_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@


class TestCondaSubprocess(TestCase):
def setUp(self):
self.env_path = os.path.join(context.root_prefix, "..", "py312")
def setUpClass(cls):
cls.env_name = "py312"
cls.env_path = os.path.join(context.root_prefix, "..", cls.env_name)

def test_call(self):
def test_call_path(self):
self.assertEqual(call("python --version", prefix_path=self.env_path), 0)

def test_check_call(self):
def test_call_name(self):
self.assertEqual(call("python --version", prefix_name=self.env_name), 0)

def test_check_call_path(self):
self.assertEqual(check_call("python --version", prefix_path=self.env_path), 0)

def test_check_output(self):
def test_check_call_name(self):
self.assertEqual(check_call("python --version", prefix_name=self.env_name), 0)

def test_check_output_path(self):
if os.name == "nt":
self.assertEqual(
check_output("python --version", prefix_path=self.env_path),
Expand All @@ -28,6 +35,18 @@ def test_check_output(self):
b"Python 3.12.1\n",
)

def test_check_output_name(self):
if os.name == "nt":
self.assertEqual(
check_output("python --version", prefix_name=self.env_name),
b"Python 3.12.1\r\n",
)
else:
self.assertEqual(
check_output("python --version", prefix_name=self.env_name),
b"Python 3.12.1\n",
)

def test_check_output_universal_newlines(self):
self.assertEqual(
check_output(
Expand All @@ -36,12 +55,17 @@ def test_check_output_universal_newlines(self):
"Python 3.12.1\n",
)

def test_run(self):
def test_run_path(self):
self.assertEqual(
run("python --version", prefix_path=self.env_path).returncode, 0
)

def test_popen(self):
def test_run_name(self):
self.assertEqual(
run("python --version", prefix_name=self.env_name).returncode, 0
)

def test_popen_path(self):
process = Popen("python --version", prefix_path=self.env_path, stdout=PIPE)
output = process.communicate()
if os.name == "nt":
Expand All @@ -50,6 +74,15 @@ def test_popen(self):
self.assertEqual(output[0], b"Python 3.12.1\n")
self.assertIsNone(output[1])

def test_popen_name(self):
process = Popen("python --version", prefix_name=self.env_name, stdout=PIPE)
output = process.communicate()
if os.name == "nt":
self.assertEqual(output[0], b"Python 3.12.1\r\n")
else:
self.assertEqual(output[0], b"Python 3.12.1\n")
self.assertIsNone(output[1])

def test_environment_variable(self):
self.assertTrue(
"TESTVAR=test"
Expand Down

0 comments on commit 2c62093

Please sign in to comment.