Add a test for %py_byte_compile macro

This commit is contained in:
Lumir Balhar 2020-08-31 13:44:41 +02:00
parent 2eb41fe707
commit 431e4380cc
2 changed files with 36 additions and 0 deletions

33
tests/pythontest.spec Normal file
View File

@ -0,0 +1,33 @@
%global basedir /opt/test/byte_compilation
Name: pythontest
Version: 0
Release: 0
Summary: ...
License: MIT
BuildRequires: python3-devel
%description
...
%install
mkdir -p %{buildroot}%{basedir}/directory/to/test/recursion
echo "print()" > %{buildroot}%{basedir}/file.py
echo "print()" > %{buildroot}%{basedir}/directory/to/test/recursion/file_in_dir.py
%py_byte_compile %{python3} %{buildroot}%{basedir}/file.py
%py_byte_compile %{python3} %{buildroot}%{basedir}/directory
%check
# Count .py and .pyc files
PY=$(find %{buildroot}%{basedir} -name "*.py" | wc -l)
PYC=$(find %{buildroot}%{basedir} -name "*.pyc" | wc -l)
# Every .py file should be byte-compiled to two .pyc files (optimization level 0 and 1)
# so we should have two times more .pyc files than .py files
test $(expr $PY \* 2) -eq $PYC
%files
%pycached %{basedir}/file.py
%pycached %{basedir}/directory/to/test/recursion/file_in_dir.py

View File

@ -16,6 +16,9 @@
- pytest:
dir: .
run: pytest -v
- manual_byte_compilation:
dir: .
run: rpmbuild -ba pythontest.spec
required_packages:
- rpm-build
- python-rpm-macros