/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/launchpad/test_lp_api_lite.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

Lines of Context:
128
128
                          'ws.size': '1',
129
129
                          'distro_series': '/ubuntu/natty',
130
130
                          'pocket': 'Release',
131
 
                         }, latest_pub._query_params())
 
131
                          }, latest_pub._query_params())
132
132
 
133
133
    def test__query_params_no_series(self):
134
134
        latest_pub = self.make_latest_publication(series=None)
138
138
                          'status': 'Published',
139
139
                          'ws.size': '1',
140
140
                          'pocket': 'Release',
141
 
                         }, latest_pub._query_params())
 
141
                          }, latest_pub._query_params())
142
142
 
143
143
    def test__query_params_pocket(self):
144
144
        latest_pub = self.make_latest_publication(series='natty-proposed')
149
149
                          'ws.size': '1',
150
150
                          'distro_series': '/ubuntu/natty',
151
151
                          'pocket': 'Proposed',
152
 
                         }, latest_pub._query_params())
 
152
                          }, latest_pub._query_params())
153
153
 
154
154
    def test__query_URL(self):
155
155
        latest_pub = self.make_latest_publication()
296
296
 
297
297
    def assertBranchInfo(self, url, archive, series, project):
298
298
        self.assertEqual((archive, series, project),
299
 
            launchpad._get_package_branch_info(url))
 
299
                         launchpad._get_package_branch_info(url))
300
300
 
301
301
    def test_package_branch_regex(self):
