diff options
author | Fred Wright <fw@fwright.net> | 2017-02-18 23:55:52 -0800 |
---|---|---|
committer | Fred Wright <fw@fwright.net> | 2017-02-19 00:23:55 -0800 |
commit | 447c7762b8794ef7876853ee69b8645b77f10f85 (patch) | |
tree | 927323ba0a4acc2ae4d41a8288d4e77980ed58f8 /gps/fake.py | |
parent | 8cb5632098d97b055bfb214dd5fce2985fc4ef89 (diff) | |
download | gpsd-447c7762b8794ef7876853ee69b8645b77f10f85.tar.gz |
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.
Diffstat (limited to 'gps/fake.py')
-rw-r--r-- | gps/fake.py | 26 |
1 files changed, 11 insertions, 15 deletions
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): |