Ejemplo n.º 1
0
def test_comparable_parsing():
    dumper = ASTDumper()

    json_src = """{
    "a" : 1,
    "b" : [ 
      2,
      3,
    ],
    "c" : {
      "i1" : true,
      "i2" : "a",
      "i3" : null
    }
  }"""

    json_ast = json.loads(json_src)
    json_txt = dumper.dump(json_ast)

    yaml_src = """
  a : 1
  b :
    - 2
    - 3

  c :
    i1 : true
    i2 : "a"
    i3 : null
  """

    yaml_ast = yaml.loads(yaml_src)
    yaml_txt = dumper.dump(yaml_ast)

    assert (json_ast == yaml_ast)
Ejemplo n.º 2
0
def test_parse_dates():
    src = """
something:
  example: 2021-01-01
"""

    ast = yaml.loads(src)
    assert isinstance(ast["something"]["example"], ValueNode)
Ejemplo n.º 3
0
def test_allow_for_empty_properties():
  # empty properties shouldn't fail building object schema from AST
  ast = yaml.loads("""
  something:
    type: object
    properties:  
  """)
  schema = build(ast)
  assert len(schema.something.properties) == 0
Ejemplo n.º 4
0
def test_allow_for_no_items():
  # empty properties shouldn't fail building object schema from AST
  ast = yaml.loads("""
  something:
    type: array
  """)
  schema = build(ast)
  assert isinstance(schema.something.items, list)
  assert len(schema.something.items) == 0
Ejemplo n.º 5
0
def test_allow_for_tuple_items():
  # tuple properties shouldn't fail building object schema from AST
  ast = yaml.loads("""
  something:
    type: array
    items:
      - type: integer
      - type: string
  """)
  schema = build(ast)
  assert isinstance(schema.something.items, list)
  assert len(schema.something.items) == 2
  assert isinstance(schema.something.items[0], TupleItem)
  assert isinstance(schema.something.items[0].definition, IntegerSchema)
  assert isinstance(schema.something.items[1].definition, StringSchema)