Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsalmon committed Apr 2, 2013
1 parent bf83ffa commit fe989c3
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 72 deletions.
10 changes: 5 additions & 5 deletions tests/functional/test_client.py
@@ -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')")


8 changes: 8 additions & 0 deletions tests/functional/test_copy.py
@@ -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()
106 changes: 54 additions & 52 deletions tests/functional/test_file.py
@@ -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()
30 changes: 15 additions & 15 deletions tests/functional/test_filesystem.py
Expand Up @@ -3,12 +3,12 @@
from XRootD.enums import OpenFlags, QueryCode, MkDirFlags, AccessMode, \
DirListFlags, PrepareFlags
import pytest

def test_filesystem():
c = client.Client("root://localhost")

funcspecs = [(c.locate, ('/tmp', OpenFlags.REFRESH), True),
(c.deeplocate, ('/tmp', OpenFlags.REFRESH), True),
funcspecs = [#(c.locate, ('/tmp', OpenFlags.REFRESH), True),
#(c.deeplocate, ('/tmp', OpenFlags.REFRESH), True),
(c.query, (QueryCode.SPACE, '/tmp'), True),
(c.truncate, ('/tmp/spam', 1000), False),
(c.mv, ('/tmp/spam', '/tmp/ham'), False),
Expand All @@ -24,45 +24,45 @@ def test_filesystem():
(c.sendinfo, ('important info',), False),
(c.prepare, (['/tmp/foo'], PrepareFlags.STAGE), True),
]

for func, args, hasReturnObject in funcspecs:
sync (func, args, hasReturnObject)

# Create new temp file
f = client.File()
status, response = f.open('root://localhost//tmp/spam', OpenFlags.NEW)

for func, args, hasReturnObject in funcspecs:
async(func, args, hasReturnObject)

def sync(func, args, hasReturnObject):
status, response = func(*args)
print status
assert status.ok
if hasReturnObject:
print response
assert response

def async(func, args, hasReturnObject):
status = func(callback=callback, *args)
handler = AsyncResponseHandler()
status = func(callback=handler, *args)
print status
assert status.ok
#handler.waitFor()
status, response, hostlist = handler.waitFor()
#assert 0

def callback(status, response, hostlist):

assert status.ok
if response:
print response
assert response
#assert hostList

def test_args():
c = client.Client("root://localhost")
status, response = c.locate(path="/tmp", flags=0, timeout=1)
assert status
assert response

pytest.raises(TypeError, 'c.locate(path="/tmp")')
pytest.raises(TypeError, 'c.locate(path="/tmp", foo=1)')
pytest.raises(TypeError, 'c.locate(foo="/tmp")')
Expand Down

0 comments on commit fe989c3

Please sign in to comment.