From 97dc74c7278eb54d09657a0cdb7321a613329a8c Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Tue, 31 Mar 2020 16:05:52 -0700 Subject: [PATCH] python: fix tests, remove intentional debug failures --- lib/spack/spack/package.py | 2 +- .../repos/builtin/packages/python/package.py | 26 +++++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 6b6bf9e520b..f08e4f45972 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -1692,7 +1692,7 @@ def run_test(self, exe, options=[], expected=[], status=None): for check in expected: cmd = ' '.join([exe] + options) msg = "Expected '%s' in output of `%s`" % (check, cmd) -# msg += '\n%s' % output + msg += '\n\nOutput: %s' % output assert check in output, msg except ProcessError as err: diff --git a/var/spack/repos/builtin/packages/python/package.py b/var/spack/repos/builtin/packages/python/package.py index aace7c93806..fe9cd520111 100644 --- a/var/spack/repos/builtin/packages/python/package.py +++ b/var/spack/repos/builtin/packages/python/package.py @@ -1111,21 +1111,15 @@ def remove_files_from_view(self, view, merge_map): os.remove(dst) def test(self): - self.run_test('true', expected=['not in output']) + # guaranteed executable name + # do not use self.command because we are also testing the run env + exe = 'python3' if self.spec.satisfies('@3:') else 'python' - # contains python executable - python = which('python') - assert os.path.dirname(python.path) == os.path.dirname( - self.command.path) + # test hello world + self.run_test(exe, options=['-c', 'print("hello world!")'], + expected=['hello world!']) - # run hello world - output = self.command('-c', 'print("hello world!")', - output=str.split, error=str.split) - assert output == "hello world!" - - self.command('-c', 'assert False', output=str.split, error=str.split) - -# error = self.command('-c', 'print("Error: failed.")', -# output=str.split, error=str.split) - -# assert error.strip() == 'Error: failed.' + # check that the executable comes from the spec prefix + # also checks imports work + self.run_test(exe, options=['-c', 'import sys; print(sys.executable)'], + expected=[self.spec.prefix])