<pre style='margin:0'>
Renee Otten (reneeotten) pushed a commit to branch master
in repository upt-macports.
</pre>
<p><a href="https://github.com/macports/upt-macports/commit/4186851e388d7fc819b74fa2f330a1d100596da6">https://github.com/macports/upt-macports/commit/4186851e388d7fc819b74fa2f330a1d100596da6</a></p>
<pre style="white-space: pre; background: #F8F8F8">The following commit(s) were added to refs/heads/master by this push:
<span style='display:block; white-space:pre;color:#404040;'> new 4186851 Add license logging
</span>4186851 is described below
<span style='display:block; white-space:pre;color:#808000;'>commit 4186851e388d7fc819b74fa2f330a1d100596da6
</span>Author: Korusuke <karan.sheth@somaiya.edu>
AuthorDate: Sat Jun 8 05:23:18 2019 +0530
<span style='display:block; white-space:pre;color:#404040;'> Add license logging
</span>---
upt_macports/tests/test_macports_package.py | 43 ++++++++++++++++++++++++++++-
upt_macports/upt_macports.py | 21 ++++++++++++--
2 files changed, 61 insertions(+), 3 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/upt_macports/tests/test_macports_package.py b/upt_macports/tests/test_macports_package.py
</span><span style='display:block; white-space:pre;color:#808080;'>index 2b78a14..57bdb6b 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/upt_macports/tests/test_macports_package.py
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/upt_macports/tests/test_macports_package.py
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1,6 +1,8 @@
</span> import unittest
import upt
<span style='display:block; white-space:pre;background:#ffe0e0;'>-from upt_macports.upt_macports import MacPortsPackage
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+from upt_macports.upt_macports import MacPortsPackage, logging
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+from unittest import mock
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+from io import StringIO
</span>
class TestMacPortsPackageLicenses(unittest.TestCase):
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -18,6 +20,11 @@ class TestMacPortsPackageLicenses(unittest.TestCase):
</span> expected = 'BSD'
self.assertEqual(self.package.licenses, expected)
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_unknown_license(self):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.upt_pkg.licenses = [upt.licenses.ZlibLicense()]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ expected = 'unknown # MacPorts license unknown for zlib'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.assertEqual(self.package.licenses, expected)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> def test_bad_license(self):
self.package.upt_pkg.licenses = [upt.licenses.UnknownLicense()]
expected = 'unknown'
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -31,6 +38,40 @@ class TestMacPortsPackageLicenses(unittest.TestCase):
</span> expected = 'BSD BSD'
self.assertEqual(self.package.licenses, expected)
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ # Logger tests
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch('sys.stdout', new_callable=StringIO)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_license_not_found(self, m_stdout):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ upt.log.create_logger(logging.DEBUG)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.upt_pkg.licenses = []
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.licenses
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.assertEqual(m_stdout.getvalue(), 'No license found\n')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch('sys.stdout', new_callable=StringIO)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_license_detection_failed(self, m_stdout):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ upt.log.create_logger(logging.DEBUG)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.upt_pkg.licenses = [upt.licenses.UnknownLicense()]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.licenses
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.assertEqual(m_stdout.getvalue(), 'upt failed to detect license\n')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch('sys.stdout', new_callable=StringIO)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_license_detection_success(self, m_stdout):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ upt.log.create_logger(logging.DEBUG)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.upt_pkg.licenses = [upt.licenses.BSDThreeClauseLicense()]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.licenses
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.assertEqual(m_stdout.getvalue(), 'Found license BSD\n')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch('sys.stderr', new_callable=StringIO)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch('sys.stdout', new_callable=StringIO)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_license_conversion_error(self, m_stdout, m_stderr):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ upt.log.create_logger(logging.DEBUG)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.upt_pkg.licenses = [upt.licenses.ZlibLicense()]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.licenses
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ err = 'MacPorts license unknown for zlib\n'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ info = 'Please report the error at https://github.com/macports/upt-macports\n' # noqa
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.assertEqual(m_stdout.getvalue(), info)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.assertEqual(m_stderr.getvalue(), err)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span>
class TestMacPortsPackageArchiveType(unittest.TestCase):
def setUp(self):
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/upt_macports/upt_macports.py b/upt_macports/upt_macports.py
</span><span style='display:block; white-space:pre;color:#808080;'>index 35be19d..b5bc500 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/upt_macports/upt_macports.py
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/upt_macports/upt_macports.py
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -32,8 +32,25 @@ class MacPortsPackage(object):
</span> with open(filepath) as f:
spdx2macports = json.loads(f.read())
<span style='display:block; white-space:pre;background:#ffe0e0;'>- return ' '.join([spdx2macports.get(license.spdx_identifier, 'unknown')
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- for license in self.upt_pkg.licenses]) or 'unknown'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if not self.upt_pkg.licenses:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.info('No license found')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 'unknown'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ licenses = []
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ for license in self.upt_pkg.licenses:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ try:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if license.spdx_identifier == 'unknown':
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ port_license = 'unknown'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.warning(f'upt failed to detect license')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ else:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ port_license = spdx2macports[license.spdx_identifier]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.info(f'Found license {port_license}')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ licenses.append(port_license)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ except KeyError:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ err = f'MacPorts license unknown for {license.spdx_identifier}'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ licenses.append('unknown # ' + err)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.error(err)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.info('Please report the error at https://github.com/macports/upt-macports') # noqa
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return ' '.join(licenses)
</span>
def _depends(self, phase):
return self.upt_pkg.requirements.get(phase, [])
</pre><pre style='margin:0'>
</pre>