|
@@ -23,42 +23,115 @@ class BigIntTestCase(BaseTestCase):
|
|
|
self.assert_equal(bigint_to_int(int_to_bigint(2**70)), 2**70)
|
|
|
|
|
|
|
|
|
-class LocationTestCase(BaseTestCase):
|
|
|
-
|
|
|
- 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=None, path='/some/path', archive='archive')"
|
|
|
- )
|
|
|
- self.assert_equal(
|
|
|
- repr(Location('path::archive')),
|
|
|
- "Location(proto='file', user=None, host=None, port=None, path='path', 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')"
|
|
|
- )
|
|
|
- self.assert_raises(ValueError, lambda: Location('ssh://localhost:22/path:archive'))
|
|
|
-
|
|
|
- def test_canonical_path(self):
|
|
|
+class TestLocationWithoutEnv:
|
|
|
+ def test_ssh(self, monkeypatch):
|
|
|
+ monkeypatch.delenv('BORG_REPO', raising=False)
|
|
|
+ assert repr(Location('ssh://user@host:1234/some/path::archive')) == \
|
|
|
+ "Location(proto='ssh', user='user', host='host', port=1234, path='/some/path', archive='archive')"
|
|
|
+ assert repr(Location('ssh://user@host:1234/some/path')) == \
|
|
|
+ "Location(proto='ssh', user='user', host='host', port=1234, path='/some/path', archive=None)"
|
|
|
+
|
|
|
+ def test_file(self, monkeypatch):
|
|
|
+ monkeypatch.delenv('BORG_REPO', raising=False)
|
|
|
+ assert repr(Location('file:///some/path::archive')) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='/some/path', archive='archive')"
|
|
|
+ assert repr(Location('file:///some/path')) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='/some/path', archive=None)"
|
|
|
+
|
|
|
+ def test_scp(self, monkeypatch):
|
|
|
+ monkeypatch.delenv('BORG_REPO', raising=False)
|
|
|
+ assert repr(Location('user@host:/some/path::archive')) == \
|
|
|
+ "Location(proto='ssh', user='user', host='host', port=None, path='/some/path', archive='archive')"
|
|
|
+ assert repr(Location('user@host:/some/path')) == \
|
|
|
+ "Location(proto='ssh', user='user', host='host', port=None, path='/some/path', archive=None)"
|
|
|
+
|
|
|
+ def test_folder(self, monkeypatch):
|
|
|
+ monkeypatch.delenv('BORG_REPO', raising=False)
|
|
|
+ assert repr(Location('path::archive')) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='path', archive='archive')"
|
|
|
+ assert repr(Location('path')) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='path', archive=None)"
|
|
|
+
|
|
|
+ def test_abspath(self, monkeypatch):
|
|
|
+ monkeypatch.delenv('BORG_REPO', raising=False)
|
|
|
+ assert repr(Location('/some/absolute/path::archive')) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='/some/absolute/path', archive='archive')"
|
|
|
+ assert repr(Location('/some/absolute/path')) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='/some/absolute/path', archive=None)"
|
|
|
+
|
|
|
+ def test_relpath(self, monkeypatch):
|
|
|
+ monkeypatch.delenv('BORG_REPO', raising=False)
|
|
|
+ assert repr(Location('some/relative/path::archive')) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='some/relative/path', archive='archive')"
|
|
|
+ assert repr(Location('some/relative/path')) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='some/relative/path', archive=None)"
|
|
|
+
|
|
|
+ def test_underspecified(self, monkeypatch):
|
|
|
+ monkeypatch.delenv('BORG_REPO', raising=False)
|
|
|
+ with pytest.raises(ValueError):
|
|
|
+ Location('::archive')
|
|
|
+ with pytest.raises(ValueError):
|
|
|
+ Location('::')
|
|
|
+ with pytest.raises(ValueError):
|
|
|
+ Location()
|
|
|
+
|
|
|
+ def test_no_double_colon(self, monkeypatch):
|
|
|
+ monkeypatch.delenv('BORG_REPO', raising=False)
|
|
|
+ with pytest.raises(ValueError):
|
|
|
+ Location('ssh://localhost:22/path:archive')
|
|
|
+
|
|
|
+ def test_canonical_path(self, monkeypatch):
|
|
|
+ monkeypatch.delenv('BORG_REPO', raising=False)
|
|
|
locations = ['some/path::archive', 'file://some/path::archive', 'host:some/path::archive',
|
|
|
'host:~user/some/path::archive', 'ssh://host/some/path::archive',
|
|
|
'ssh://user@host:1234/some/path::archive']
|
|
|
for location in locations:
|
|
|
- self.assert_equal(Location(location).canonical_path(),
|
|
|
- Location(Location(location).canonical_path()).canonical_path())
|
|
|
+ assert Location(location).canonical_path() == \
|
|
|
+ Location(Location(location).canonical_path()).canonical_path()
|
|
|
+
|
|
|
+
|
|
|
+class TestLocationWithEnv:
|
|
|
+ def test_ssh(self, monkeypatch):
|
|
|
+ monkeypatch.setenv('BORG_REPO', 'ssh://user@host:1234/some/path')
|
|
|
+ assert repr(Location('::archive')) == \
|
|
|
+ "Location(proto='ssh', user='user', host='host', port=1234, path='/some/path', archive='archive')"
|
|
|
+ assert repr(Location()) == \
|
|
|
+ "Location(proto='ssh', user='user', host='host', port=1234, path='/some/path', archive=None)"
|
|
|
+
|
|
|
+ def test_file(self, monkeypatch):
|
|
|
+ monkeypatch.setenv('BORG_REPO', 'file:///some/path')
|
|
|
+ assert repr(Location('::archive')) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='/some/path', archive='archive')"
|
|
|
+ assert repr(Location()) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='/some/path', archive=None)"
|
|
|
+
|
|
|
+ def test_scp(self, monkeypatch):
|
|
|
+ monkeypatch.setenv('BORG_REPO', 'user@host:/some/path')
|
|
|
+ assert repr(Location('::archive')) == \
|
|
|
+ "Location(proto='ssh', user='user', host='host', port=None, path='/some/path', archive='archive')"
|
|
|
+ assert repr(Location()) == \
|
|
|
+ "Location(proto='ssh', user='user', host='host', port=None, path='/some/path', archive=None)"
|
|
|
+
|
|
|
+ def test_folder(self, monkeypatch):
|
|
|
+ monkeypatch.setenv('BORG_REPO', 'path')
|
|
|
+ assert repr(Location('::archive')) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='path', archive='archive')"
|
|
|
+ assert repr(Location()) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='path', archive=None)"
|
|
|
+
|
|
|
+ def test_abspath(self, monkeypatch):
|
|
|
+ monkeypatch.setenv('BORG_REPO', '/some/absolute/path')
|
|
|
+ assert repr(Location('::archive')) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='/some/absolute/path', archive='archive')"
|
|
|
+ assert repr(Location()) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='/some/absolute/path', archive=None)"
|
|
|
+
|
|
|
+ def test_relpath(self, monkeypatch):
|
|
|
+ monkeypatch.setenv('BORG_REPO', 'some/relative/path')
|
|
|
+ assert repr(Location('::archive')) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='some/relative/path', archive='archive')"
|
|
|
+ assert repr(Location()) == \
|
|
|
+ "Location(proto='file', user=None, host=None, port=None, path='some/relative/path', archive=None)"
|
|
|
|
|
|
|
|
|
class FormatTimedeltaTestCase(BaseTestCase):
|