def test_special_numbers(language, tmp_path: Path, pytestconfig): conf = configuration(pytestconfig, "", language, tmp_path) plan = Plan() bundle = create_bundle(conf, sys.stdout, plan) type_map = bundle.lang_config.type_support_map() # Create a list of basic types we want to test. types = [] for t, n in itertools.product([ BasicNumericTypes.RATIONAL, AdvancedNumericTypes.DOUBLE_PRECISION, AdvancedNumericTypes.SINGLE_PRECISION ], [ SpecialNumbers.NOT_A_NUMBER, SpecialNumbers.POS_INFINITY, SpecialNumbers.NEG_INFINITY ]): if type_map[t] == TypeSupport.SUPPORTED: types.append(NumberType(type=t, data=n)) # Run the encode templates. results = run_encoder(bundle, tmp_path, types) assert len(results) == len(types) for result, expected in zip(results, types): actual = as_basic_type(parse_value(result)) expected = as_basic_type(expected) assert expected.type == actual.type py_expected = to_python_comparable(expected) py_actual = to_python_comparable(actual) assert py_expected == py_actual
def test_escape(language, tmp_path: Path, pytestconfig): conf = configuration(pytestconfig, "", language, tmp_path) plan = Plan() bundle = create_bundle(conf, sys.stdout, plan) assert_serialisation( bundle, tmp_path, StringType(type=BasicStringTypes.TEXT, data='"hallo"')) assert_serialisation(bundle, tmp_path, StringType(type=AdvancedStringTypes.CHAR, data="'"))
def evaluator_config(tmp_path: Path, pytestconfig, options=None) -> EvaluatorConfig: if options is None: options = dict() conf = configuration(pytestconfig, "", "python", tmp_path) plan = Plan() bundle = create_bundle(conf, sys.stdout, plan) return EvaluatorConfig( bundle=bundle, options=options, context_dir=tmp_path )
def test_basic_types(language, tmp_path: Path, pytestconfig): conf = configuration(pytestconfig, "", language, tmp_path) plan = Plan() bundle = create_bundle(conf, sys.stdout, plan) type_map = bundle.lang_config.type_support_map() # Create a list of basic types we want to test. types = [] if type_map[BasicNumericTypes.INTEGER] != TypeSupport.UNSUPPORTED: types.append(NumberType(type=BasicNumericTypes.INTEGER, data=5)) if type_map[BasicNumericTypes.RATIONAL] != TypeSupport.UNSUPPORTED: types.append(NumberType(type=BasicNumericTypes.RATIONAL, data=5.5)) if type_map[BasicStringTypes.TEXT] != TypeSupport.UNSUPPORTED: types.append(StringType(type=BasicStringTypes.TEXT, data="hallo")) if type_map[BasicBooleanTypes.BOOLEAN] != TypeSupport.UNSUPPORTED: types.append(BooleanType(type=BasicBooleanTypes.BOOLEAN, data=True)) if type_map[BasicSequenceTypes.SEQUENCE] != TypeSupport.UNSUPPORTED: types.append( SequenceType( type=BasicSequenceTypes.SEQUENCE, data=[NumberType(type=BasicNumericTypes.INTEGER, data=20)])) if type_map[BasicSequenceTypes.SET] != TypeSupport.UNSUPPORTED: types.append( SequenceType( type=BasicSequenceTypes.SET, data=[NumberType(type=BasicNumericTypes.INTEGER, data=20)])) if type_map[BasicObjectTypes.MAP] != TypeSupport.UNSUPPORTED: types.append( ObjectType(type=BasicObjectTypes.MAP, data=[ ObjectKeyValuePair( key=StringType(type=BasicStringTypes.TEXT, data="data"), value=NumberType(type=BasicNumericTypes.INTEGER, data=5)) ])) if type_map[BasicNothingTypes.NOTHING] != TypeSupport.UNSUPPORTED: types.append(NothingType()) # Run the encode templates. results = run_encoder(bundle, tmp_path, types) assert len(results) == len(types) for result, expected in zip(results, types): actual = as_basic_type(parse_value(result)) assert expected.type == actual.type py_expected = to_python_comparable(expected) py_actual = to_python_comparable(actual) assert py_expected == py_actual
def test_advanced_types(language, tmp_path: Path, pytestconfig): conf = configuration(pytestconfig, "", language, tmp_path) plan = Plan() bundle = create_bundle(conf, sys.stdout, plan) type_map = bundle.lang_config.type_support_map() # Create a list of basic types we want to test. types = [] # The only advanced type undefined that should be tested if type_map[AdvancedNothingTypes.UNDEFINED] == TypeSupport.SUPPORTED: types.append(NothingType(type=AdvancedNothingTypes.UNDEFINED)) # Run the encode templates. results = run_encoder(bundle, tmp_path, types) assert len(results) == len(types) for result, expected in zip(results, types): actual = parse_value(result) assert expected.type == actual.type py_expected = to_python_comparable(expected) py_actual = to_python_comparable(actual) assert py_expected == py_actual
def test_python_escape(tmp_path: Path, pytestconfig): conf = configuration(pytestconfig, "", "python", tmp_path) plan = Plan() bundle = create_bundle(conf, sys.stdout, plan) assert_serialisation(bundle, tmp_path, StringType(type=BasicStringTypes.TEXT, data='"hallo"')) assert_serialisation(bundle, tmp_path, StringType(type=BasicStringTypes.TEXT, data="'hallo'"))