580
580
self.assertEqual([('source/lnk', 'target/lnk')], processed_links)
583
class TestTerminalEncoding(TestCase):
584
"""Test the auto-detection of proper terminal encoding."""
587
self._stdout = sys.stdout
588
self._stderr = sys.stderr
589
self._stdin = sys.stdin
590
self._user_encoding = bzrlib.user_encoding
592
self.addCleanup(self._reset)
594
sys.stdout = StringIOWrapper()
595
sys.stdout.encoding = 'stdout_encoding'
596
sys.stderr = StringIOWrapper()
597
sys.stderr.encoding = 'stderr_encoding'
598
sys.stdin = StringIOWrapper()
599
sys.stdin.encoding = 'stdin_encoding'
600
bzrlib.user_encoding = 'user_encoding'
603
sys.stdout = self._stdout
604
sys.stderr = self._stderr
605
sys.stdin = self._stdin
606
bzrlib.user_encoding = self._user_encoding
608
def test_get_terminal_encoding(self):
609
# first preference is stdout encoding
610
self.assertEqual('stdout_encoding', osutils.get_terminal_encoding())
612
sys.stdout.encoding = None
613
# if sys.stdout is None, fall back to sys.stdin
614
self.assertEqual('stdin_encoding', osutils.get_terminal_encoding())
616
sys.stdin.encoding = None
617
# and in the worst case, use bzrlib.user_encoding
618
self.assertEqual('user_encoding', osutils.get_terminal_encoding())
583
#class TestTerminalEncoding has been moved to test_osutils_encodings.py
584
# [bialix] 2006/12/26
621
587
class TestSetUnsetEnv(TestCase):
677
643
self.assertEqual(None, os.environ.get('BZR_TEST_ENV_VAR'))
678
644
self.failIf('BZR_TEST_ENV_VAR' in os.environ)
647
class TestLocalTimeOffset(TestCase):
649
def test_local_time_offset(self):
650
"""Test that local_time_offset() returns a sane value."""
651
offset = osutils.local_time_offset()
652
self.assertTrue(isinstance(offset, int))
653
# Test that the offset is no more than a eighteen hours in
655
# Time zone handling is system specific, so it is difficult to
656
# do more specific tests, but a value outside of this range is
658
eighteen_hours = 18 * 3600
659
self.assertTrue(-eighteen_hours < offset < eighteen_hours)
661
def test_local_time_offset_with_timestamp(self):
662
"""Test that local_time_offset() works with a timestamp."""
663
offset = osutils.local_time_offset(1000000000.1234567)
664
self.assertTrue(isinstance(offset, int))
665
eighteen_hours = 18 * 3600
666
self.assertTrue(-eighteen_hours < offset < eighteen_hours)