302
302
        self.assertPackageBranchRe(
405
405
        """
406
406
        orig_log_len = len(self.get_log())
407
407
        lp_api_lite.report_freshness(self.branch, verbosity,
408
 
            StubLatestPublication(latest_version))
 
408
                                     StubLatestPublication(latest_version))
409
409
        new_content = self.get_log()[orig_log_len:]
410
410
        # Strip out lines that have LatestPublication.get_* because those are
411
411
        # timing related lines. While interesting to log for now, they aren't
413
413
        new_content = new_content.split('\n')
414
414
        for i in range(2):
415
415
            if (len(new_content) > 0
416
 
                and 'LatestPublication.get_' in new_content[0]):
 
416
                    and 'LatestPublication.get_' in new_content[0]):
417
417
                new_content = new_content[1:]
418
418
        new_content = '\n'.join(new_content)
419
419
        self.assertThat(new_content,
420
 
            DocTestMatches(content,
421
 
                doctest.ELLIPSIS | doctest.REPORT_UDIFF))
 
420
                        DocTestMatches(content,
 
421
                                       doctest.ELLIPSIS | doctest.REPORT_UDIFF))
422
422
 
423
423
    def test_verbosity_off_skips_check(self):
424
424
        # We force _get_package_branch_info so that we know it would otherwise
425
425
        # try to connect to launcphad
426
426
        self.overrideAttr(launchpad, '_get_package_branch_info',
427
 
            lambda x: ('ubuntu', 'natty', 'bzr'))
 
427
                          lambda x: ('ubuntu', 'natty', 'bzr'))
428
428
        self.overrideAttr(lp_api_lite, 'LatestPublication',
429
 
            lambda *args: self.fail('Tried to query launchpad'))
 
429
                          lambda *args: self.fail('Tried to query launchpad'))
430
430
        c = self.branch.get_config_stack()
431
431
        c.set('launchpad.packaging_verbosity', 'off')
432
432
        orig_log_len = len(self.get_log())
433
433
        launchpad._check_is_up_to_date(self.branch)
434
434
        new_content = self.get_log()[orig_log_len:]
435
435
        self.assertContainsRe(new_content,
436
 
            'not checking memory.*/tip/ because verbosity is turned off')
 
436
                              'not checking memory.*/tip/ because verbosity is turned off')
437
437
 
438
438
    def test_verbosity_off(self):
439
439
        latest_pub = StubLatestPublication('1.0-1ubuntu2')
443
443
    def test_verbosity_all_out_of_date_smoke(self):
444
444
        self.branch.tags.set_tag('1.0-1ubuntu1', b'A')
445
445
        self.assertFreshnessReports('all', '1.0-1ubuntu2',
446
 
             '    INFO  Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
447
 
             'Packaging branch version: 1.0-1ubuntu1\n'
448
 
             'Packaging branch status: OUT-OF-DATE\n')
 
446
                                    '    INFO  Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
 
447
                                    'Packaging branch version: 1.0-1ubuntu1\n'
 
448
                                    'Packaging branch status: OUT-OF-DATE\n')
449
449
 
450
450
 
451
451
class Test_GetNewestVersions(tests.TestCaseWithMemoryTransport):
463
463
            self.branch.tags.set_tag(latest_branch_version, b'A')
464
464
        latest_pub = StubLatestPublication(pub_version)
465
465
        self.assertEqual((pub_version, latest_branch_version),
466
 
            lp_api_lite._get_newest_versions(self.branch, latest_pub))
 
466
                         lp_api_lite._get_newest_versions(self.branch, latest_pub))
467
467
 
468
468
    def test_no_tags(self):
469
469
        self.assertLatestVersions(None, '1.0-1ubuntu2')
481
481
class Test_ReportFreshness(tests.TestCase):
482
482
 
483
483
    def assertReportedFreshness(self, verbosity, latest_ver, branch_latest_ver,
484
 
                               content, place='Ubuntu Natty'):
 
484
                                content, place='Ubuntu Natty'):
485
485
        """Assert that lp_api_lite.report_freshness reports the given content.
486
486
        """
487
487
        reported = []
 
488
 
488
489
        def report_func(value):
489
490
            reported.append(value)
490
491
 
492
493
                                      verbosity, report_func)
493
494
        new_content = '\n'.join(reported)
494
495
        self.assertThat(new_content,
495
 
            DocTestMatches(content,
496
 
                doctest.ELLIPSIS | doctest.REPORT_UDIFF))
 
496
                        DocTestMatches(content,
 
497
                                       doctest.ELLIPSIS | doctest.REPORT_UDIFF))
497
498
 
498
499
    def test_verbosity_minimal_no_tags(self):
499
500
        self.assertReportedFreshness('minimal', '1.0-1ubuntu2', None,
500
 
            'Branch is OUT-OF-DATE, Ubuntu Natty has 1.0-1ubuntu2\n')
 
501
                                     'Branch is OUT-OF-DATE, Ubuntu Natty has 1.0-1ubuntu2\n')
501
502
 
502
503
    def test_verbosity_minimal_out_of_date(self):
503
504
        self.assertReportedFreshness('minimal', '1.0-1ubuntu2', '1.0-1ubuntu1',
504
 
            '1.0-1ubuntu1 is OUT-OF-DATE,'
505
 
            ' Ubuntu Natty has 1.0-1ubuntu2\n')
 
505
                                     '1.0-1ubuntu1 is OUT-OF-DATE,'
 
506
                                     ' Ubuntu Natty has 1.0-1ubuntu2\n')
506
507
 
507
508
    def test_verbosity_minimal_up_to_date(self):
508
509
        self.assertReportedFreshness('minimal', '1.0-1ubuntu2', '1.0-1ubuntu2',
509
 
             '')
 
510
                                     '')
510
511
 
511
512
    def test_verbosity_minimal_missing(self):
512
513
        self.assertReportedFreshness('minimal', None, None,
513
 
             '')
 
514
                                     '')
514
515
 
515
516
    def test_verbosity_short_out_of_date(self):
516
517
        self.assertReportedFreshness('short', '1.0-1ubuntu2', '1.0-1ubuntu1',
517
 
            '1.0-1ubuntu1 is OUT-OF-DATE,'
518
 
            ' Ubuntu Natty has 1.0-1ubuntu2\n')
 
518
                                     '1.0-1ubuntu1 is OUT-OF-DATE,'
 
519
                                     ' Ubuntu Natty has 1.0-1ubuntu2\n')
519
520
 
520
521
    def test_verbosity_short_up_to_date(self):
521
522
        self.assertReportedFreshness('short', '1.0-1ubuntu2', '1.0-1ubuntu2',
522
 
             '1.0-1ubuntu2 is CURRENT in Ubuntu Natty')
 
523
                                     '1.0-1ubuntu2 is CURRENT in Ubuntu Natty')
523
524
 
524
525
    def test_verbosity_short_missing(self):
525
526
        self.assertReportedFreshness('short', None, None,
526
 
             'Ubuntu Natty is MISSING a version')
 
527
                                     'Ubuntu Natty is MISSING a version')
527
528
 
528
529
    def test_verbosity_all_no_tags(self):
529
530
        self.assertReportedFreshness('all', '1.0-1ubuntu2', None,
530
 
             'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
531
 
             'Packaging branch version: None\n'
532
 
             'Packaging branch status: OUT-OF-DATE\n')
 
531
                                     'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
 
532
                                     'Packaging branch version: None\n'
 
533
                                     'Packaging branch status: OUT-OF-DATE\n')
533
534
 
534
535
    def test_verbosity_all_out_of_date(self):
535
536
        self.assertReportedFreshness('all', '1.0-1ubuntu2', '1.0-1ubuntu1',
536
 
             'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
537
 
             'Packaging branch version: 1.0-1ubuntu1\n'
538
 
             'Packaging branch status: OUT-OF-DATE\n')
 
537
                                     'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
 
538
                                     'Packaging branch version: 1.0-1ubuntu1\n'
 
539
                                     'Packaging branch status: OUT-OF-DATE\n')
539
540
 
540
541
    def test_verbosity_all_up_to_date(self):
541
542
        self.assertReportedFreshness('all', '1.0-1ubuntu2', '1.0-1ubuntu2',
542
 
             'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
543
 
             'Packaging branch status: CURRENT\n')
 
543
                                     'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
 
544
                                     'Packaging branch status: CURRENT\n')
544
545
 
545
546
    def test_verbosity_all_missing(self):
546
547
        self.assertReportedFreshness('all', None, None,
547
 
             'Most recent Ubuntu Natty version: MISSING\n')
 
548
                                     'Most recent Ubuntu Natty version: MISSING\n')
548
549
 
549
550
    def test_verbosity_None_is_all(self):
550
551
        self.assertReportedFreshness(None, '1.0-1ubuntu2', '1.0-1ubuntu2',
551
 
             'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
552
 
             'Packaging branch status: CURRENT\n')
 
552
                                     'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
 
553
                                     'Packaging branch status: CURRENT\n')