diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-02-16 10:58:34 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-02-16 10:58:34 +0000 |
commit | 8260972771458e9baa146a257751fa4027d6c5c6 (patch) | |
tree | 1d6708eeab13614415a2d870042bb11c17e46525 | |
parent | 7f2b5aa7891902f9731fba9df04c1e20e9e1aab1 (diff) | |
download | obnam-8260972771458e9baa146a257751fa4027d6c5c6.tar.gz |
Convert UnitError to StructuredError
-rw-r--r-- | obnamlib/sizeparse.py | 17 | ||||
-rw-r--r-- | obnamlib/sizeparse_tests.py | 4 | ||||
-rw-r--r-- | test-gpghome/random_seed | bin | 600 -> 600 bytes |
3 files changed, 9 insertions, 12 deletions
diff --git a/obnamlib/sizeparse.py b/obnamlib/sizeparse.py index 479ce2e1..3fed6a73 100644 --- a/obnamlib/sizeparse.py +++ b/obnamlib/sizeparse.py @@ -19,22 +19,19 @@ import re import obnamlib -class UnitError(obnamlib.Error): +class UnitError(obnamlib.ObnamError): - def __str__(self): - return self.msg + pass class SizeSyntaxError(UnitError): - def __init__(self, string): - self.msg = '"%s" is not a valid size' % string + msg = '"{size}" is not a valid size' class UnitNameError(UnitError): - def __init__(self, string): - self.msg = '"%s" is not a valid unit' % string + msg = '"{unit}" is not a valid unit' class ByteSizeParser(object): @@ -62,19 +59,19 @@ class ByteSizeParser(object): def set_default_unit(self, unit): if unit.lower() not in self.units: - raise UnitNameError(unit) + raise UnitNameError(size=unit) self.default_unit = unit def parse(self, string): m = self.pat.match(string) if not m: - raise SizeSyntaxError(string) + raise SizeSyntaxError(size=string) size = float(m.group('size')) unit = m.group('unit') if not unit: unit = self.default_unit elif unit.lower() not in self.units: - raise UnitNameError(unit) + raise UnitNameError(unit=unit) factor = self.units[unit.lower()] return int(size * factor) diff --git a/obnamlib/sizeparse_tests.py b/obnamlib/sizeparse_tests.py index 07ae5775..3a4dce8f 100644 --- a/obnamlib/sizeparse_tests.py +++ b/obnamlib/sizeparse_tests.py @@ -85,11 +85,11 @@ class ByteSizeParserTests(unittest.TestCase): def test_size_syntax_error_includes_input_string(self): text = 'asdf asdf' - e = obnamlib.SizeSyntaxError(text) + e = obnamlib.SizeSyntaxError(size=text) self.assert_(text in str(e), str(e)) def test_unit_name_error_includes_input_string(self): text = 'asdf asdf' - e = obnamlib.UnitNameError(text) + e = obnamlib.UnitNameError(unit=text) self.assert_(text in str(e), str(e)) diff --git a/test-gpghome/random_seed b/test-gpghome/random_seed Binary files differindex b237a51a..85661e53 100644 --- a/test-gpghome/random_seed +++ b/test-gpghome/random_seed |