Exemplo n.º 1
0
def test_allow_only(monkeypatch):
    licenses = (
        "BSD License",
        "Apache Software License",
        "Mozilla Public License 2.0 (MPL 2.0)",
        "MIT License, Mozilla Public License 2.0 (MPL 2.0)",
        "Apache Software License, BSD License",
        "Python Software Foundation License, MIT License",
        "Public Domain, Python Software Foundation License, BSD License, "
        "GNU General Public License (GPL)",
        "GNU General Public License (GPL)",
        "GNU Library or Lesser General Public License (LGPL)",
    )
    allow_only_args = ['--allow-only={}'.format(";".join(licenses))]
    mocked_stdout = MockStdStream()
    mocked_stderr = MockStdStream()
    monkeypatch.setattr(sys.stdout, 'write', mocked_stdout.write)
    monkeypatch.setattr(sys.stderr, 'write', mocked_stderr.write)
    monkeypatch.setattr(sys, 'exit', lambda n: None)
    args = create_parser().parse_args(allow_only_args)
    create_licenses_table(args)

    assert '' == mocked_stdout.printed
    assert 'license MIT License not in allow-only licenses was found for ' \
           'package' in mocked_stderr.printed
Exemplo n.º 2
0
def test_fail_on(monkeypatch):
    licenses = ("MIT License", )
    allow_only_args = ['--fail-on={}'.format(";".join(licenses))]
    mocked_stdout = MockStdStream()
    mocked_stderr = MockStdStream()
    monkeypatch.setattr(sys.stdout, 'write', mocked_stdout.write)
    monkeypatch.setattr(sys.stderr, 'write', mocked_stderr.write)
    monkeypatch.setattr(sys, 'exit', lambda n: None)
    args = create_parser().parse_args(allow_only_args)
    create_licenses_table(args)

    assert '' == mocked_stdout.printed
    assert 'fail-on license MIT License was found for ' \
           'package' in mocked_stderr.printed
Exemplo n.º 3
0
    def test_with_empty_args(self):
        empty_args = []
        args = self.parser.parse_args(empty_args)
        table = create_licenses_table(args)

        self.assertIn('l', table.align.values())
        self.assertFalse(table.border)
        self.assertTrue(table.header)
        self.assertEqual('+', table.junction_char)
        self.assertEqual(RULE_FRAME, table.hrules)

        output_fields = get_output_fields(args)
        self.assertEqual(output_fields, list(DEFAULT_OUTPUT_FIELDS))
        self.assertNotIn('Author', output_fields)
        self.assertNotIn('URL', output_fields)

        pkg_name_columns = self._create_pkg_name_columns(table)
        for sys_pkg in SYSTEM_PACKAGES:
            self.assertNotIn(sys_pkg, pkg_name_columns)

        sortby = get_sortby(args)
        self.assertEqual('Name', sortby)

        output_string = create_output_string(args)
        self.assertNotIn('<table>', output_string)
Exemplo n.º 4
0
    def test_ignore_packages(self):
        ignore_pkg_name = 'PTable'
        ignore_packages_args = ['--ignore-package=' + ignore_pkg_name]
        args = self.parser.parse_args(ignore_packages_args)
        table = create_licenses_table(args)

        pkg_name_columns = self._create_pkg_name_columns(table)
        self.assertNotIn(ignore_pkg_name, pkg_name_columns)
Exemplo n.º 5
0
    def test_with_packages(self):
        pkg_name = 'py'
        only_packages_args = ['--packages=' + pkg_name]
        args = self.parser.parse_args(only_packages_args)
        table = create_licenses_table(args)

        pkg_name_columns = self._create_pkg_name_columns(table)
        self.assertListEqual([pkg_name], pkg_name_columns)
Exemplo n.º 6
0
    def test_with_system(self):
        with_system_args = ['--with-system']
        args = self.parser.parse_args(with_system_args)
        table = create_licenses_table(args)

        pkg_name_columns = self._create_pkg_name_columns(table)
        external_sys_pkgs = list(SYSTEM_PACKAGES)
        external_sys_pkgs.remove(__pkgname__)
        for sys_pkg in external_sys_pkgs:
            self.assertIn(sys_pkg, pkg_name_columns)
