def test_selector_precedence3() -> None: unit = parse_buffer( "X'Head.B", rule=librflxlang.GrammarRule.extended_expression_rule, ) assert len(unit.diagnostics) == 0, "\n".join( str(d) for d in unit.diagnostics) assert to_dict(unit.root) == { "_kind": "SelectNode", "expression": { "_kind": "Attribute", "expression": { "_kind": "Variable", "identifier": { "_kind": "ID", "name": { "_kind": "UnqualifiedID", "_value": "X" }, "package": None, }, }, "kind": { "_kind": "AttrHead", "_value": "Head" }, }, "selector": { "_kind": "UnqualifiedID", "_value": "B" }, }
def test_modular_type() -> None: unit = parse_buffer( """ type Modular_Type is mod 2 ** 9; """, rule=librflxlang.GrammarRule.type_declaration_rule, ) assert to_dict(unit.root) == { "_kind": "TypeDecl", "definition": { "_kind": "ModularTypeDef", "mod": { "_kind": "BinOp", "left": { "_kind": "NumericLiteral", "_value": "2" }, "op": { "_kind": "OpPow", "_value": "**" }, "right": { "_kind": "NumericLiteral", "_value": "9" }, }, }, "identifier": { "_kind": "UnqualifiedID", "_value": "Modular_Type" }, "parameters": None, }
def test_kown_version_status(app, monkeypatch): """if TARTARE_VERSION is given at startup, a version is available""" version = 'v1.42.12' monkeypatch.setitem(os.environ, 'TARTARE_VERSION', version) raw = app.get('/status') r = to_dict(raw) assert raw.status_code == 200 assert r.get('version') == version
def test_checksum_attributes() -> None: unit = parse_buffer( """ A'Valid_Checksum and B'Valid_Checksum; """, rule=librflxlang.GrammarRule.expression_rule, ) assert to_dict(unit.root) == { "_kind": "BinOp", "left": { "_kind": "Attribute", "expression": { "_kind": "Variable", "identifier": { "_kind": "ID", "name": { "_kind": "UnqualifiedID", "_value": "A" }, "package": None, }, }, "kind": { "_kind": "AttrValidChecksum", "_value": "Valid_Checksum" }, }, "op": { "_kind": "OpAnd", "_value": "and" }, "right": { "_kind": "Attribute", "expression": { "_kind": "Variable", "identifier": { "_kind": "ID", "name": { "_kind": "UnqualifiedID", "_value": "B" }, "package": None, }, }, "kind": { "_kind": "AttrValidChecksum", "_value": "Valid_Checksum" }, }, }
def test_negative_number() -> None: unit = parse_buffer( """ -16#20_000# """, rule=librflxlang.GrammarRule.expression_rule, ) assert len(unit.diagnostics) == 0, "\n".join( str(d) for d in unit.diagnostics) assert to_dict(unit.root) == { "_kind": "Negation", "data": { "_kind": "NumericLiteral", "_value": "16#20_000#" }, }
def test_selector_precedence1() -> None: unit = parse_buffer( "X.B = Z", rule=librflxlang.GrammarRule.extended_expression_rule, ) assert len(unit.diagnostics) == 0, "\n".join( str(d) for d in unit.diagnostics) assert to_dict(unit.root) == { "_kind": "BinOp", "left": { "_kind": "SelectNode", "expression": { "_kind": "Variable", "identifier": { "_kind": "ID", "name": { "_kind": "UnqualifiedID", "_value": "X" }, "package": None, }, }, "selector": { "_kind": "UnqualifiedID", "_value": "B", }, }, "op": { "_kind": "OpEq", "_value": "=" }, "right": { "_kind": "Variable", "identifier": { "_kind": "ID", "name": { "_kind": "UnqualifiedID", "_value": "Z" }, "package": None, }, }, }
def test_empty_package() -> None: unit = parse_buffer( """ package Empty_Package is end Empty_Package; """, ) assert to_dict(unit.root) == { "context_clause": [], "_kind": "Specification", "package_declaration": { "declarations": [], "end_identifier": { "_kind": "UnqualifiedID", "_value": "Empty_Package" }, "identifier": { "_kind": "UnqualifiedID", "_value": "Empty_Package" }, "_kind": "PackageNode", }, }
def test_suffix_precedence() -> None: unit = parse_buffer( "2**X'Size", rule=librflxlang.GrammarRule.extended_expression_rule, ) assert len(unit.diagnostics) == 0, "\n".join( str(d) for d in unit.diagnostics) assert to_dict(unit.root) == { "_kind": "BinOp", "left": { "_kind": "NumericLiteral", "_value": "2" }, "op": { "_kind": "OpPow", "_value": "**" }, "right": { "_kind": "Attribute", "expression": { "_kind": "Variable", "identifier": { "_kind": "ID", "name": { "_kind": "UnqualifiedID", "_value": "X" }, "package": None, }, }, "kind": { "_kind": "AttrSize", "_value": "Size" }, }, }
def data_source(app, contributor): contributor['data_sources'] = [ { "id": "ds_test", "name": "bobette", "data_format": "gtfs", "input": { "type": "auto", "url": "http://stif.com/od.zip", "frequency": { "type": "daily", "hour_of_day": 20 } } } ] contributors = app.put('/contributors/{}'.format(contributor.get('id')), headers={'Content-Type': 'application/json'}, data=to_json(contributor)) ds = to_dict(contributors)['contributors'][0]['data_sources'][0] calculated_fields = ['status', 'updated_at', 'fetch_started_at'] for calculated_field in calculated_fields: ds.pop(calculated_field, None) return ds
def test_index(app): response = app.get('/') assert response.status_code == 200 r = to_dict(response) assert '_links' in r
def test_unkown_version_status(app): raw = app.get('/status') r = to_dict(raw) assert raw.status_code == 200 assert r.get('version') == 'unknown_version'
def test_operator_precedence() -> None: unit = parse_buffer( """ A / 8 >= 46 and A / 8 <= 1500 """, rule=librflxlang.GrammarRule.expression_rule, ) assert to_dict(unit.root) == { "_kind": "BinOp", "left": { "_kind": "BinOp", "left": { "_kind": "BinOp", "left": { "identifier": { "_kind": "ID", "name": { "_kind": "UnqualifiedID", "_value": "A" }, "package": None, }, "_kind": "Variable", }, "op": { "_kind": "OpDiv", "_value": "/" }, "right": { "_kind": "NumericLiteral", "_value": "8" }, }, "op": { "_kind": "OpGe", "_value": ">=" }, "right": { "_kind": "NumericLiteral", "_value": "46" }, }, "op": { "_kind": "OpAnd", "_value": "and" }, "right": { "_kind": "BinOp", "left": { "_kind": "BinOp", "left": { "identifier": { "_kind": "ID", "name": { "_kind": "UnqualifiedID", "_value": "A" }, "package": None, }, "_kind": "Variable", }, "op": { "_kind": "OpDiv", "_value": "/" }, "right": { "_kind": "NumericLiteral", "_value": "8" }, }, "op": { "_kind": "OpLe", "_value": "<=" }, "right": { "_kind": "NumericLiteral", "_value": "1500" }, }, }
def contributor(app): contributor = app.post('/contributors', headers={'Content-Type': 'application/json'}, data='{"id": "id_test", "name": "name_test", "data_prefix": "AAA"}') return to_dict(contributor)['contributors'][0]
def coverage(app): coverage = app.post('/coverages', headers={'Content-Type': 'application/json'}, data='{"id": "jdr", "name": "name of the coverage jdr"}') return to_dict(coverage)['coverages'][0]
def coverage_with_data_source_tram_lyon(app): coverage = app.post('/coverages', headers={'Content-Type': 'application/json'}, data='{"id": "jdr", "name": "name of the coverage jdr", "data_sources": ["tram_lyon"]}') return to_dict(coverage)['coverages'][0]