def test_sftp(self): SftpPath._check_dependencies = self.mocked_dependencies sftp_mock = MagicMock() sftp_mock.hostkeys.HostKeys().items.return_value = {'key': 'value'} self.deps.append(sftp_mock) with AnyPath('ssh://user@host:example') as path: self.assertTrue(path.parent.exists(), 'Path was not created')
def test_http(self): HttpPath._check_dependencies = self.mocked_dependencies req_mock = MagicMock() res_mock = MagicMock() res_mock.text = 'Content' req_mock.Session().send.return_value = res_mock self.deps.append(req_mock) with AnyPath('http://example.com') as path: content = path.read_text() self.assertEqual(content, 'Content', 'Content was not created')
def test_sftp_scheme(self): ap = AnyPath('sftp://root@test:/test') self.assertEqual(type(ap), SftpPath)
def test_https_schemes(self): ap = AnyPath('hg+https://test') self.assertEqual(type(ap), HgPath)
def test_relative_scheme(self): ap = AnyPath('./test') self.assertEqual(type(ap), LocalPath)
def test_absolute_scheme(self): ap = AnyPath('/test') self.assertEqual(type(ap), LocalPath)
def test_file_scheme(self): ap = AnyPath('file://test') self.assertEqual(type(ap), LocalPath)
def test_http_scheme(self): ap = AnyPath('http://test') self.assertEqual(type(ap), HttpPath)
def test_git_scheme(self): ap = AnyPath('git://test') self.assertEqual(type(ap), GitPath)
def test_https_scheme(self): ap = AnyPath('git+https://test') self.assertEqual(type(ap), GitPath)
def create(self): for local, remote in self.value.items(): ap = AnyPath(remote, self.parent.joinpath(local)) ap.fetch() ap.close()
from anypath.anypath import AnyPath, path_provider from anypath.pathprovider.git import GitPath from anypath.pathprovider.http import HttpPath path_provider.add(HttpPath, GitPath) path_provider.check_requirements() with AnyPath('http://example.org') as path: content = path.read_text() print(len(content)) with AnyPath('git+https://github.com/vaubarth/anypath.git') as path: content = path.glob('*') print(list(content))
def test_hg(self): HgPath._check_dependencies = self.mocked_dependencies with patch('subprocess.Popen'): with AnyPath('hg+http://asdas') as path: self.assertTrue(path.parent.exists(), 'Path was not created')
def test_local(self): with AnyPath('./resources/localfile.txt') as path: content = path.read_text() self.assertEqual(content, 'Content', 'Content was not created')