helpers.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from datetime import datetime
  2. from darc.helpers import Location, format_timedelta, IncludePattern
  3. from darc.testsuite import DarcTestCase
  4. class LocationTestCase(DarcTestCase):
  5. def test(self):
  6. self.assert_equal(
  7. repr(Location('ssh://user@host:1234/some/path::archive')),
  8. "Location(proto='ssh', user='user', host='host', port=1234, path='/some/path', archive='archive')"
  9. )
  10. self.assert_equal(
  11. repr(Location('file:///some/path::archive')),
  12. "Location(proto='file', user=None, host=None, port=None, path='/some/path', archive='archive')"
  13. )
  14. self.assert_equal(
  15. repr(Location('user@host:/some/path::archive')),
  16. "Location(proto='ssh', user='user', host='host', port=22, path='/some/path', archive='archive')"
  17. )
  18. self.assert_equal(
  19. repr(Location('/some/path::archive')),
  20. "Location(proto='file', user=None, host=None, port=None, path='/some/path', archive='archive')"
  21. )
  22. class FormatTimedeltaTestCase(DarcTestCase):
  23. def test(self):
  24. t0 = datetime(2001, 1, 1, 10, 20, 3, 0)
  25. t1 = datetime(2001, 1, 1, 12, 20, 4, 100000)
  26. self.assert_equal(
  27. format_timedelta(t1 - t0),
  28. '2 hours 1.10 seconds'
  29. )
  30. class PatternTestCase(DarcTestCase):
  31. def test(self):
  32. py = IncludePattern('*.py')
  33. foo = IncludePattern('/foo')
  34. self.assert_equal(py.match('/foo/foo.py'), True)
  35. self.assert_equal(py.match('/bar/foo.java'), False)
  36. self.assert_equal(foo.match('/foo/foo.py'), True)
  37. self.assert_equal(foo.match('/bar/foo.java'), False)
  38. self.assert_equal(foo.match('/foobar/foo.py'), False)
  39. self.assert_equal(foo.match('/foo'), True)