def test_listing_from_readable(self):
        env = InstalledPackageVersions.from_freeze_file(StringIO('a===1.0.0'))
        packages = [p for p, _ in env]
        self.assertEqual(['a'], packages)

        env = InstalledPackageVersions.from_freeze_file(
            StringIO('a===1.0.0\nb===2.2.2\n'))
        packages = [p for p, _ in env]
        self.assertEqual(['a', 'b'], packages)
 def test_ignore_some_lines(self):
     env = InstalledPackageVersions.from_freeze_file(
         StringIO('\n\n# foo bar \na===1.0.0\n# foo bar\n   #\n  \nxxx'))
     self.assertEqual({'xxx'}, env.packages_with_error)
     self.assertEqual('Could not parse package/version "xxx"\n',
                      env.get_errors())
     packages = [p for p, _ in env]
     self.assertEqual(['a'], packages)
 def test_report_ignore_all(self):
     env = InstalledPackageVersions.from_freeze_file(StringIO('non-lts-example==1.0.7'))
     version_db = PackageVersionClassifications(yaml_db=TEST_DB_NAME)
     available = FakePackageVersionInfo.from_list('non-lts-example', NON_LTS_EXAMPLE_VERSIONS)
     analyzer = Analyzer(env, available, version_db)
     report = analyzer.analyze(
         ignored_packages=['non-lts-example']
     )
     self.assertEqual('', report.render())
    def test_unknown_package(self):
        env = InstalledPackageVersions.from_freeze_file(StringIO('FOO==1.0.8'))
        version_db = PackageVersionClassifications(yaml_db=TEST_DB_NAME)
        available = FakePackageVersionInfo()
        analyzer = Analyzer(env, available, version_db)
        report = analyzer.analyze()
        expected_report = """Packages with PyPI or version problem: FOO
"""
        self.assertEqual(expected_report, report.render())
 def test_listing_from_file(self):
     freeze_file_name = os.path.join(self.temp_dir, 'frozen.txt')
     with open(freeze_file_name, 'w') as f:
         f.writelines([
             'a===1.0.0\n',
             'b===2.2.2\n',
         ])
     env = InstalledPackageVersions.from_freeze_file(freeze_file_name)
     packages = [p for p, _ in env]
     self.assertEqual(['a', 'b'], packages)
    def test_package_not_in_release_database(self):
        env = InstalledPackageVersions.from_freeze_file(StringIO('FOO==1.0.8'))
        version_db = PackageVersionClassifications(yaml_db=TEST_DB_NAME)
        available = FakePackageVersionInfo.from_list('FOO', ['1.0.8', '1.0.9'])
        analyzer = Analyzer(env, available, version_db)
        report = analyzer.analyze()
        expected_report = """FOO: 1.0.8
Newer releases:
  1.0.9: No information about package
"""
        self.assertEqual(expected_report, report.render())
Пример #7
0
def main(args):
    """Parse arguments and call library to analyze"""
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--cache-file',
        help='name of JSON document where data from PyPI is cached')
    parser.add_argument('--cache-time',
                        help='seconds that data from PyPI is cached',
                        type=int)
    parser.add_argument('--db', help='path to package release database')
    parser.add_argument('--ignore',
                        help='comma-delimited list of packages to ignore',
                        default='')
    parser.add_argument('--types', help='all|feature|compat|bug|security')
    parser.add_argument('--verbose',
                        help='show more details',
                        action='store_true')
    parser.add_argument('freeze_output', nargs='?')
    args = parser.parse_args(args)

    try:
        types = ReportedUpdateTypes(types=args.types)
    except ValueError:
        print('Bad value for --types', file=sys.stderr)
        sys.exit(1)

    if args.freeze_output:
        env_packages = InstalledPackageVersions.from_freeze_file(
            args.freeze_output)
    else:
        env_packages = InstalledPackageVersions.from_active_env()
    if env_packages.packages_with_error:
        print('Packages in virtualenv with error:', file=sys.stderr)
        for package in env_packages.packages_with_error:
            print('  %s' % package, file=sys.stderr)

    version_db = PackageVersionClassifications(yaml_db=args.db)

    split_re = re.compile(r'( +| *, *)')
    with AvailablePackageVersions(
            max_cache_time_seconds=args.cache_time,
            cache_file_path=args.cache_file) as version_info:
        analyzer = Analyzer(env_packages, version_info, version_db)
        report = analyzer.analyze(
            ignored_packages=split_re.split(args.ignore),
            types=types,
        )

    print(report.render(verbose=args.verbose), end='')
    def test_report_no_newer(self):
        env = InstalledPackageVersions.from_freeze_file(StringIO('non-lts-example==1.0.8'))
        version_db = PackageVersionClassifications(yaml_db=TEST_DB_NAME)
        available = FakePackageVersionInfo.from_list('non-lts-example', NON_LTS_EXAMPLE_VERSIONS)
        analyzer = Analyzer(env, available, version_db)
        report = analyzer.analyze()
        # non-verbose:
        expected_report = ''
        self.assertEqual(expected_report, report.render())
        # verbose: (should show older releases)
        expected_report = """non-lts-example: 1.0.8
Older: 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.0.7a1, 1.0.7b2, 1.0.7, 1.0.8rc3

Up to date: non-lts-example
"""
        self.assertEqual(expected_report, report.render(verbose=True))
    def test_report_older(self):
        env = InstalledPackageVersions.from_freeze_file(StringIO('non-lts-example==1.0.7'))
        version_db = PackageVersionClassifications(yaml_db=TEST_DB_NAME)
        available = FakePackageVersionInfo.from_list('non-lts-example', NON_LTS_EXAMPLE_VERSIONS)
        analyzer = Analyzer(env, available, version_db)
        report = analyzer.analyze()
        # non-verbose:
        expected_report = """non-lts-example: 1.0.7
Newer releases:
  1.0.8: SECURITY
  Changelog: https://non-lts-example.com/CHANGES.md
"""
        self.assertEqual(expected_report, report.render())
        # verbose: (should show older releases)
        expected_report = """non-lts-example: 1.0.7
Newer releases:
  1.0.8: SECURITY
  Changelog: https://non-lts-example.com/CHANGES.md
Older: 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.0.7a1, 1.0.7b2
"""
        self.assertEqual(expected_report, report.render(verbose=True))
    def test_lts(self):
        env = InstalledPackageVersions.from_freeze_file(StringIO('d===1.11.5'))
        version_db = PackageVersionClassifications(yaml_db=TEST_DB_NAME)
        available = FakePackageVersionInfo({
            'd': {
                'releases': {
                    '1.11.9': True,
                    '1.11.10': True,
                    '2.0': True,
                    '2.0.1': True,
                    '2.0.2': True
                }
            }
        })
        analyzer = Analyzer(env, available, version_db)
        report = analyzer.analyze()
        expected_report = """d: 1.11.5
Newer releases:
  1.11.9: Non-security bug fixes
  1.11.10: SECURITY
  Changelog: https://docs.d.com/CHANGELOG.md
"""
        self.assertEqual(expected_report, report.render())
 def setUp(self):
     self.env = InstalledPackageVersions.from_freeze_file(
         StringIO('a==1.0.0\nb==2.0.0\nc==3.0.0\n'))