Changeset - d0f5f1547ced
[Not reviewed]
0 3 0
Brett Smith - 7 years ago 2017-06-29 21:18:47
brettcsmith@brettcsmith.org
config: Error out when historical arguments are ambiguous.
3 files changed with 25 insertions and 2 deletions:
0 comments (0 inline, 0 general)
oxrlib/config.py
Show inline comments
...
 
@@ -8,2 +8,3 @@ import pathlib
 
import babel
 
import babel.dates
 
import babel.numbers
...
 
@@ -76,3 +77,3 @@ class Configuration:
 
                retval = retval.replace(**replacements)
 
        return retval
 
        return retval, replacements
 

	
...
 
@@ -193,2 +194,3 @@ class Configuration:
 
    def _post_hook_historical(self):
 
        self.args.date, date_spec = self.args.date
 
        year = self.args.date.year
...
 
@@ -225,2 +227,14 @@ class Configuration:
 
            self.args.to_currency = pref_currency
 
        if ((len(date_spec) == 1)
 
            and self.args.from_currency
 
            and (self.args.amount is None)):
 
            self.error(("ambiguous input: "
 
                        "Did you want rates for {args.from_currency} on {date}, "
 
                        "or to convert {amt} {args.from_currency} to {args.to_currency}?\n"
 
                        "Specify more of the date to disambiguate."
 
                        ).format(
 
                            args=self.args,
 
                            date=babel.dates.format_date(self.args.date),
 
                            amt=date_spec['day'],
 
                        ))
 

	
setup.py
Show inline comments
...
 
@@ -7,3 +7,3 @@ setup(
 
    description="Library to query the Open Exchange Rates (OXR) API",
 
    version='1.6',
 
    version='1.7',
 
    author='Brett Smith',
tests/test_Configuration.py
Show inline comments
...
 
@@ -130 +130,10 @@ def test_bad_date_parsing(date_s):
 
        assert not config.args.date, "date parsed from {!r}".format(date_s)
 

	
 
def test_ambiguous_arglist_failure():
 
    try:
 
        # It's ambiguous if "2" is "the 2nd" or "2 EUR".
 
        config = config_from(os.devnull, ['historical', '2', 'eur'])
 
    except SystemExit:
 
        pass
 
    else:
 
        assert not config.args, "ambiguous args parsed"
0 comments (0 inline, 0 general)