Skip to content

Commit 766f9e3

Browse files
committed
test for nodejs or node in tests
1 parent 95c500d commit 766f9e3

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

tests/nodeenv_test.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@
1515
HERE = os.path.abspath(os.path.dirname(__file__))
1616

1717

18+
if subprocess.run(["which", "nodejs"],capture_output=True).returncode == 0:
19+
is_nodejs = True
20+
else:
21+
is_nodejs = False
22+
23+
24+
def call_nodejs(ev_path):
25+
assert os.path.exists(ev_path)
26+
activate = pipes.quote(os.path.join(ev_path, 'bin', 'activate'))
27+
if is_nodejs:
28+
subprocess.check_call([
29+
'sh', '-c', '. {} && nodejs --version'.format(activate),
30+
])
31+
else:
32+
subprocess.check_call([
33+
'sh', '-c', '. {} && node --version'.format(activate),
34+
])
35+
36+
1837
@pytest.mark.integration
1938
def test_smoke(tmpdir):
2039
nenv_path = tmpdir.join('nenv').strpath
@@ -23,11 +42,7 @@ def test_smoke(tmpdir):
2342
'coverage', 'run', '-p',
2443
'-m', 'nodeenv', '--prebuilt', nenv_path,
2544
])
26-
assert os.path.exists(nenv_path)
27-
activate = pipes.quote(os.path.join(nenv_path, 'bin', 'activate'))
28-
subprocess.check_call([
29-
'sh', '-c', '. {} && nodejs --version'.format(activate),
30-
])
45+
call_nodejs(nenv_path)
3146

3247

3348
@pytest.mark.integration
@@ -38,11 +53,7 @@ def test_smoke_n_system_special_chars(tmpdir):
3853
'coverage', 'run', '-p',
3954
'-m', 'nodeenv', '-n', 'system', nenv_path,
4055
))
41-
assert os.path.exists(nenv_path)
42-
activate = pipes.quote(os.path.join(nenv_path, 'bin', 'activate'))
43-
subprocess.check_call([
44-
'sh', '-c', '. {} && nodejs --version'.format(activate),
45-
])
56+
call_nodejs(nenv_path)
4657

4758

4859
@pytest.yield_fixture

0 commit comments

Comments
 (0)