~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Vincent Ladeuil
  • Date: 2011-02-18 10:33:36 UTC
  • mto: This revision was merged to the branch mainline in revision 5684.
  • Revision ID: v.ladeuil+lp@free.fr-20110218103336-83nx6nqk06ibgqky
Turn the exception about dict option expansion into a warning.

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
38
38
    file_utils,
39
39
    test__walkdirs_win32,
40
40
    )
 
41
from bzrlib.tests.scenarios import load_tests_apply_scenarios
41
42
 
42
43
 
43
44
class _UTF8DirReaderFeature(tests.Feature):
96
97
    return scenarios
97
98
 
98
99
 
99
 
def load_tests(basic_tests, module, loader):
100
 
    suite = loader.suiteClass()
101
 
    dir_reader_tests, remaining_tests = tests.split_suite_by_condition(
102
 
        basic_tests, tests.condition_isinstance(TestDirReader))
103
 
    tests.multiply_tests(dir_reader_tests, dir_reader_scenarios(), suite)
104
 
    suite.addTest(remaining_tests)
105
 
    return suite
 
100
load_tests = load_tests_apply_scenarios
106
101
 
107
102
 
108
103
class TestContainsWhitespace(tests.TestCase):
1107
1102
 
1108
1103
        # rename the 1file to a latin-1 filename
1109
1104
        os.rename("./1file", "\xe8file")
 
1105
        if "\xe8file" not in os.listdir("."):
 
1106
            self.skip("Lack filesystem that preserves arbitrary bytes")
1110
1107
 
1111
1108
        self._save_platform_info()
1112
1109
        win32utils.winver = None # Avoid the win32 detection code
1733
1730
 
1734
1731
class TestDirReader(tests.TestCaseInTempDir):
1735
1732
 
 
1733
    scenarios = dir_reader_scenarios()
 
1734
 
1736
1735
    # Set by load_tests
1737
1736
    _dir_reader_class = None
1738
1737
    _native_to_unicode = None
1900
1899
        self.assertIsInstance(concurrency, int)
1901
1900
 
1902
1901
    def test_local_concurrency_environment_variable(self):
1903
 
        os.environ['BZR_CONCURRENCY'] = '2'
 
1902
        self.overrideEnv('BZR_CONCURRENCY', '2')
1904
1903
        self.assertEqual(2, osutils.local_concurrency(use_cache=False))
1905
 
        os.environ['BZR_CONCURRENCY'] = '3'
 
1904
        self.overrideEnv('BZR_CONCURRENCY', '3')
1906
1905
        self.assertEqual(3, osutils.local_concurrency(use_cache=False))
1907
 
        os.environ['BZR_CONCURRENCY'] = 'foo'
 
1906
        self.overrideEnv('BZR_CONCURRENCY', 'foo')
1908
1907
        self.assertEqual(1, osutils.local_concurrency(use_cache=False))
1909
1908
 
1910
1909
    def test_option_concurrency(self):
1911
 
        os.environ['BZR_CONCURRENCY'] = '1'
 
1910
        self.overrideEnv('BZR_CONCURRENCY', '1')
1912
1911
        self.run_bzr('rocks --concurrency 42')
1913
 
        # Command line overrides envrionment variable
 
1912
        # Command line overrides environment variable
1914
1913
        self.assertEquals('42', os.environ['BZR_CONCURRENCY'])
1915
1914
        self.assertEquals(42, osutils.local_concurrency(use_cache=False))
1916
1915
 
1986
1985
    def test_defaults_to_BZR_COLUMNS(self):
1987
1986
        # BZR_COLUMNS is set by the test framework
1988
1987
        self.assertNotEqual('12', os.environ['BZR_COLUMNS'])
1989
 
        os.environ['BZR_COLUMNS'] = '12'
 
1988
        self.overrideEnv('BZR_COLUMNS', '12')
1990
1989
        self.assertEqual(12, osutils.terminal_width())
1991
1990
 
 
1991
    def test_BZR_COLUMNS_0_no_limit(self):
 
1992
        self.overrideEnv('BZR_COLUMNS', '0')
 
1993
        self.assertEqual(None, osutils.terminal_width())
 
1994
 
1992
1995
    def test_falls_back_to_COLUMNS(self):
1993
 
        del os.environ['BZR_COLUMNS']
 
1996
        self.overrideEnv('BZR_COLUMNS', None)
