/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 bzrlib/tests/test_osutils.py

  • Committer: Aaron Bentley
  • Date: 2009-12-07 21:46:28 UTC
  • mfrom: (4871 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4873.
  • Revision ID: aaron@aaronbentley.com-20091207214628-yifwgux0fn4x3bo4
Merge bzr.dev into merge-i-lock.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import socket
24
24
import stat
25
25
import sys
 
26
import termios
26
27
import time
27
28
 
28
29
from bzrlib import (
378
379
        # Instead blackbox.test_locale should check for localized
379
380
        # dates once they do occur in output strings.
380
381
 
 
382
    def test_format_date_with_offset_in_original_timezone(self):
 
383
        self.assertEqual("Thu 1970-01-01 00:00:00 +0000",
 
384
            osutils.format_date_with_offset_in_original_timezone(0))
 
385
        self.assertEqual("Fri 1970-01-02 03:46:40 +0000",
 
386
            osutils.format_date_with_offset_in_original_timezone(100000))
 
387
        self.assertEqual("Fri 1970-01-02 05:46:40 +0200",
 
388
            osutils.format_date_with_offset_in_original_timezone(100000, 7200))
 
389
 
381
390
    def test_local_time_offset(self):
382
391
        """Test that local_time_offset() returns a sane value."""
383
392
        offset = osutils.local_time_offset()
1847
1856
 
1848
1857
class TestConcurrency(tests.TestCase):
1849
1858
 
 
1859
    def setUp(self):
 
1860
        super(TestConcurrency, self).setUp()
 
1861
        orig = osutils._cached_local_concurrency
 
1862
        def restore():
 
1863
            osutils._cached_local_concurrency = orig
 
1864
        self.addCleanup(restore)
 
1865
 
1850
1866
    def test_local_concurrency(self):
1851
1867
        concurrency = osutils.local_concurrency()
1852
1868
        self.assertIsInstance(concurrency, int)
1853
1869
 
 
1870
    def test_local_concurrency_environment_variable(self):
 
1871
        os.environ['BZR_CONCURRENCY'] = '2'
 
1872
        self.assertEqual(2, osutils.local_concurrency(use_cache=False))
 
1873
        os.environ['BZR_CONCURRENCY'] = '3'
 
1874
        self.assertEqual(3, osutils.local_concurrency(use_cache=False))
 
1875
        os.environ['BZR_CONCURRENCY'] = 'foo'
 
1876
        self.assertEqual(1, osutils.local_concurrency(use_cache=False))
 
1877
 
 
1878
    def test_option_concurrency(self):
 
1879
        os.environ['BZR_CONCURRENCY'] = '1'
 
1880
        self.run_bzr('rocks --concurrency 42')
 
1881
        # Command line overrides envrionment variable
 
1882
        self.assertEquals('42', os.environ['BZR_CONCURRENCY'])
 
1883
        self.assertEquals(42, osutils.local_concurrency(use_cache=False))
 
1884
 
1854
1885
 
1855
1886
class TestFailedToLoadExtension(tests.TestCase):
1856
1887
 
1892
1923
            r"bzr: warning: some compiled extensions could not be loaded; "
1893
1924
            "see <https://answers\.launchpad\.net/bzr/\+faq/703>\n"
1894
1925
            )
 
1926
 
 
1927
 
 
1928
class TestTerminalWidth(tests.TestCase):
 
1929
 
 
1930
    def test_default_values(self):
 
1931
        self.assertEquals(80, osutils.default_terminal_width)
 
1932
 
 
1933
    def test_defaults_to_BZR_COLUMNS(self):
 
1934
        # BZR_COLUMNS is set by the test framework
 
1935
        self.assertEquals('80', os.environ['BZR_COLUMNS'])
 
1936
        os.environ['BZR_COLUMNS'] = '12'
 
1937
        self.assertEquals(12, osutils.terminal_width())
 
1938
 
 
1939
    def test_tty_default_without_columns(self):
 
1940
        del os.environ['BZR_COLUMNS']
 
1941
        del os.environ['COLUMNS']
 
1942
        orig_stdout = sys.stdout
 
1943
        def restore():
 
1944
            sys.stdout = orig_stdout
 
1945
        self.addCleanup(restore)
 
1946
 
 
1947
        class I_am_a_tty(object):
 
1948
            def isatty(self):
 
1949
                return True
 
1950
 
 
1951
        sys.stdout = I_am_a_tty()
 
1952
        self.assertEquals(None, osutils.terminal_width())
 
1953
 
 
1954
    def test_non_tty_default_without_columns(self):
 
1955
        del os.environ['BZR_COLUMNS']
 
1956
        del os.environ['COLUMNS']
 
1957
        orig_stdout = sys.stdout
 
1958
        def restore():
 
1959
            sys.stdout = orig_stdout
 
1960
        self.addCleanup(restore)
 
1961
        sys.stdout = None
 
1962
        self.assertEquals(None, osutils.terminal_width())
 
1963
 
 
1964
    def test_TIOCGWINSZ(self):
 
1965
        # bug 63539 is about a termios without TIOCGWINSZ attribute
 
1966
        exist = True
 
1967
        try:
 
1968
            orig = termios.TIOCGWINSZ
 
1969
        except AttributeError:
 
1970
            exist = False
 
1971
 
 
1972
        def restore():
 
1973
            if exist:
 
1974
                termios.TIOCGWINSZ = orig
 
1975
        self.addCleanup(restore)
 
1976
 
 
1977
        del termios.TIOCGWINSZ
 
1978
        del os.environ['BZR_COLUMNS']
 
1979
        del os.environ['COLUMNS']
 
1980
        self.assertEquals(None, osutils.terminal_width())