mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-07-25 12:15:32 +03:00
164 lines
6.3 KiB
Diff
164 lines
6.3 KiB
Diff
diff --git a/src/twisted/conch/test/test_cftp.py b/src/twisted/conch/test/test_cftp.py
|
|
index 58eb5cc..62e8a8b 100644
|
|
--- a/src/twisted/conch/test/test_cftp.py
|
|
+++ b/src/twisted/conch/test/test_cftp.py
|
|
@@ -64,158 +64,6 @@ class SSHSessionTests(TestCase):
|
|
|
|
|
|
|
|
-class ListingTests(TestCase):
|
|
- """
|
|
- Tests for L{lsLine}, the function which generates an entry for a file or
|
|
- directory in an SFTP I{ls} command's output.
|
|
- """
|
|
- if getattr(time, 'tzset', None) is None:
|
|
- skip = "Cannot test timestamp formatting code without time.tzset"
|
|
-
|
|
-
|
|
- def setUp(self):
|
|
- """
|
|
- Patch the L{ls} module's time function so the results of L{lsLine} are
|
|
- deterministic.
|
|
- """
|
|
- self.now = 123456789
|
|
- def fakeTime():
|
|
- return self.now
|
|
- self.patch(ls, 'time', fakeTime)
|
|
-
|
|
- # Make sure that the timezone ends up the same after these tests as
|
|
- # it was before.
|
|
- if 'TZ' in os.environ:
|
|
- self.addCleanup(operator.setitem, os.environ, 'TZ', os.environ['TZ'])
|
|
- self.addCleanup(time.tzset)
|
|
- else:
|
|
- def cleanup():
|
|
- # os.environ.pop is broken! Don't use it! Ever! Or die!
|
|
- try:
|
|
- del os.environ['TZ']
|
|
- except KeyError:
|
|
- pass
|
|
- time.tzset()
|
|
- self.addCleanup(cleanup)
|
|
-
|
|
-
|
|
- def _lsInTimezone(self, timezone, stat):
|
|
- """
|
|
- Call L{ls.lsLine} after setting the timezone to C{timezone} and return
|
|
- the result.
|
|
- """
|
|
- # Set the timezone to a well-known value so the timestamps are
|
|
- # predictable.
|
|
- os.environ['TZ'] = timezone
|
|
- time.tzset()
|
|
- return ls.lsLine('foo', stat)
|
|
-
|
|
-
|
|
- def test_oldFile(self):
|
|
- """
|
|
- A file with an mtime six months (approximately) or more in the past has
|
|
- a listing including a low-resolution timestamp.
|
|
- """
|
|
- # Go with 7 months. That's more than 6 months.
|
|
- then = self.now - (60 * 60 * 24 * 31 * 7)
|
|
- stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0))
|
|
-
|
|
- self.assertEqual(
|
|
- self._lsInTimezone('America/New_York', stat),
|
|
- '!--------- 0 0 0 0 Apr 26 1973 foo')
|
|
- self.assertEqual(
|
|
- self._lsInTimezone('Pacific/Auckland', stat),
|
|
- '!--------- 0 0 0 0 Apr 27 1973 foo')
|
|
-
|
|
-
|
|
- def test_oldSingleDigitDayOfMonth(self):
|
|
- """
|
|
- A file with a high-resolution timestamp which falls on a day of the
|
|
- month which can be represented by one decimal digit is formatted with
|
|
- one padding 0 to preserve the columns which come after it.
|
|
- """
|
|
- # A point about 7 months in the past, tweaked to fall on the first of a
|
|
- # month so we test the case we want to test.
|
|
- then = self.now - (60 * 60 * 24 * 31 * 7) + (60 * 60 * 24 * 5)
|
|
- stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0))
|
|
-
|
|
- self.assertEqual(
|
|
- self._lsInTimezone('America/New_York', stat),
|
|
- '!--------- 0 0 0 0 May 01 1973 foo')
|
|
- self.assertEqual(
|
|
- self._lsInTimezone('Pacific/Auckland', stat),
|
|
- '!--------- 0 0 0 0 May 02 1973 foo')
|
|
-
|
|
-
|
|
- def test_newFile(self):
|
|
- """
|
|
- A file with an mtime fewer than six months (approximately) in the past
|
|
- has a listing including a high-resolution timestamp excluding the year.
|
|
- """
|
|
- # A point about three months in the past.
|
|
- then = self.now - (60 * 60 * 24 * 31 * 3)
|
|
- stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0))
|
|
-
|
|
- self.assertEqual(
|
|
- self._lsInTimezone('America/New_York', stat),
|
|
- '!--------- 0 0 0 0 Aug 28 17:33 foo')
|
|
- self.assertEqual(
|
|
- self._lsInTimezone('Pacific/Auckland', stat),
|
|
- '!--------- 0 0 0 0 Aug 29 09:33 foo')
|
|
-
|
|
-
|
|
- def test_localeIndependent(self):
|
|
- """
|
|
- The month name in the date is locale independent.
|
|
- """
|
|
- # A point about three months in the past.
|
|
- then = self.now - (60 * 60 * 24 * 31 * 3)
|
|
- stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0))
|
|
-
|
|
- # Fake that we're in a language where August is not Aug (e.g.: Spanish)
|
|
- currentLocale = locale.getlocale()
|
|
- locale.setlocale(locale.LC_ALL, "es_AR.UTF8")
|
|
- self.addCleanup(locale.setlocale, locale.LC_ALL, currentLocale)
|
|
-
|
|
- self.assertEqual(
|
|
- self._lsInTimezone('America/New_York', stat),
|
|
- '!--------- 0 0 0 0 Aug 28 17:33 foo')
|
|
- self.assertEqual(
|
|
- self._lsInTimezone('Pacific/Auckland', stat),
|
|
- '!--------- 0 0 0 0 Aug 29 09:33 foo')
|
|
-
|
|
- # If alternate locale is not available, the previous test will be
|
|
- # skipped, please install this locale for it to run
|
|
- currentLocale = locale.getlocale()
|
|
- try:
|
|
- try:
|
|
- locale.setlocale(locale.LC_ALL, "es_AR.UTF8")
|
|
- except locale.Error:
|
|
- test_localeIndependent.skip = "The es_AR.UTF8 locale is not installed."
|
|
- finally:
|
|
- locale.setlocale(locale.LC_ALL, currentLocale)
|
|
-
|
|
-
|
|
- def test_newSingleDigitDayOfMonth(self):
|
|
- """
|
|
- A file with a high-resolution timestamp which falls on a day of the
|
|
- month which can be represented by one decimal digit is formatted with
|
|
- one padding 0 to preserve the columns which come after it.
|
|
- """
|
|
- # A point about three months in the past, tweaked to fall on the first
|
|
- # of a month so we test the case we want to test.
|
|
- then = self.now - (60 * 60 * 24 * 31 * 3) + (60 * 60 * 24 * 4)
|
|
- stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0))
|
|
-
|
|
- self.assertEqual(
|
|
- self._lsInTimezone('America/New_York', stat),
|
|
- '!--------- 0 0 0 0 Sep 01 17:33 foo')
|
|
- self.assertEqual(
|
|
- self._lsInTimezone('Pacific/Auckland', stat),
|
|
- '!--------- 0 0 0 0 Sep 02 09:33 foo')
|
|
-
|
|
-
|
|
-
|
|
class InMemorySSHChannel(StringTransport, object):
|
|
"""
|
|
Minimal implementation of a L{SSHChannel} like class which only reads and
|
|
|