Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_transform_getter_and_setter():
page = Page()
c = page.new_chart()
assert isinstance(c.transformer, chart.NoOpTransformer)
c.transformer = '1to2'
assert isinstance(c.transformer, chart.DictLevelsTransformer)
c.transformer = 'numbers'
assert isinstance(c.transformer, chart.NumberSequenceTransformer)
numbers = chart.NumberSequenceTransformer()
c.transformer = numbers
assert c.transformer is numbers
c.transformer = {'type': 'flat', 'chart_mapping': [], 'series_mapping': [], 'value_key': ''}
assert isinstance(c.transformer, chart.FlatDictTransformer)
def test_numbers_transformer():
numbers = chart.NumberSequenceTransformer()
transform = numbers.transform([1, 2.0])
assert transform == {
'': {
'series': [
{'data': [(0, 1), (0, 2)], 'name': 1}
],
'title': '',
'type': 'line'
}
}
transform = numbers.transform([[1, 2, 3], [4, 5, 6]])
assert transform == {
'': {
'series': [
{'data': [(0, 1), (0, 4)], 'name': 1},
{'data': [(0, 2), (0, 5)], 'name': 2},
def test_numbers_transformer_timed_tuples():
ts = 1000.12
expected_ts = int(ts * 1000)
numbers = chart.NumberSequenceTransformer()
for ds in [list, tuple]:
transform = numbers.transform([ds((ts, 1234))])
assert transform == {
'': {'series': [{'data': [(expected_ts, 1234)], 'name': 1}], 'title': '', 'type': 'line'}
}