Exemplo n.º 7
0
    def test_format_confluence(self):
        format_confluence_args = ['--format=confluence']
        args = self.parser.parse_args(format_confluence_args)
        table = create_licenses_table(args)

        self.assertIn('l', table.align.values())
        self.assertTrue(table.border)
        self.assertTrue(table.header)
        self.assertEqual('|', table.junction_char)
        self.assertEqual(RULE_NONE, table.hrules)
Exemplo n.º 8
0
    def test_format_markdown(self):
        format_markdown_args = ['--format=markdown']
        args = self.parser.parse_args(format_markdown_args)
        table = create_licenses_table(args)

        self.assertIn('l', table.align.values())
        self.assertTrue(table.border)
        self.assertTrue(table.header)
        self.assertEqual('|', table.junction_char)
        self.assertEqual(RULE_HEADER, table.hrules)
Exemplo n.º 9
0
    def test_from_classifier(self):
        from_classifier_args = ['--from=classifier']
        args = self.parser.parse_args(from_classifier_args)
        table = create_licenses_table(args)

        output_fields = get_output_fields(args)
        self.assertIn('License', output_fields)

        license_columns = self._create_license_columns(table)
        license_notation_as_classifier = 'MIT License'
        self.assertIn(license_notation_as_classifier, license_columns)
Exemplo n.º 10
0
    def test_with_packages_with_system(self):
        if 'PTable' in SYSTEM_PACKAGES:
            pkg_name = 'PTable'
        else:
            pkg_name = 'prettytable'
        only_packages_args = ['--packages=' + pkg_name, "--with-system"]
        args = self.parser.parse_args(only_packages_args)
        table = create_licenses_table(args)

        pkg_name_columns = self._create_pkg_name_columns(table)
        self.assertListEqual([pkg_name], pkg_name_columns)
Exemplo n.º 11
0
    def test_from_meta(self):
        from_args = ['--from=meta']
        args = self.parser.parse_args(from_args)

        output_fields = get_output_fields(args)
        self.assertIn('License', output_fields)

        table = create_licenses_table(args, output_fields)
        license_columns = self._create_license_columns(table, output_fields)
        license_notation_as_meta = 'MIT'
        self.assertIn(license_notation_as_meta, license_columns)
Exemplo n.º 12
0
    def test_format_rst_default_filter(self):
        format_rst_args = ['--format=rst', '--filter-strings']
        args = self.parser.parse_args(format_rst_args)
        table = create_licenses_table(args)

        self.assertIn('l', table.align.values())
        self.assertTrue(table.border)
        self.assertTrue(table.header)
        self.assertEqual('+', table.junction_char)
        self.assertEqual(RULE_ALL, table.hrules)
        self.check_rst(str(table))
Exemplo n.º 13
0
    def test_from_mixed(self):
        from_classifier_args = ['--from=mixed']
        args = self.parser.parse_args(from_classifier_args)
        table = create_licenses_table(args)

        output_fields = get_output_fields(args)
        self.assertIn('License', output_fields)

        license_columns = self._create_license_columns(table)
        # Depending on the condition "MIT" or "BSD" etc.
        license_notation_as_classifier = 'MIT License'
        self.assertIn(license_notation_as_classifier, license_columns)
Exemplo n.º 14
0
    def test_format_rst_without_filter(self):
        format_rst_args = ['--format=rst']
        args = self.parser.parse_args(format_rst_args)
        table = create_licenses_table(args)

        self.assertIn('l', table.align.values())
        self.assertTrue(table.border)
        self.assertTrue(table.header)
        self.assertEqual('+', table.junction_char)
        self.assertEqual(RULE_ALL, table.hrules)
        with self.assertRaises(docutils.utils.SystemMessage):
            self.check_rst(str(table))
Exemplo n.º 15
0
    def test_from_all(self):
        from_args = ['--from=all']
        args = self.parser.parse_args(from_args)
        output_fields = get_output_fields(args)
        table = create_licenses_table(args, output_fields)

        self.assertIn('License-Metadata', output_fields)
        self.assertIn('License-Classifier', output_fields)

        index_license_meta = output_fields.index('License-Metadata')
        license_meta = []
        for row in table._rows:
            license_meta.append(row[index_license_meta])

        index_license_classifier = output_fields.index('License-Classifier')
        license_classifier = []
        for row in table._rows:
            license_classifier.append(row[index_license_classifier])

        for license in ('BSD', 'MIT', 'Apache 2.0'):
            self.assertIn(license, license_meta)
        for license in ('BSD License', 'MIT License',
                        'Apache Software License'):
            self.assertIn(license, license_classifier)