Skip to content

Commit

Permalink
test for nodejs or node in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
a16bitsysop committed Aug 29, 2020
1 parent 95c500d commit 766f9e3
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions tests/nodeenv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@
HERE = os.path.abspath(os.path.dirname(__file__))


if subprocess.run(["which", "nodejs"],capture_output=True).returncode == 0:

This comment has been minimized.

Copy link
@tchaikov

tchaikov Oct 6, 2020

Contributor

@a16bitsysop @ekalinin this breaks the test. as capture_output parameter was introduced by python3.7.

This comment has been minimized.

Copy link
@a16bitsysop

a16bitsysop Oct 7, 2020

Author Contributor

@tchaikov I was using it to stop the return code making the test fail if nodejs does not exist

This comment has been minimized.

Copy link
@tchaikov

tchaikov via email Oct 7, 2020

Contributor

This comment has been minimized.

Copy link
@a16bitsysop

a16bitsysop Oct 7, 2020

Author Contributor

could this be moved into a shell script for the test suite that returns "node" or "nodejs" or fails if neither exists?

This comment has been minimized.

Copy link
@tchaikov

tchaikov via email Oct 7, 2020

Contributor

This comment has been minimized.

Copy link
@a16bitsysop

a16bitsysop Oct 7, 2020

Author Contributor

It is hard to check for existence of one or the other without the test failing

This comment has been minimized.

Copy link
@a16bitsysop

a16bitsysop Oct 8, 2020

Author Contributor

would this work on lower versions of python @tchaikov

def call_nodejs(ev_path):
    assert os.path.exists(ev_path)
    activate = pipes.quote(os.path.join(ev_path, 'bin', 'activate'))
    my_env = os.environ.copy()
    my_env["PATH"] = HERE + os.pathsep + my_env["PATH"]
    subprocess.check_call([
        'sh', '-c', '. {} && which_nodejs.sh --version'.format(activate),
    ], env=my_env) 

Script in test folder which_nodejs.sh

#!/bin/sh
which nodejs && nodejs "$1" || node "$1"

Passes under alpine linux

is_nodejs = True
else:
is_nodejs = False


def call_nodejs(ev_path):
assert os.path.exists(ev_path)
activate = pipes.quote(os.path.join(ev_path, 'bin', 'activate'))
if is_nodejs:
subprocess.check_call([
'sh', '-c', '. {} && nodejs --version'.format(activate),
])
else:
subprocess.check_call([
'sh', '-c', '. {} && node --version'.format(activate),
])


@pytest.mark.integration
def test_smoke(tmpdir):
nenv_path = tmpdir.join('nenv').strpath
Expand All @@ -23,11 +42,7 @@ def test_smoke(tmpdir):
'coverage', 'run', '-p',
'-m', 'nodeenv', '--prebuilt', nenv_path,
])
assert os.path.exists(nenv_path)
activate = pipes.quote(os.path.join(nenv_path, 'bin', 'activate'))
subprocess.check_call([
'sh', '-c', '. {} && nodejs --version'.format(activate),
])
call_nodejs(nenv_path)


@pytest.mark.integration
Expand All @@ -38,11 +53,7 @@ def test_smoke_n_system_special_chars(tmpdir):
'coverage', 'run', '-p',
'-m', 'nodeenv', '-n', 'system', nenv_path,
))
assert os.path.exists(nenv_path)
activate = pipes.quote(os.path.join(nenv_path, 'bin', 'activate'))
subprocess.check_call([
'sh', '-c', '. {} && nodejs --version'.format(activate),
])
call_nodejs(nenv_path)


@pytest.yield_fixture
Expand Down

0 comments on commit 766f9e3

Please sign in to comment.