From 447c7762b8794ef7876853ee69b8645b77f10f85 Mon Sep 17 00:00:00 2001 From: Fred Wright Date: Sat, 18 Feb 2017 23:55:52 -0800 Subject: Reworks local exception definitions in fake.py. This reduces duplicated code by using subclasses for local exceptions. It's not entirely clear that limiting __str__() to only certain exceptions is necessary, but it preserves that behavior. TESTED: Ran "scons build-all check" on several platforms. --- gps/fake.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'gps/fake.py') diff --git a/gps/fake.py b/gps/fake.py index 6d2a5742..08923d5e 100644 --- a/gps/fake.py +++ b/gps/fake.py @@ -123,12 +123,16 @@ def GetDelay(slow=False): return delay -class TestLoadError(BaseException): +class TestError(BaseException): def __init__(self, msg): - super(TestLoadError, self).__init__() + super(TestError, self).__init__() self.msg = msg +class TestLoadError(TestError): + pass + + class TestLoad(object): "Digest a logfile into a list of sentences we can cycle through." @@ -219,10 +223,8 @@ class TestLoad(object): self.sentences.append(b"# EOF\n") -class PacketError(BaseException): - def __init__(self, msg): - super(PacketError, self).__init__() - self.msg = msg +class PacketError(TestError): + pass class FakeGPS(object): @@ -431,11 +433,7 @@ class FakeUDP(FakeGPS): pass # shutdown() fails on UDP -class SubprogramError(BaseException): - def __init__(self, msg): - super(SubprogramError, self).__init__() - self.msg = msg - +class SubprogramError(TestError): def __str__(self): return repr(self.msg) @@ -562,10 +560,8 @@ class DaemonInstance(SubprogramInstance): self.sock.close() -class TestSessionError(BaseException): - def __init__(self, msg): - super(TestSessionError, self).__init__() - self.msg = msg +class TestSessionError(TestError): + pass class TestSession(object): -- cgit v1.2.1