Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
from XRootD import client | ||
import pytest | ||
|
||
def test_valid_url(): | ||
c = client.Client('root://localhost') | ||
assert c.url.is_valid() | ||
|
||
def test_invalid_url(): | ||
c = client.Client('root://') | ||
print c.url | ||
assert c.url.is_valid() == False | ||
|
||
def test_args(): | ||
c = client.Client(url='root://localhost') | ||
assert c | ||
|
||
pytest.raises(TypeError, "c = client.Client(foo='root://localhost')") | ||
|
||
pytest.raises(TypeError, "c = client.Client(path='root://localhost', foo='bar')") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# from XRootD import client | ||
# | ||
# def test_copy(): | ||
# c = client.CopyProcess() | ||
# c.add_job( client.CopyJob( source='root://localhost//tmp/spam', | ||
# target='root://localhost//tmp/eggs' )) | ||
# c.prepare() | ||
# c.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,131 +1,133 @@ | ||
from XRootD import client | ||
from XRootD.client import AsyncResponseHandler | ||
from XRootD.enums import OpenFlags | ||
|
||
import pytest | ||
import sys | ||
|
||
def test_write(): | ||
f = client.File() | ||
buffer = 'eggs and ham\n' | ||
|
||
pytest.raises(ValueError, "f.write(buffer)") | ||
|
||
status, response = f.open('root://localhost//tmp/spam', OpenFlags.DELETE) | ||
assert status.ok | ||
|
||
status, response = f.write(buffer) | ||
assert status.ok | ||
|
||
status, response = f.read() | ||
assert status.ok | ||
assert len(response) == len(buffer) | ||
|
||
# Test write offsets and sizes | ||
f.close() | ||
|
||
def test_read(): | ||
f = client.File() | ||
pytest.raises(ValueError, 'f.read()') | ||
|
||
status, response = f.open('root://localhost//tmp/spam', OpenFlags.READ) | ||
assert status.ok | ||
|
||
status, response = f.read() | ||
|
||
status, response = f.open('root://localhost//tmp/bigfile', OpenFlags.READ) | ||
assert status.ok | ||
|
||
assert response | ||
|
||
|
||
status, response = f.stat(timeout=5) | ||
size = response.size | ||
|
||
# status, response = f.read() | ||
# assert status.ok | ||
# assert len(response) == size | ||
|
||
f.readline(offset=0, size=1024) | ||
f.close() | ||
assert 0 # TODO add readline() params | ||
|
||
# Test read offsets and sizes | ||
f.close() | ||
|
||
def test_vector_read(): | ||
v = [(0, 100), (101, 200), (201, 200)] | ||
|
||
f = client.File() | ||
pytest.raises(ValueError, 'f.vector_read(v)') | ||
|
||
status, response = f.open('root://localhost//tmp/spam', OpenFlags.READ) | ||
assert status.ok | ||
status, response = f.vector_read(chunks=v) | ||
assert status.ok == False | ||
assert not response | ||
f.close() | ||
|
||
f = client.File() | ||
status, response = f.open('root://localhost//tmp/xrootd.tgz', OpenFlags.READ) | ||
status, response = f.open('root://localhost//tmp/bigfile', OpenFlags.READ) | ||
print status | ||
assert status.ok | ||
status, response = f.vector_read(chunks=v) | ||
assert status.ok | ||
assert response | ||
f.close() | ||
|
||
def test_stat(): | ||
f = client.File() | ||
|
||
pytest.raises(ValueError, 'f.stat()') | ||
|
||
|
||
status, response = f.open('root://localhost//tmp/spam') | ||
assert status.ok | ||
|
||
status, response = f.stat() | ||
assert status.ok | ||
assert response.size | ||
# pytest.raises(ValueError, 'f.stat()') | ||
# | ||
# | ||
# status, response = f.open('root://localhost//tmp/spam') | ||
# assert status.ok | ||
# | ||
# status, response = f.stat() | ||
# assert status.ok | ||
# assert response.size | ||
f.close() | ||
|
||
def test_sync(): | ||
f = client.File() | ||
|
||
pytest.raises(ValueError, 'f.sync()') | ||
|
||
status, response = f.open('root://localhost//tmp/spam') | ||
assert status.ok | ||
|
||
status, response = f.sync() | ||
assert status.ok | ||
f.close() | ||
|
||
def test_truncate(): | ||
f = client.File() | ||
|
||
pytest.raises(ValueError, 'f.truncate(10000)') | ||
|
||
status, response = f.open('root://localhost//tmp/spam', OpenFlags.UPDATE) | ||
assert status.ok | ||
|
||
status, response = f.truncate(size=10000) | ||
print status | ||
assert status.ok | ||
f.close() | ||
|
||
def test_misc(): | ||
f = client.File() | ||
assert not f.is_open() | ||
|
||
status, response = f.open('root://localhost//tmp/spam', OpenFlags.READ) | ||
assert status.ok | ||
assert f.is_open() | ||
|
||
pytest.raises(TypeError, "f.enable_read_recovery(enable='foo')") | ||
|
||
|
||
f.enable_read_recovery(enable=True) | ||
|
||
pytest.raises(TypeError, "f.enable_write_recovery(enable='foo')") | ||
|
||
f.enable_write_recovery(enable=True) | ||
|
||
assert f.get_data_server() | ||
|
||
pytest.raises(TypeError, 'f.get_data_server("invalid_arg")') | ||
|
||
|
||
# testing context manager | ||
f.close() | ||
assert not f.is_open() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters