praiskup / argparse-manpage

Automatically build man-pages for your Python project
Apache License 2.0
40 stars 22 forks source link

[self-tests] normalized version and setuptools 60+ #50

Closed stanislavlevin closed 2 years ago

stanislavlevin commented 2 years ago

As of 60 setuptools once again switched stdlib's distutils to its own copy:

https://docs.python.org/3/whatsnew/3.10.html#distutils-deprecated https://setuptools.pypa.io/en/latest/history.html#v60-0-0

With this change 2 tests fails as:

=================================== FAILURES ===================================
_______________________ TestAllExapmles.test_old_example _______________________

self = <test_examples.TestAllExapmles object at 0x7fe5fa352370>

    def test_old_example(self):
        with pushd('examples/old_format'):
            try:
                os.remove('example.1')
            except OSError:
                pass
            run_setup_py(['build_manpage'])
>           file_cmp('example.1', 'expected-output.1')

tests/test_examples.py:106: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

file1 = 'example.1', file2 = 'expected-output.1', filter_string = None

    def file_cmp(file1, file2, filter_string=None):
        with open(file1, 'r') as f1:
            with open(file2, 'r') as f2:
                a1 = f1.readlines()
                a2 = f2.readlines()
                if len(a1) != len(a2):
                    # get the pretty diff
                    assert a1 == a2

                first = True
                for left, right in zip(a1, a2):
                    if first:
                        left  = re.sub('[0-9]{4}\\\\-[0-9]{2}\\\\-[0-9]{2}', '!!DATE!!', left)
                        right = re.sub('[0-9]{4}\\\\-[0-9]{2}\\\\-[0-9]{2}', '!!DATE!!', right)
                        first = False

                    if filter_string is not None:
                        left = filter_string(left)
                        right = filter_string(right)

>                   assert left == right
E                   assert '.TH example ...0.1.0.dev0"\n' == '.TH example ....0.1.0-dev"\n'
E                     - .TH example 1 !!DATE!! "example v.0.1.0-dev"
E                     ?                                        ^
E                     + .TH example 1 !!DATE!! "example v.0.1.0.dev0"
E                     ?

tests/test_examples.py:95: AssertionError
----------------------------- Captured stdout call -----------------------------
running build_manpage
----------------------------- Captured stderr call -----------------------------
/usr/src/RPM/BUILD/python3-module-argparse-manpage-2.1/.tox/py3/lib/python3/site-packages/setuptools/dist.py:494: UserWarning: Normalizing '0.1.0-dev' to '0.1.0.dev0'
  warnings.warn(tmpl.format(**locals()))
__________________ TestAllExapmles.test_old_example_file_name __________________

self = <test_examples.TestAllExapmles object at 0x7fe5fa3525e0>

    def test_old_example_file_name(self):
        with pushd('examples/old_format_file_name'):
            try:
                os.remove('example.1')
            except OSError:
                pass
            run_setup_py(['build_manpage'])
>           file_cmp('example.1', 'expected-output.1')

tests/test_examples.py:115: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

file1 = 'example.1', file2 = 'expected-output.1', filter_string = None

    def file_cmp(file1, file2, filter_string=None):
        with open(file1, 'r') as f1:
            with open(file2, 'r') as f2:
                a1 = f1.readlines()
                a2 = f2.readlines()
                if len(a1) != len(a2):
                    # get the pretty diff
                    assert a1 == a2

                first = True
                for left, right in zip(a1, a2):
                    if first:
                        left  = re.sub('[0-9]{4}\\\\-[0-9]{2}\\\\-[0-9]{2}', '!!DATE!!', left)
                        right = re.sub('[0-9]{4}\\\\-[0-9]{2}\\\\-[0-9]{2}', '!!DATE!!', right)
                        first = False

                    if filter_string is not None:
                        left = filter_string(left)
                        right = filter_string(right)

>                   assert left == right
E                   assert '.TH example ...0.1.0.dev0"\n' == '.TH example ....0.1.0-dev"\n'
E                     - .TH example 1 !!DATE!! "example v.0.1.0-dev"
E                     ?                                        ^
E                     + .TH example 1 !!DATE!! "example v.0.1.0.dev0"
E                     ?                                        ^   +

