1
0
Fork 0

terrasync.py: make assert statements more useful

When the second argument of an assert statement is a string, using
repr() is more helpful than relying on the default representation.
This commit is contained in:
Florent Rougon 2018-02-15 18:02:00 +01:00
parent 48563acdd2
commit dd4fc36a9d
2 changed files with 8 additions and 7 deletions

View file

@ -134,7 +134,8 @@ class HTTPGetter:
Example: '/scenery/Airports/N/E/4/.dirindex' Example: '/scenery/Airports/N/E/4/.dirindex'
""" """
assert not self.parsedBaseUrl.path.endswith('/'), self.parsedBaseUrl assert not self.parsedBaseUrl.path.endswith('/'), \
repr(self.parsedBaseUrl)
return self.parsedBaseUrl.path + str(httpGetCallback.src) return self.parsedBaseUrl.path + str(httpGetCallback.src)
def assembleUrl(self, httpGetCallback): def assembleUrl(self, httpGetCallback):
@ -631,7 +632,7 @@ class TerraSync:
# 'reason' is a member of the FailedCheckReason enum # 'reason' is a member of the FailedCheckReason enum
def abortCheckMode(self, reason, fileOrDirVirtualPath): def abortCheckMode(self, reason, fileOrDirVirtualPath):
assert self.mode == self.Mode.check, self.mode assert self.mode == self.Mode.check, repr(self.mode)
print("{prg}: exiting from 'check' mode because {explanation}." print("{prg}: exiting from 'check' mode because {explanation}."
.format(prg=PROGNAME, .format(prg=PROGNAME,

View file

@ -116,7 +116,7 @@ class VirtualPath:
"""Run consistency checks on self.""" """Run consistency checks on self."""
assert (self._path.startswith('/') and not self._path.startswith('//') assert (self._path.startswith('/') and not self._path.startswith('//')
and (self._path == '/' or not self._path.endswith('/'))), \ and (self._path == '/' or not self._path.endswith('/'))), \
self._path repr(self._path)
@classmethod @classmethod
def normalizeStringPath(cls, path): def normalizeStringPath(cls, path):
@ -155,7 +155,7 @@ class VirtualPath:
Return a new instance of type(self). Return a new instance of type(self).
""" """
assert not (s.startswith('/') or s.endswith('/')), s assert not (s.startswith('/') or s.endswith('/')), repr(s)
if self._path == '/': if self._path == '/':
return type(self)(self._path + s) return type(self)(self._path + s)
@ -214,7 +214,7 @@ class VirtualPath:
if self._path == '/': if self._path == '/':
return return
assert self._path.startswith('/') assert self._path.startswith('/'), repr(self._path)
prevPos = len(self._path) prevPos = len(self._path)
while True: while True:
@ -324,7 +324,7 @@ class VirtualPath:
'' ''
""" """
assert self._path.startswith('/'), self._path assert self._path.startswith('/'), repr(self._path)
return self._path[1:] return self._path[1:]
@ -354,7 +354,7 @@ class MutableVirtualPath(VirtualPath):
# This check could of course be skipped if it is found to really affect # This check could of course be skipped if it is found to really affect
# performance. # performance.
self._check() self._check()
assert not (s.startswith('/') or s.endswith('/')), s assert not (s.startswith('/') or s.endswith('/')), repr(s)
if self._path == '/': if self._path == '/':
self._path += s self._path += s