437
436
self.assertTrue(-eighteen_hours < offset < eighteen_hours)
440
class TestFdatasync(tests.TestCaseInTempDir):
442
def do_fdatasync(self):
443
f = tempfile.NamedTemporaryFile()
444
osutils.fdatasync(f.fileno())
448
def raise_eopnotsupp(*args, **kwargs):
449
raise IOError(errno.EOPNOTSUPP, os.strerror(errno.EOPNOTSUPP))
452
def raise_enotsup(*args, **kwargs):
453
raise IOError(errno.ENOTSUP, os.strerror(errno.ENOTSUP))
455
def test_fdatasync_handles_system_function(self):
456
self.overrideAttr(os, "fdatasync")
459
def test_fdatasync_handles_no_fdatasync_no_fsync(self):
460
self.overrideAttr(os, "fdatasync")
461
self.overrideAttr(os, "fsync")
464
def test_fdatasync_handles_no_EOPNOTSUPP(self):
465
self.overrideAttr(errno, "EOPNOTSUPP")
468
def test_fdatasync_catches_ENOTSUP(self):
469
enotsup = getattr(errno, "ENOTSUP", None)
471
raise tests.TestNotApplicable("No ENOTSUP on this platform")
472
self.overrideAttr(os, "fdatasync", self.raise_enotsup)
475
def test_fdatasync_catches_EOPNOTSUPP(self):
476
enotsup = getattr(errno, "EOPNOTSUPP", None)
478
raise tests.TestNotApplicable("No EOPNOTSUPP on this platform")
479
self.overrideAttr(os, "fdatasync", self.raise_eopnotsupp)
483
439
class TestLinks(tests.TestCaseInTempDir):
485
441
def test_dereference_path(self):
598
554
"""Test pumpfile method."""
601
super(TestPumpFile, self).setUp()
557
tests.TestCase.setUp(self)
602
558
# create a test datablock
603
559
self.block_size = 512
604
560
pattern = '0123456789ABCDEF'
872
828
self.assertEqual(None, osutils.safe_file_id(None))
875
class TestSendAll(tests.TestCase):
877
def test_send_with_disconnected_socket(self):
878
class DisconnectedSocket(object):
879
def __init__(self, err):
881
def send(self, content):
885
# All of these should be treated as ConnectionReset
887
for err_cls in (IOError, socket.error):
888
for errnum in osutils._end_of_stream_errors:
889
errs.append(err_cls(errnum))
891
sock = DisconnectedSocket(err)
892
self.assertRaises(errors.ConnectionReset,
893
osutils.send_all, sock, 'some more content')
895
def test_send_with_no_progress(self):
896
# See https://bugs.launchpad.net/bzr/+bug/1047309
897
# It seems that paramiko can get into a state where it doesn't error,
898
# but it returns 0 bytes sent for requests over and over again.
899
class NoSendingSocket(object):
902
def send(self, bytes):
904
if self.call_count > 100:
905
# Prevent the test suite from hanging
906
raise RuntimeError('too many calls')
908
sock = NoSendingSocket()
909
self.assertRaises(errors.ConnectionReset,
910
osutils.send_all, sock, 'content')
911
self.assertEqual(1, sock.call_count)
914
831
class TestPosixFuncs(tests.TestCase):
915
832
"""Test that the posix version of normpath returns an appropriate path
916
833
when used with 2 leading slashes."""
943
860
osutils._win32_pathjoin('path/to', 'C:/foo'))
944
861
self.assertEqual('path/to/foo',
945
862
osutils._win32_pathjoin('path/to/', 'foo'))
947
def test_pathjoin_late_bugfix(self):
948
if sys.version_info < (2, 7, 6):
952
self.assertEqual(expected,
863
self.assertEqual('/foo',
953
864
osutils._win32_pathjoin('C:/path/to/', '/foo'))
954
self.assertEqual(expected,
865
self.assertEqual('/foo',
955
866
osutils._win32_pathjoin('C:\\path\\to\\', '\\foo'))
957
868
def test_normpath(self):
1860
1771
_native_to_unicode = None
1862
1773
def setUp(self):
1863
super(TestDirReader, self).setUp()
1774
tests.TestCaseInTempDir.setUp(self)
1864
1775
self.overrideAttr(osutils,
1865
1776
'_selected_dir_reader', self._dir_reader_class())
2074
1985
class TestTerminalWidth(tests.TestCase):
2076
1987
def setUp(self):
2077
super(TestTerminalWidth, self).setUp()
1988
tests.TestCase.setUp(self)
2078
1989
self._orig_terminal_size_state = osutils._terminal_size_state
2079
1990
self._orig_first_terminal_size = osutils._first_terminal_size
2080
1991
self.addCleanup(self.restore_osutils_globals)
2161
2072
_test_needs_features = [features.chown_feature]
2163
2074
def setUp(self):
2164
super(TestCreationOps, self).setUp()
2075
tests.TestCaseInTempDir.setUp(self)
2165
2076
self.overrideAttr(os, 'chown', self._dummy_chown)
2167
2078
# params set by call to _dummy_chown