Skip to content

Commit eb2039d

Browse files
Merge pull request #72 from xenserver-next/accessor-pylint-remains
tests/test_accessor.py: Test File* and HTTPAccessor.openAddress(), fix pylint
2 parents 25bb3f4 + 7b2f85a commit eb2039d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

tests/test_accessor.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33
import xcp.accessor
44

55
class TestAccessor(unittest.TestCase):
6+
def setUp(self):
7+
"""Provide the refrence content of the repo/.treeinfo file for check_repo_access()"""
8+
with open("tests/data/repo/.treeinfo", "rb") as dot_treeinfo:
9+
self.reference_treeinfo = dot_treeinfo.read()
10+
611
def check_repo_access(self, a):
712
"""Common helper function for testing Accessor.access() with repo files"""
813
a.start()
14+
15+
treeinfo_file = a.openAddress('.treeinfo')
16+
assert not isinstance(treeinfo_file, bool) # check to not return False, pytype alerts on it
17+
assert treeinfo_file.read() == self.reference_treeinfo
18+
treeinfo_file.close()
19+
920
self.assertTrue(a.access('.treeinfo'))
1021
self.assertFalse(a.access('no_such_file'))
1122
self.assertEqual(a.lastError, 404)

xcp/accessor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def __init__(self, baseAddress, ro):
216216

217217
def openAddress(self, address):
218218
try:
219-
file = open(os.path.join(self.baseAddress, address), "rb")
219+
reader = open(os.path.join(self.baseAddress, address), "rb")
220220
except (IOError, OSError) as e:
221221
if e.errno == errno.EIO:
222222
self.lastError = 5
@@ -226,7 +226,7 @@ def openAddress(self, address):
226226
except Exception as e:
227227
self.lastError = 500
228228
return False
229-
return file
229+
return reader
230230

231231
def writeFile(self, in_fh, out_name):
232232
logger.info("Copying to %s" % os.path.join(self.baseAddress, out_name))
@@ -293,7 +293,7 @@ def finish(self):
293293
self.cleanup = False
294294
self.ftp = None
295295

296-
def access(self, path):
296+
def access(self, path): # pylint: disable=arguments-differ,arguments-renamed
297297
try:
298298
logger.debug("Testing "+path)
299299
self._cleanup()
@@ -377,7 +377,7 @@ def __repr__(self):
377377
'ftp': FTPAccessor,
378378
'file': FileAccessor,
379379
'dev': DeviceAccessor,
380-
}
380+
}
381381

382382
def createAccessor(baseAddress, *args):
383383
url_parts = urllib.parse.urlsplit(baseAddress, allow_fragments=False)

0 commit comments

Comments
 (0)