|
| 1 | +import pytest |
| 2 | + |
| 3 | +from paths_cli.compiling._gendocs.json_type_handlers import * |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.parametrize('json_type', ['object', 'foo']) |
| 7 | +def test_handle_object(json_type): |
| 8 | + # object should convert to dict; anything else should be is-identical |
| 9 | + if json_type == "foo": |
| 10 | + json_type = {'foo': 'bar'} # make the `is` test meaningful |
| 11 | + result = handle_object(json_type) |
| 12 | + if json_type == 'object': |
| 13 | + assert result == 'dict' |
| 14 | + else: |
| 15 | + assert result is json_type |
| 16 | + |
| 17 | + |
| 18 | +def test_handle_listof(): |
| 19 | + json_type = {'type': "array", "items": "float"} |
| 20 | + assert handle_listof(json_type) == "list of float" |
| 21 | + |
| 22 | + |
| 23 | +def test_category_handler(): |
| 24 | + json_type = {"$ref": "#/definitions/engine_type"} |
| 25 | + handler = CategoryHandler('engine') |
| 26 | + assert handler(json_type) == ":ref:`engine <compiling--engine>`" |
| 27 | + |
| 28 | + |
| 29 | +def test_eval_handler(): |
| 30 | + json_type = {"$ref": "#/definitions/EvalInt"} |
| 31 | + handler = EvalHandler("EvalInt", link_to="EvalInt") |
| 32 | + assert handler(json_type) == ":ref:`EvalInt <EvalInt>`" |
| 33 | + |
| 34 | + |
| 35 | +@pytest.mark.parametrize('json_type', ['string', 'float', 'list-float', |
| 36 | + 'engine', 'list-engine']) |
| 37 | +def test_json_type_to_string(json_type): |
| 38 | + # integration tests for json_type_to_string |
| 39 | + inputs, expected = { |
| 40 | + 'string': ("string", "string"), |
| 41 | + 'float': ("float", "float"), |
| 42 | + 'list-float': ({'type': 'array', 'items': 'float'}, |
| 43 | + "list of float"), |
| 44 | + 'engine': ({"$ref": "#/definitions/engine_type"}, |
| 45 | + ":ref:`engine <compiling--engine>`"), |
| 46 | + 'list-engine': ({"type": "array", |
| 47 | + "items": {"$ref": "#/definitions/engine_type"}}, |
| 48 | + "list of :ref:`engine <compiling--engine>`"), |
| 49 | + }[json_type] |
| 50 | + assert json_type_to_string(inputs) == expected |
0 commit comments