~brian-murray/apport/python-apt-hash

« back to all changes in this revision

Viewing changes to test/test_backend_apt_dpkg.py

  • Committer: Martin Pitt
  • Date: 2015-05-28 07:40:47 UTC
  • Revision ID: martin.pitt@canonical.com-20150528074047-hkybfkjljhxg381j
* Fix backend_apt_dpkg.test_install_packages_permanent_sandbox test to more carefully restore the environment and apt config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
740
740
                os.path.join(self.rootdir, 'usr/bin/stat')))
741
741
 
742
742
        # Prevent packages from downloading.
 
743
        orig_apt_proxy = apt_pkg.config.get('Acquire::http::Proxy')
743
744
        apt_pkg.config.set('Acquire::http::Proxy', 'http://nonexistent')
744
 
        orig_env = os.environ.copy()
 
745
        orig_http_proxy = os.environ.get('http_proxy')
745
746
        os.environ['http_proxy'] = 'http://nonexistent'
746
747
        try:
 
748
            orig_no_proxy = os.environ['no_proxy']
747
749
            del os.environ['no_proxy']
748
750
        except KeyError:
749
 
            pass
 
751
            orig_no_proxy = None
750
752
        self.assertRaises(SystemExit, impl.install_packages, self.rootdir,
751
753
                          self.configdir, 'Foonux 1.2', [('libc6', None)], False,
752
754
                          self.cachedir, permanent_rootdir=True)
753
 
        os.environ = orig_env
 
755
        if orig_http_proxy:
 
756
            os.environ['http_proxy'] = orig_http_proxy
 
757
        else:
 
758
            del os.environ['http_proxy']
 
759
        if orig_no_proxy:
 
760
            os.environ['no_proxy'] = orig_no_proxy
 
761
 
754
762
        # These packages exist, so attempting to install them should not fail.
755
763
        impl.install_packages(self.rootdir, self.configdir, 'Foonux 1.2',
756
764
                              [('coreutils', None), ('tzdata', None)], False, self.cachedir,
768
776
                          self.configdir, 'Foonux 1.2', [('aspell-doc', None)], False,
769
777
                          self.cachedir, permanent_rootdir=True)
770
778
 
771
 
        apt_pkg.config.set('Acquire::http::Proxy', '')
 
779
        apt_pkg.config.set('Acquire::http::Proxy', orig_apt_proxy)
772
780
 
773
781
    @unittest.skipUnless(_has_internet(), 'online test')
774
782
    def test_install_packages_permanent_sandbox_repack(self):