aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2023-03-06 21:37:29 -0500
committerEli Schwartz <eschwartz@archlinux.org>2023-05-02 19:28:35 -0400
commit6a1427401c76db73081e478c4ff49fcc75420de6 (patch)
treebb7790eb92ef6da31ffcff79da0fadb8d4c796c2 /unittests
parent0e7fb07f915b7a2b04df209fbacd92aca19c87af (diff)
downloadmeson-6a1427401c76db73081e478c4ff49fcc75420de6.zip
meson-6a1427401c76db73081e478c4ff49fcc75420de6.tar.gz
meson-6a1427401c76db73081e478c4ff49fcc75420de6.tar.bz2
tests: add a python test for bytecode compilation
Some tweaks are added to the test case so that it supports python2 as well.
Diffstat (limited to 'unittests')
-rw-r--r--unittests/pythontests.py38
1 files changed, 33 insertions, 5 deletions
diff --git a/unittests/pythontests.py b/unittests/pythontests.py
index d49107f..6f3f075 100644
--- a/unittests/pythontests.py
+++ b/unittests/pythontests.py
@@ -12,18 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os
-import unittest
-import pathlib
-import subprocess
+import glob, os, pathlib, shutil, subprocess, unittest
from run_tests import (
Backend
)
from .allplatformstests import git_init
-
from .baseplatformtests import BasePlatformTests
+
from mesonbuild.mesonlib import TemporaryDirectoryWinProof
class PythonTests(BasePlatformTests):
@@ -60,3 +57,34 @@ python = pymod.find_installation('python3', required: true)
git_init(dirstr)
self.init(dirstr)
subprocess.check_call(self.meson_command + ['dist', '-C', self.builddir], stdout=subprocess.DEVNULL)
+
+ def _test_bytecompile(self, py2=False):
+ testdir = os.path.join(self.src_root, 'test cases', 'python', '2 extmodule')
+
+ self.init(testdir, extra_args=['-Dpython2=auto', '-Dpython.bytecompile=1'])
+ self.build()
+ self.install()
+
+ count = 0
+ for root, dirs, files in os.walk(self.installdir):
+ for file in files:
+ realfile = os.path.join(root, file)
+ if file.endswith('.py'):
+ cached = glob.glob(realfile+'?') + glob.glob(os.path.join(root, '__pycache__', os.path.splitext(file)[0] + '*.pyc'))
+ self.assertEqual(len(cached), 2)
+ count += 1
+ # there are 5 files x 2 installations
+ if py2:
+ self.assertEqual(count, 10)
+ else:
+ self.assertEqual(count, 5)
+
+ def test_bytecompile_multi(self):
+ if not shutil.which('python2'):
+ raise self.skipTest('python2 not installed')
+ self._test_bytecompile(True)
+
+ def test_bytecompile_single(self):
+ if shutil.which('python2'):
+ raise self.skipTest('python2 installed, already tested')
+ self._test_bytecompile()