~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

Merge fetch-spec-everything-not-in-other.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
1899
1899
        self.assertIsInstance(concurrency, int)
1900
1900
 
1901
1901
    def test_local_concurrency_environment_variable(self):
1902
 
        os.environ['BZR_CONCURRENCY'] = '2'
 
1902
        self.overrideEnv('BZR_CONCURRENCY', '2')
1903
1903
        self.assertEqual(2, osutils.local_concurrency(use_cache=False))
1904
 
        os.environ['BZR_CONCURRENCY'] = '3'
 
1904
        self.overrideEnv('BZR_CONCURRENCY', '3')
1905
1905
        self.assertEqual(3, osutils.local_concurrency(use_cache=False))
1906
 
        os.environ['BZR_CONCURRENCY'] = 'foo'
 
1906
        self.overrideEnv('BZR_CONCURRENCY', 'foo')
1907
1907
        self.assertEqual(1, osutils.local_concurrency(use_cache=False))
1908
1908
 
1909
1909
    def test_option_concurrency(self):
1910
 
        os.environ['BZR_CONCURRENCY'] = '1'
 
1910
        self.overrideEnv('BZR_CONCURRENCY', '1')
1911
1911
        self.run_bzr('rocks --concurrency 42')
1912
 
        # Command line overrides envrionment variable
 
1912
        # Command line overrides environment variable
1913
1913
        self.assertEquals('42', os.environ['BZR_CONCURRENCY'])
1914
1914
        self.assertEquals(42, osutils.local_concurrency(use_cache=False))
1915
1915
 
1985
1985
    def test_defaults_to_BZR_COLUMNS(self):
1986
1986
        # BZR_COLUMNS is set by the test framework
1987
1987
        self.assertNotEqual('12', os.environ['BZR_COLUMNS'])
1988
 
        os.environ['BZR_COLUMNS'] = '12'
 
1988
        self.overrideEnv('BZR_COLUMNS', '12')
1989
1989
        self.assertEqual(12, osutils.terminal_width())
1990
1990
 
 
1991
    def test_BZR_COLUMNS_0_no_limit(self):
 
1992
        self.overrideEnv('BZR_COLUMNS', '0')
 
1993
        self.assertEqual(None, osutils.terminal_width())
 
1994
 
1991
1995
    def test_falls_back_to_COLUMNS(self):
1992
 
        del os.environ['BZR_COLUMNS']
 
1996
        self.overrideEnv('BZR_COLUMNS', None)
1993
1997
        self.assertNotEqual('42', os.environ['COLUMNS'])
1994
1998
        self.set_fake_tty()
1995
 
        os.environ['COLUMNS'] = '42'
 
1999
        self.overrideEnv('COLUMNS', '42')
1996
2000
        self.assertEqual(42, osutils.terminal_width())
1997
2001
 
1998
2002
    def test_tty_default_without_columns(self):
1999
 
        del os.environ['BZR_COLUMNS']
2000
 
        del os.environ['COLUMNS']
 
2003
        self.overrideEnv('BZR_COLUMNS', None)
 
2004
        self.overrideEnv('COLUMNS', None)
2001
2005
 
2002
2006
        def terminal_size(w, h):
2003
2007
            return 42, 42
2010
2014
        self.assertEqual(42, osutils.terminal_width())
2011
2015
 
2012
2016
    def test_non_tty_default_without_columns(self):
2013
 
        del os.environ['BZR_COLUMNS']
2014
 
        del os.environ['COLUMNS']
 
2017
        self.overrideEnv('BZR_COLUMNS', None)
 
2018
        self.overrideEnv('COLUMNS', None)
2015
2019
        self.replace_stdout(None)
2016
2020
        self.assertEqual(None, osutils.terminal_width())
2017
2021
 
2027
2031
        else:
2028
2032
            self.overrideAttr(termios, 'TIOCGWINSZ')
2029
2033
            del termios.TIOCGWINSZ
2030
 
        del os.environ['BZR_COLUMNS']
2031
 
        del os.environ['COLUMNS']
 
2034
        self.overrideEnv('BZR_COLUMNS', None)
 
2035
        self.overrideEnv('COLUMNS', None)
2032
2036
        # Whatever the result is, if we don't raise an exception, it's ok.
2033
2037
        osutils.terminal_width()
2034
2038
 
2070
2074
class TestGetuserUnicode(tests.TestCase):
2071
2075
 
2072
2076
    def test_ascii_user(self):
2073
 
        osutils.set_or_unset_env('LOGNAME', 'jrandom')
 
2077
        self.overrideEnv('LOGNAME', 'jrandom')
2074
2078
        self.assertEqual(u'jrandom', osutils.getuser_unicode())
2075
2079
 
2076
2080
    def test_unicode_user(self):
2082
2086
                % (osutils.get_user_encoding(),))
2083
2087
        uni_username = u'jrandom' + uni_val
2084
2088
        encoded_username = uni_username.encode(ue)
2085
 
        osutils.set_or_unset_env('LOGNAME', encoded_username)
 
2089
        self.overrideEnv('LOGNAME', encoded_username)
2086
2090
        self.assertEqual(uni_username, osutils.getuser_unicode())
2087
 
        osutils.set_or_unset_env('LOGNAME', u'jrandom\xb6'.encode(ue))
 
2091
        self.overrideEnv('LOGNAME', u'jrandom\xb6'.encode(ue))
2088
2092
        self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())
2089
2093
 
2090
2094
class TestBackupNames(tests.TestCase):