unittests: fix incorrect calculation of bytecompile outputs

If py2 is not found *and* the compiler is MSVC, we didn't take into
account that py2 is not found. This also meant that we didn't take into
account the expected count when it *is* found, because the python module
has a better finder than just "is the binary on PATH".
pull/11853/head
Eli Schwartz 2 years ago
parent 7126ca6e27
commit df053848eb
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 9
      unittests/pythontests.py

@ -23,6 +23,7 @@ from .baseplatformtests import BasePlatformTests
from .helpers import * from .helpers import *
from mesonbuild.mesonlib import MachineChoice, TemporaryDirectoryWinProof from mesonbuild.mesonlib import MachineChoice, TemporaryDirectoryWinProof
from mesonbuild.modules.python import PythonModule
class PythonTests(BasePlatformTests): class PythonTests(BasePlatformTests):
''' '''
@ -75,25 +76,25 @@ python = pymod.find_installation('python3', required: true)
realfile = os.path.join(root, file) realfile = os.path.join(root, file)
if file.endswith('.py'): if file.endswith('.py'):
cached = glob.glob(realfile+'?') + glob.glob(os.path.join(root, '__pycache__', os.path.splitext(file)[0] + '*.pyc')) cached = glob.glob(realfile+'?') + glob.glob(os.path.join(root, '__pycache__', os.path.splitext(file)[0] + '*.pyc'))
if cc.get_id() == 'msvc': if py2 and cc.get_id() == 'msvc':
# MSVC python installs python2/python3 into the same directory # MSVC python installs python2/python3 into the same directory
self.assertLength(cached, 4) self.assertLength(cached, 4)
else: else:
self.assertLength(cached, 2) self.assertLength(cached, 2)
count += 1 count += 1
# there are 5 files x 2 installations # there are 5 files x 2 installations
if py2: if py2 and not cc.get_id() == 'msvc':
self.assertEqual(count, 10) self.assertEqual(count, 10)
else: else:
self.assertEqual(count, 5) self.assertEqual(count, 5)
@xfail_if_jobname('msys2-clangx64ninja') @xfail_if_jobname('msys2-clangx64ninja')
def test_bytecompile_multi(self): def test_bytecompile_multi(self):
if not shutil.which('python2'): if not shutil.which('python2') and not PythonModule._get_win_pythonpath('python2'):
raise self.skipTest('python2 not installed') raise self.skipTest('python2 not installed')
self._test_bytecompile(True) self._test_bytecompile(True)
def test_bytecompile_single(self): def test_bytecompile_single(self):
if shutil.which('python2'): if shutil.which('python2') or PythonModule._get_win_pythonpath('python2'):
raise self.skipTest('python2 installed, already tested') raise self.skipTest('python2 installed, already tested')
self._test_bytecompile() self._test_bytecompile()

Loading…
Cancel
Save