1994
1997
        self.assertNotEqual('42', os.environ['COLUMNS'])
1995
1998
        self.set_fake_tty()
1996
 
        os.environ['COLUMNS'] = '42'
 
1999
        self.overrideEnv('COLUMNS', '42')
1997
2000
        self.assertEqual(42, osutils.terminal_width())
1998
2001
 
1999
2002
    def test_tty_default_without_columns(self):
2000
 
        del os.environ['BZR_COLUMNS']
2001
 
        del os.environ['COLUMNS']
 
2003
        self.overrideEnv('BZR_COLUMNS', None)
 
2004
        self.overrideEnv('COLUMNS', None)
2002
2005
 
2003
2006
        def terminal_size(w, h):
2004
2007
            return 42, 42
2011
2014
        self.assertEqual(42, osutils.terminal_width())
2012
2015
 
2013
2016
    def test_non_tty_default_without_columns(self):
2014
 
        del os.environ['BZR_COLUMNS']
2015
 
        del os.environ['COLUMNS']
 
2017
        self.overrideEnv('BZR_COLUMNS', None)
 
2018
        self.overrideEnv('COLUMNS', None)
2016
2019
        self.replace_stdout(None)
2017
2020
        self.assertEqual(None, osutils.terminal_width())
2018
2021
 
2028
2031
        else:
2029
2032
            self.overrideAttr(termios, 'TIOCGWINSZ')
2030
2033
            del termios.TIOCGWINSZ
2031
 
        del os.environ['BZR_COLUMNS']
2032
 
        del os.environ['COLUMNS']
 
2034
        self.overrideEnv('BZR_COLUMNS', None)
 
2035
        self.overrideEnv('COLUMNS', None)
2033
2036
        # Whatever the result is, if we don't raise an exception, it's ok.
2034
2037
        osutils.terminal_width()
2035
2038
 
2071
2074
class TestGetuserUnicode(tests.TestCase):
2072
2075
 
2073
2076
    def test_ascii_user(self):
2074
 
        osutils.set_or_unset_env('LOGNAME', 'jrandom')
 
2077
        self.overrideEnv('LOGNAME', 'jrandom')
2075
2078
        self.assertEqual(u'jrandom', osutils.getuser_unicode())
2076
2079
 
2077
2080
    def test_unicode_user(self):
2083
2086
                % (osutils.get_user_encoding(),))
2084
2087
        uni_username = u'jrandom' + uni_val
2085
2088
        encoded_username = uni_username.encode(ue)
2086
 
        osutils.set_or_unset_env('LOGNAME', encoded_username)
 
2089
        self.overrideEnv('LOGNAME', encoded_username)
2087
2090
        self.assertEqual(uni_username, osutils.getuser_unicode())
2088
 
        osutils.set_or_unset_env('LOGNAME', u'jrandom\xb6'.encode(ue))
 
2091
        self.overrideEnv('LOGNAME', u'jrandom\xb6'.encode(ue))
2089
2092
        self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())
2090
2093
 
2091
2094
class TestBackupNames(tests.TestCase):
2116
2119
        # revisited if we test against all implementations.
2117
2120
        self.backups.remove('file.~2~')
2118
2121
        self.assertBackupName('file.~2~', 'file')
 
2122
 
 
2123
 
 
2124
class TestFindExecutableInPath(tests.TestCase):
 
2125
 
 
2126
    def test_windows(self):
 
2127
        if sys.platform != 'win32':
 
2128
            raise tests.TestSkipped('test requires win32')
 
2129
        self.assertTrue(osutils.find_executable_on_path('explorer') is not None)
 
2130
        self.assertTrue(
 
2131
            osutils.find_executable_on_path('explorer.exe') is not None)
 
2132
        self.assertTrue(
 
2133
            osutils.find_executable_on_path('EXPLORER.EXE') is not None)
 
2134
        self.assertTrue(
 
2135
            osutils.find_executable_on_path('THIS SHOULD NOT EXIST') is None)
 
2136
        self.assertTrue(osutils.find_executable_on_path('file.txt') is None)
 
2137
 
 
2138
    def test_other(self):
 
2139
        if sys.platform == 'win32':
 
2140
            raise tests.TestSkipped('test requires non-win32')
 
2141
        self.assertTrue(osutils.find_executable_on_path('sh') is not None)
 
2142
        self.assertTrue(
 
2143
            osutils.find_executable_on_path('THIS SHOULD NOT EXIST') is None)