TST: add tests of shorthand parsing for all timeUnits and aggregates
import pandas as pd
+import altair as alt
from .. import parse_shorthand, update_nested
@@ -66,6 +67,28 @@ def test_parse_shorthand_with_data():
check('month(z)', data, timeUnit='month', field='z', type='temporal')
+def test_parse_shorthand_all_aggregates():
+ aggregates = alt.Root._schema['definitions']['AggregateOp']['enum']
+ for aggregate in aggregates:
+ shorthand = "{aggregate}(field):Q".format(aggregate=aggregate)
+ assert parse_shorthand(shorthand) == {'aggregate': aggregate,
+ 'field': 'field',
+ 'type': 'quantitative'}
+
+
+def test_parse_shorthand_all_timeunits():
+ timeUnits = []
+ for loc in ['Local', 'Utc']:
+ for typ in ['Single', 'Multi']:
+ defn = loc + typ + 'TimeUnit'
+ timeUnits.extend(alt.Root._schema['definitions'][defn]['enum'])
+ for timeUnit in timeUnits:
+ shorthand = "{timeUnit}(field):Q".format(timeUnit=timeUnit)
+ assert parse_shorthand(shorthand) == {'timeUnit': timeUnit,
+ 'field': 'field',
+ 'type': 'quantitative'}
+
+
def test_update_nested():
original = {'x': {'b': {'foo': 2}, 'c': 4}}
update = {'x': {'b': {'foo': 5}, 'd': 6}, 'y': 40}
