Skip to content

Commit

Permalink
tests: Add variant type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnar-mb committed Dec 10, 2024
1 parent 924df20 commit ad0ea0a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ifex/model/ifex_ast_introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""

import re
import ifex_ast
import ifex.model.ifex_ast as ifex_ast
from dataclasses import is_dataclass, fields
from typing import get_args, get_origin, List, Optional, Union, Any, ForwardRef
import typing
Expand Down
23 changes: 23 additions & 0 deletions tests/gen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import yaml

from ifex.model import ifex_ast, ifex_parser, ifex_generator
import ifex.model.ifex_ast_introspect as introspect
import dacite, pytest
import os

Expand Down Expand Up @@ -55,6 +56,28 @@ def test_ast_gen():
assert service.minor_version == 0


# This does not assert anything -> but if printouts are captured they can be studied
def test_print():
ast = ifex_parser.get_ast_from_yaml_file(os.path.join(TestPath, 'test.variant', 'input.yaml'))
print(yaml.dump(ast, sort_keys=False))
print(introspect.get_variant_types(ast.namespaces[0].typedefs[0]))

# Test expectations and helper-functions on the variant type
def test_variant():
ast = ifex_parser.get_ast_from_yaml_file(os.path.join(TestPath, 'test.variant', 'input.yaml'))
# Method argument
v0type = ast.namespaces[0].methods[0].input[0].datatype
assert not introspect.is_ifex_variant_typedef(v0type)
assert introspect.is_ifex_variant_shortform(v0type)

# Typdefs
v1 = ast.namespaces[0].typedefs[0]
v2 = ast.namespaces[0].typedefs[1]
assert introspect.is_ifex_variant_typedef(v1)
assert introspect.is_ifex_variant_typedef(v2)
assert introspect.is_ifex_variant_shortform(v2.datatype)


def test_ast_manual():
service = ifex_ast.AST(name='test', description='test', major_version=1, minor_version=0)

Expand Down

0 comments on commit ad0ea0a

Please sign in to comment.