borg/attic/testsuite/helpers.py

57 lines
2.3 KiB
Python
Raw Normal View History

2013-06-24 20:41:05 +00:00
from datetime import datetime
2013-07-08 21:38:27 +00:00
from attic.helpers import Location, format_timedelta, IncludePattern, ExcludePattern
from attic.testsuite import AtticTestCase
2013-06-24 20:41:05 +00:00
2013-07-08 21:38:27 +00:00
class LocationTestCase(AtticTestCase):
2013-06-24 20:41:05 +00:00
def test(self):
self.assert_equal(
repr(Location('ssh://user@host:1234/some/path::archive')),
"Location(proto='ssh', user='user', host='host', port=1234, path='/some/path', archive='archive')"
)
self.assert_equal(
repr(Location('file:///some/path::archive')),
"Location(proto='file', user=None, host=None, port=None, path='/some/path', archive='archive')"
)
self.assert_equal(
repr(Location('user@host:/some/path::archive')),
"Location(proto='ssh', user='user', host='host', port=22, path='/some/path', archive='archive')"
)
self.assert_equal(
2013-07-08 21:38:27 +00:00
repr(Location('mybackup.attic::archive')),
"Location(proto='file', user=None, host=None, port=None, path='mybackup.attic', archive='archive')"
)
self.assert_equal(
repr(Location('/some/absolute/path::archive')),
"Location(proto='file', user=None, host=None, port=None, path='/some/absolute/path', archive='archive')"
)
self.assert_equal(
repr(Location('some/relative/path::archive')),
"Location(proto='file', user=None, host=None, port=None, path='some/relative/path', archive='archive')"
2013-06-24 20:41:05 +00:00
)
2013-07-08 21:38:27 +00:00
class FormatTimedeltaTestCase(AtticTestCase):
2013-06-24 20:41:05 +00:00
def test(self):
t0 = datetime(2001, 1, 1, 10, 20, 3, 0)
t1 = datetime(2001, 1, 1, 12, 20, 4, 100000)
self.assert_equal(
format_timedelta(t1 - t0),
'2 hours 1.10 seconds'
)
2013-07-08 21:38:27 +00:00
class PatternTestCase(AtticTestCase):
2013-06-24 20:41:05 +00:00
def test(self):
2013-06-30 20:32:27 +00:00
self.assert_equal(IncludePattern('/usr').match('/usr'), True)
self.assert_equal(IncludePattern('/usr').match('/usr/bin'), True)
self.assert_equal(IncludePattern('/usr').match('/usrbin'), False)
self.assert_equal(ExcludePattern('*.py').match('foo.py'), True)
self.assert_equal(ExcludePattern('*.py').match('foo.pl'), False)
self.assert_equal(ExcludePattern('/tmp').match('/tmp'), True)
self.assert_equal(ExcludePattern('/tmp').match('/tmp/foo'), True)
self.assert_equal(ExcludePattern('/tmp').match('/tmofoo'), False)