~ps-jenkins/ubuntu-system-image/ubuntu-utopic-proposed

« back to all changes in this revision

Viewing changes to systemimage/tests/test_main.py

  • Committer: Barry Warsaw
  • Date: 2013-12-03 16:03:43 UTC
  • Revision ID: barry@python.org-20131203160343-1qucjodl9klxc00e
Tags: 2.0.2
 * Fix additional build environment test failures.  (LP: #1256947)

Show diffs side-by-side

added added

removed removed

Lines of Context:
499
499
        # latter can mess with pdb output should we need to trace through
500
500
        # the code.
501
501
        capture = StringIO()
502
 
        self._enter(patch('builtins.print', partial(print, file=capture)))
503
 
        self._enter(patch('systemimage.main.sys.argv',
504
 
                          ['argv0', '-C', ini_file, '--dry-run']))
505
 
        cli_main()
 
502
        with ExitStack() as resources:
 
503
            resources.enter_context(
 
504
                patch('builtins.print', partial(print, file=capture)))
 
505
            resources.enter_context(
 
506
                patch('systemimage.main.sys.argv',
 
507
                      ['argv0', '-C', ini_file, '--dry-run']))
 
508
            cli_main()
506
509
        self.assertEqual(capture.getvalue(),
507
510
                         'Upgrade path is 1200:1201:1304\n')
508
511
 
514
517
        # latter can mess with pdb output should we need to trace through
515
518
        # the code.
516
519
        capture = StringIO()
517
 
        self._enter(patch('builtins.print', partial(print, file=capture)))
518
 
        self._enter(patch('systemimage.main.sys.argv',
519
 
                          ['argv0', '-C', ini_file, '--dry-run']))
520
520
        # Set up the build number.
521
521
        config = Configuration()
522
522
        config.load(ini_file)
523
523
        touch_build(1701)
524
 
        cli_main()
 
524
        with ExitStack() as resources:
 
525
            resources.enter_context(
 
526
                patch('builtins.print', partial(print, file=capture)))
 
527
            resources.enter_context(
 
528
                patch('systemimage.main.sys.argv',
 
529
                      ['argv0', '-C', ini_file, '--dry-run']))
 
530
            cli_main()
525
531
        self.assertEqual(capture.getvalue(), 'Already up-to-date\n')
526
532
 
527
533
    @configuration
533
539
        # latter can mess with pdb output should we need to trace through
534
540
        # the code.
535
541
        capture = StringIO()
536
 
        self._enter(patch('builtins.print', partial(print, file=capture)))
537
 
        # Use --build to override the default build number.
538
 
        self._enter(patch('systemimage.main.sys.argv',
539
 
                          ['argv0', '-C', ini_file,
540
 
                           '--channel', 'daily-proposed',
541
 
                           '--dry-run']))
542
 
        cli_main()
 
542
        with ExitStack() as resources:
 
543
            resources.enter_context(
 
544
                patch('builtins.print', partial(print, file=capture)))
 
545
            # Use --build to override the default build number.
 
546
            resources.enter_context(
 
547
                patch('systemimage.main.sys.argv', [
 
548
                            'argv0', '-C', ini_file,
 
549
                            '--channel', 'daily-proposed',
 
550
                            '--dry-run']))
 
551
            cli_main()
543
552
        self.assertEqual(capture.getvalue(), 'Already up-to-date\n')
544
553
 
545
554
 
558
567
        head, tail = os.path.split(channel_ini)
559
568
        copy('channel_05.ini', head, tail)
560
569
        capture = StringIO()
561
 
        self._enter(patch('systemimage.device.check_output',
562
 
                          return_value='manta'))
563
 
        self._enter(patch('builtins.print', partial(print, file=capture)))
564
 
        self._enter(patch('systemimage.main.sys.argv',
565
 
                          ['argv0', '-C', ini_file, '--dry-run']))
566
 
        cli_main()
 
570
        with ExitStack() as resources:
 
571
            resources.enter_context(
 
572
                patch('systemimage.device.check_output',
 
573
                      return_value='manta'))
 
574
            resources.enter_context(
 
575
                patch('builtins.print', partial(print, file=capture)))
 
576
            resources.enter_context(
 
577
                patch('systemimage.main.sys.argv',
 
578
                      ['argv0', '-C', ini_file, '--dry-run']))
 
579
            cli_main()
567
580
        self.assertEqual(
568
581
            capture.getvalue(),
569
582
            'Upgrade path is 200:201:304 (saucy -> tubular)\n')
585
598
        # latter can mess with pdb output should we need to trace through
586
599
        # the code.
587
600
        capture = StringIO()
588
 
        self._enter(patch('builtins.print', partial(print, file=capture)))
589
 
        self._enter(patch('systemimage.main.sys.argv',
590
 
                          ['argv0', '-C', ini_file, '--dry-run',
591
 
                           '--filter', 'full']))
592
601
        # Set up the build number.
593
602
        config = Configuration()
594
603
        config.load(ini_file)
595
604
        touch_build(100)
596
 
        cli_main()
597
 
        self.assertMultiLineEqual(
598
 
            capture.getvalue(), 'Already up-to-date\n')
 
605
        with ExitStack() as resources:
 
606
            resources.enter_context(
 
607
                patch('builtins.print', partial(print, file=capture)))
 
608
            resources.enter_context(
 
609
                patch('systemimage.main.sys.argv', [
 
610
                            'argv0', '-C', ini_file, '--dry-run',
 
611
                            '--filter', 'full']))
 
612
            cli_main()
 
613
        self.assertMultiLineEqual(capture.getvalue(), 'Already up-to-date\n')
599
614
 
600
615
    @configuration
601
616
    def test_filter_delta(self, ini_file):
605
620
        # latter can mess with pdb output should we need to trace through
606
621
        # the code.
607
622
        capture = StringIO()
608
 
        self._enter(patch('builtins.print', partial(print, file=capture)))
609
 
        self._enter(patch('systemimage.main.sys.argv',
610
 
                          ['argv0', '-C', ini_file, '--dry-run',
611
 
                           '--filter', 'delta']))
612
623
        # Set up the build number.
613
624
        config = Configuration()
614
625
        config.load(ini_file)
615
626
        touch_build(100)
616
 
        cli_main()
617
 
        self.assertMultiLineEqual(
618
 
            capture.getvalue(), 'Upgrade path is 1600\n')
 
627
        with ExitStack() as resources:
 
628
            resources.enter_context(
 
629
                patch('builtins.print', partial(print, file=capture)))
 
630
            resources.enter_context(
 
631
                patch('systemimage.main.sys.argv', [
 
632
                            'argv0', '-C', ini_file, '--dry-run',
 
633
                            '--filter', 'delta']))
 
634
            cli_main()
 
635
        self.assertMultiLineEqual(capture.getvalue(), 'Upgrade path is 1600\n')
619
636
 
620
637
 
621
638
class TestCLIDuplicateDestinations(ServerTestBase):
632
649
        # problem.  The client must refuse to upgrade in this case, by raising
633
650
        # an exception.
634
651
        self._setup_server_keyrings()
635
 
        self._enter(patch('systemimage.main.sys.argv',
636
 
                          ['argv0', '-C', ini_file]))
637
 
        exit_code = cli_main()
 
652
        with ExitStack() as resources:
 
653
            resources.enter_context(
 
654
                patch('systemimage.main.sys.argv', ['argv0', '-C', ini_file]))
 
655
            exit_code = cli_main()
638
656
        self.assertEqual(exit_code, 1)
639
657
        # 2013-11-12 BAW: IWBNI we could assert something about the log
640
658
        # output, since that contains a display of the duplicate destination