tests/test_examples.py:95: AssertionError
----------------------------- Captured stdout call -----------------------------
running build_manpage
----------------------------- Captured stderr call -----------------------------
/usr/src/RPM/BUILD/python3-module-argparse-manpage-2.1/.tox/py3/lib/python3/site-packages/setuptools/dist.py:494: UserWarning: Normalizing '0.1.0-dev' to '0.1.0.dev0'
  warnings.warn(tmpl.format(**locals()))
=============================== warnings summary ===============================
build_manpages/build_manpage.py:5
  /usr/src/RPM/BUILD/python3-module-argparse-manpage-2.1/tests/../build_manpages/build_manpage.py:5: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp

-- Docs: https://docs.pytest.org/en/stable/warnings.html
=========================== short test summary info ============================
SKIPPED [4] tests/test_examples.py:69: pip install not supported with python 3.9.9
FAILED tests/test_examples.py::TestAllExapmles::test_old_example - assert '.T...
FAILED tests/test_examples.py::TestAllExapmles::test_old_example_file_name - ...
============== 2 failed, 8 passed, 4 skipped, 1 warning in 2.92s ===============

Version is defined as distribution.get_version(): https://github.com/praiskup/argparse-manpage/blob/abe59c085961865a2ceb91f376ac9da9d83ffccd/build_manpages/build_manpage.py#L97-L101

stdlib's distutils passes version from metainfo as is, while setuptools' one normalizes it: https://github.com/pypa/setuptools/blob/5e94859bf197500e6953c90668eb4cee159d25cf/setuptools/dist.py#L470-L472

Probably, normalized versions should be provided for tests to be compatible with either setuptools.

hroncok commented 2 years ago

BTW We are working on updating setuptools to 60+ in Rawhide.

praiskup commented 2 years ago

Ok, can you confirm that #52 helps?

hroncok commented 2 years ago

If you send a Fedora PR with that patch, it will be autotested in the setuptools 60 copr.

stanislavlevin commented 2 years ago

@praiskup, for my distro I fixed examples and expected output, but the way is up to you. I left a comment in mentioned PR, thank you.

praiskup commented 2 years ago

@hroncok fixed in Fedora Rawhide (I haven't done the build as it doesn't make sense at this point in time I think)

befeleme commented 2 years ago

Hi, @praiskup, I've done a build for Fedora Rawhide in the test Copr which failed as no tests were found:

+ cd argparse-manpage-2.2
+ CFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection'
+ LDFLAGS='-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/argparse-manpage-2.2/.package_note-argparse-manpage-2.2-1.fc37.x86_64.ld'
+ PATH=/builddir/build/BUILDROOT/argparse-manpage-2.2-1.fc37.x86_64/usr/bin:/builddir/.local/bin:/builddir/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin
+ PYTHONPATH=/builddir/build/BUILDROOT/argparse-manpage-2.2-1.fc37.x86_64/usr/lib64/python3.10/site-packages:/builddir/build/BUILDROOT/argparse-manpage-2.2-1.fc37.x86_64/usr/lib/python3.10/site-packages
+ PYTHONDONTWRITEBYTECODE=1
+ PYTEST_ADDOPTS=' --ignore=/builddir/build/BUILD/argparse-manpage-2.2/.pyproject-builddir'
+ /usr/bin/pytest
============================= test session starts ==============================
platform linux -- Python 3.10.2, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /builddir/build/BUILD/argparse-manpage-2.2
collected 0 items

============================ no tests ran in 0.02s =============================
error: Bad exit status from /var/tmp/rpm-tmp.S1GW5O (%check)
    Bad exit status from /var/tmp/rpm-tmp.S1GW5O (%check)
praiskup commented 2 years ago

Thanks for the ping, the release tarball was incomplete, fixed by: 1c9418e80833bc616e6a43edacc0ba7cc70aab1b New tarball was uploaded to fedora lookaside cache.

befeleme commented 2 years ago

@praiskup, thank you, this time the build is green as cucumber :)