Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing tests test_format_csv, test_format_json, test_format_json_license_manager, and test_from_all #120

Open
mcepl opened this issue Feb 26, 2022 · 6 comments

Comments

@mcepl
Copy link

mcepl commented Feb 26, 2022

While packaging this for openSUSE, these four tests fail:

[    6s] =================================== FAILURES ===================================
[    6s] _______________________ TestGetLicenses.test_format_csv ________________________
[    6s]
[    6s] self = <test_piplicenses.TestGetLicenses testMethod=test_format_csv>
[    6s]
[    6s]     def test_format_csv(self):
[    6s]         format_csv_args = ['--format=csv', '--with-authors']
[    6s]         args = self.parser.parse_args(format_csv_args)
[    6s] >       output_string = create_output_string(args)
[    6s]
[    6s] test_piplicenses.py:455:
[    6s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[    6s] piplicenses.py:533: in create_output_string
[    6s]     return table.get_string(fields=output_fields, sortby=sortby)
[    6s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[    6s]
[    6s] self = <[TypeError('_format_rows() takes 2 positional arguments but 3 were given') raised in repr()] CSVPrettyTable object at 0x7f018d2e9f40>
[    6s] kwargs = {'fields': ['Name', 'Version', 'License', 'Author'], 'sortby': 'Name'}
[    6s] options = {'align': {'Author': 'c', 'License': 'c', 'Name': 'c', 'Version': 'c'}, 'attributes': {}, 'border': True, 'bottom_junction_char': '+', ...}
[    6s] rows = [['apipkg', '2.1.0', 'MIT License', 'holger krekel'], ['appdirs', '1.4.4', 'MIT License', 'Trent Mick'], ['attrs', '21...Software License', 'Jason R. Coombs'], ['iniconfig', '0.0.0', 'MIT License', 'Ronny Pfannschmidt, Holger Krekel'], ...]
[    6s]
[    6s]     def get_string(self, **kwargs):
[    6s]
[    6s]         def esc_quotes(val):
[    6s]             """
[    6s]             Meta-escaping double quotes
[    6s]             https://tools.ietf.org/html/rfc4180
[    6s]             """
[    6s]             try:
[    6s]                 return val.replace('"', '""')
[    6s]             except UnicodeDecodeError:  # pragma: no cover
[    6s]                 return val.decode('utf-8').replace('"', '""')
[    6s]             except UnicodeEncodeError:  # pragma: no cover
[    6s]                 return val.encode('unicode_escape').replace('"', '""')
[    6s]
[    6s]         options = self._get_options(kwargs)
[    6s]         rows = self._get_rows(options)
[    6s] >       formatted_rows = self._format_rows(rows, options)
[    6s] E       TypeError: _format_rows() takes 2 positional arguments but 3 were given
[    6s]
[    6s] piplicenses.py:384: TypeError
[    6s] _______________________ TestGetLicenses.test_format_json _______________________
[    6s]
[    6s] self = <test_piplicenses.TestGetLicenses testMethod=test_format_json>
[    6s]
[    6s]     def test_format_json(self):
[    6s]         format_json_args = ['--format=json', '--with-authors']
[    6s]         args = self.parser.parse_args(format_json_args)
[    6s] >       output_string = create_output_string(args)
[    6s]
[    6s] test_piplicenses.py:437:
[    6s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[    6s] piplicenses.py:533: in create_output_string
[    6s]     return table.get_string(fields=output_fields, sortby=sortby)
[    6s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[    6s]
[    6s] self = <[TypeError('_format_rows() takes 2 positional arguments but 3 were given') raised in repr()] JsonPrettyTable object at 0x7f018d2aab20>
[    6s] kwargs = {'fields': ['Name', 'Version', 'License', 'Author'], 'sortby': 'Name'}
[    6s] json = <module 'json' from '/usr/lib64/python3.9/json/__init__.py'>
[    6s] options = {'align': {'Author': 'c', 'License': 'c', 'Name': 'c', 'Version': 'c'}, 'attributes': {}, 'border': True, 'bottom_junction_char': '+', ...}
[    6s] rows = [['apipkg', '2.1.0', 'MIT License', 'holger krekel'], ['appdirs', '1.4.4', 'MIT License', 'Trent Mick'], ['attrs', '21...Software License', 'Jason R. Coombs'], ['iniconfig', '0.0.0', 'MIT License', 'Ronny Pfannschmidt, Holger Krekel'], ...]
[    6s]
[    6s]     def get_string(self, **kwargs):
[    6s]         # import included here in order to limit dependencies
[    6s]         # if not interested in JSON output,
[    6s]         # then the dependency is not required
[    6s]         import json
[    6s]
[    6s]         options = self._get_options(kwargs)
[    6s]         rows = self._get_rows(options)
[    6s] >       formatted_rows = self._format_rows(rows, options)
[    6s] E       TypeError: _format_rows() takes 2 positional arguments but 3 were given
[    6s]
[    6s] piplicenses.py:324: TypeError
[    6s] _______________ TestGetLicenses.test_format_json_license_manager _______________
[    6s]
[    6s] self = <test_piplicenses.TestGetLicenses testMethod=test_format_json_license_manager>
[    6s]
[    6s]     def test_format_json_license_manager(self):
[    6s]         format_json_args = ['--format=json-license-finder']
[    6s]         args = self.parser.parse_args(format_json_args)
[    6s] >       output_string = create_output_string(args)
[    6s]
[    6s] test_piplicenses.py:445:
[    6s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[    6s] piplicenses.py:533: in create_output_string
[    6s]     return table.get_string(fields=output_fields, sortby=sortby)
[    6s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[    6s]
[    6s] self = <[TypeError('_format_rows() takes 2 positional arguments but 3 were given') raised in repr()] JsonLicenseFinderTable object at 0x7f018d05aac0>
[    6s] kwargs = {'fields': ['Name', 'Version', 'License'], 'sortby': 'Name'}
[    6s] json = <module 'json' from '/usr/lib64/python3.9/json/__init__.py'>
[    6s] options = {'align': {'License': 'c', 'Name': 'c', 'Version': 'c'}, 'attributes': {}, 'border': True, 'bottom_junction_char': '+', ...}
[    6s] rows = [['apipkg', '2.1.0', 'MIT License'], ['appdirs', '1.4.4', 'MIT License'], ['attrs', '21.4.0', 'MIT License'], ['docuti...ion License'], ['importlib-metadata', '4.10.1', 'Apache Software License'], ['iniconfig', '0.0.0', 'MIT License'], ...]
[    6s]
[    6s]     def get_string(self, **kwargs):
[    6s]         # import included here in order to limit dependencies
[    6s]         # if not interested in JSON output,
[    6s]         # then the dependency is not required
[    6s]         import json
[    6s]
[    6s]         options = self._get_options(kwargs)
[    6s]         rows = self._get_rows(options)
[    6s] >       formatted_rows = self._format_rows(rows, options)
[    6s] E       TypeError: _format_rows() takes 2 positional arguments but 3 were given
[    6s]
[    6s] piplicenses.py:356: TypeError
[    6s] ________________________ TestGetLicenses.test_from_all _________________________
[    6s]
[    6s] self = <test_piplicenses.TestGetLicenses testMethod=test_from_all>
[    6s]
[    6s]     def test_from_all(self):
[    6s]         from_args = ['--from=all']
[    6s]         args = self.parser.parse_args(from_args)
[    6s]         output_fields = get_output_fields(args)
[    6s]         table = create_licenses_table(args, output_fields)
[    6s]
[    6s]         self.assertIn('License-Metadata', output_fields)
[    6s]         self.assertIn('License-Classifier', output_fields)
[    6s]
[    6s]         index_license_meta = output_fields.index('License-Metadata')
[    6s]         license_meta = []
[    6s]         for row in table._rows:
[    6s]             license_meta.append(row[index_license_meta])
[    6s]
[    6s]         index_license_classifier = output_fields.index('License-Classifier')
[    6s]         license_classifier = []
[    6s]         for row in table._rows:
[    6s]             license_classifier.append(row[index_license_classifier])
[    6s]
[    6s]         for license in ('BSD', 'MIT', 'Apache 2.0'):
[    6s] >           self.assertIn(license, license_meta)
[    6s] E           AssertionError: 'BSD' not found in ['UNKNOWN', 'MIT', 'MIT', 'MIT', 'MIT License', 'MIT license', 'MIT', 'BSD-2-Clause or Apache-2.0', 'MIT-LICENSE', 'MIT', 'MIT License', 'UNKNOWN', 'public domain, Python, 2-Clause BSD, GPL 3 (see COPYING.txt)', 'MIT', 'MIT', 'MIT']
[    6s]
[    6s] test_piplicenses.py:158: AssertionError
[    6s] =========================== short test summary info ============================
[    6s] FAILED test_piplicenses.py::TestGetLicenses::test_format_csv - TypeError: _fo...
[    6s] FAILED test_piplicenses.py::TestGetLicenses::test_format_json - TypeError: _f...
[    6s] FAILED test_piplicenses.py::TestGetLicenses::test_format_json_license_manager
[    6s] FAILED test_piplicenses.py::TestGetLicenses::test_from_all - AssertionError: ...
[    6s] ================== 4 failed, 40 passed, 2 deselected in 0.59s ==================

Complete build log shows all packages used and all steps taken to get here.

@raimon49
Copy link
Owner

@mcepl This issue is probably the same as #119.

If possible, this can be solved by using the prettytable package 2.2.1 or lower in your environment.

@mcepl
Copy link
Author

mcepl commented Feb 27, 2022

That probably cannot happen. We cannot pull whole distribution back just because of one package which is not super-important to us.

@raimon49
Copy link
Owner

Yes, it would be difficult. Currently prettytable's internal compatibility is broken, and pip-licenses are not keeping up with the changes.

raimon49 added a commit that referenced this issue Oct 27, 2022
* Complete migration of table output library from PTable to prettytable
* Remove compatibility to work with either PTable or prettytable
* Fix failing tests with prettytable #120
@raimon49
Copy link
Owner

raimon49 commented Nov 6, 2022

This issue has been resolved in pip-licenses 4.x
https://pypi.org/project/pip-licenses/4.0.0/

@raimon49 raimon49 closed this as completed Nov 6, 2022
@mcepl
Copy link
Author

mcepl commented Nov 6, 2022

Not really:

[    9s] =================================== FAILURES ===================================
[    9s] ________________________ TestGetLicenses.test_from_all _________________________
[    9s] 
[    9s] self = <test_piplicenses.TestGetLicenses testMethod=test_from_all>
[    9s] 
[    9s]     def test_from_all(self):
[    9s]         from_args = ['--from=all']
[    9s]         args = self.parser.parse_args(from_args)
[    9s]         output_fields = get_output_fields(args)
[    9s]         table = create_licenses_table(args, output_fields)
[    9s]     
[    9s]         self.assertIn('License-Metadata', output_fields)
[    9s]         self.assertIn('License-Classifier', output_fields)
[    9s]     
[    9s]         index_license_meta = output_fields.index('License-Metadata')
[    9s]         license_meta = []
[    9s]         for row in table._rows:
[    9s]             license_meta.append(row[index_license_meta])
[    9s]     
[    9s]         index_license_classifier = output_fields.index('License-Classifier')
[    9s]         license_classifier = []
[    9s]         for row in table._rows:
[    9s]             license_classifier.append(row[index_license_classifier])
[    9s]     
[    9s]         for license in ('BSD', 'MIT', 'Apache 2.0'):
[    9s] >           self.assertIn(license, license_meta)
[    9s] E           AssertionError: 'BSD' not found in ['MIT License', 'UNKNOWN', 'UNKNOWN', 'UNKNOWN', 'UNKNOWN', 'BSD-2-Clause or Apache-2.0', 'MIT', 'MIT', 'MIT', 'MIT license', 'MIT', 'public domain, Python, 2-Clause BSD, GPL 3 (see COPYING.txt)']
[    9s] 
[    9s] test_piplicenses.py:190: AssertionError
[    9s] =============================== warnings summary ===============================
[    9s] test_piplicenses.py::TestGetLicenses::test_format_rst_default_filter
[    9s] test_piplicenses.py::TestGetLicenses::test_format_rst_without_filter
[    9s]   /home/abuild/rpmbuild/BUILD/pip-licenses-4.0.0/test_piplicenses.py:100: DeprecationWarning: The frontend.OptionParser class will be replaced by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
[    9s]     settings = docutils.frontend.\
[    9s] 
[    9s] test_piplicenses.py: 136 warnings
[    9s]   /usr/lib64/python3.8/optparse.py:1000: DeprecationWarning: The frontend.Option class will be removed in Docutils 0.21 or later.
[    9s]     option = self.option_class(*args, **kwargs)
[    9s] 
[    9s] -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
[    9s] =========================== short test summary info ============================
[    9s] FAILED test_piplicenses.py::TestGetLicenses::test_from_all - AssertionError: ...
[    9s] ================== 1 failed, 50 passed, 138 warnings in 1.59s ==================

Complete build log

@raimon49
Copy link
Owner

raimon49 commented Nov 7, 2022

Oh, I had not anticipated this test case failure.

Thanks for the detailed log. I will reopen this issue.

@raimon49 raimon49 reopened this Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants