From dd4fc36a9d268d4814116c2a9efec04146b9e1a9 Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Thu, 15 Feb 2018 18:02:00 +0100 Subject: [PATCH] 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. --- scripts/python/TerraSync/terrasync/main.py | 5 +++-- scripts/python/TerraSync/terrasync/virtual_path.py | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/python/TerraSync/terrasync/main.py b/scripts/python/TerraSync/terrasync/main.py index 0ed3c7ab4..0367963fb 100755 --- a/scripts/python/TerraSync/terrasync/main.py +++ b/scripts/python/TerraSync/terrasync/main.py @@ -134,7 +134,8 @@ class HTTPGetter: 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) def assembleUrl(self, httpGetCallback): @@ -631,7 +632,7 @@ class TerraSync: # 'reason' is a member of the FailedCheckReason enum 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}." .format(prg=PROGNAME, diff --git a/scripts/python/TerraSync/terrasync/virtual_path.py b/scripts/python/TerraSync/terrasync/virtual_path.py index 1df8e2f64..834c5a2b1 100644 --- a/scripts/python/TerraSync/terrasync/virtual_path.py +++ b/scripts/python/TerraSync/terrasync/virtual_path.py @@ -116,7 +116,7 @@ class VirtualPath: """Run consistency checks on self.""" assert (self._path.startswith('/') and not self._path.startswith('//') and (self._path == '/' or not self._path.endswith('/'))), \ - self._path + repr(self._path) @classmethod def normalizeStringPath(cls, path): @@ -155,7 +155,7 @@ class VirtualPath: 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 == '/': return type(self)(self._path + s) @@ -214,7 +214,7 @@ class VirtualPath: if self._path == '/': return - assert self._path.startswith('/') + assert self._path.startswith('/'), repr(self._path) prevPos = len(self._path) 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:] @@ -354,7 +354,7 @@ class MutableVirtualPath(VirtualPath): # This check could of course be skipped if it is found to really affect # performance. self._check() - assert not (s.startswith('/') or s.endswith('/')), s + assert not (s.startswith('/') or s.endswith('/')), repr(s) if self._path == '/': self._path += s