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 create_description_instance_from_template( template: Template, programming_language: str = "python", natural_language: str = "en", namespace: str = "submission", is_html: bool = True) -> str: from pathlib import Path judge_directory = Path(__file__).parent.parent language = get_language(programming_language) bundle = Bundle(config=DodonaConfig( resources="", source="", time_limit=0, memory_limit=0, natural_language=natural_language, programming_language=programming_language, workdir="", judge=str(judge_directory)), out=open(os.devnull, 'w'), lang_config=language, context_separator_secret="", secret="", plan=Plan(namespace=namespace)) description_generator = language.get_description_generator() # Partial function doesn't work because of bundle must be given, # but custom_type_map not def get_type_name(args: TYPE_ARG, custom_type_map: TYPE_CONFIG_NAME = None) -> str: return description_generator.get_type_name(args, bundle, custom_type_map, is_html=is_html) def get_natural_type_name(type_name: str, plural: bool = False): return description_generator.get_natural_type_name( type_name, bundle, plural, is_html) def get_variable(var_name: str, is_global: bool = True): if is_global: return description_generator.get_global_variable_name( var_name, is_html) return description_generator.get_variable_name(var_name, is_html) namespace = language.conventionalize_namespace(namespace) if is_html: namespace = html.escape(namespace) return template.render( function=partial(description_generator.get_function_name, is_html=is_html), property=partial(description_generator.get_property_name, is_html=is_html), variable=get_variable, datatype_common=get_natural_type_name, datatype=get_type_name, statement=partial(description_generator.get_code, bundle=bundle, is_html=is_html, statement=True), expression=partial(description_generator.get_code, bundle=bundle, is_html=is_html, statement=False), prompt=description_generator.get_prompt(is_html=is_html), programming_language=description_generator.get_prompt_language( is_html=is_html), programming_language_raw=description_generator.get_prompt_language( is_html=False), namespace=language.conventionalize_namespace(namespace), natural_language=natural_languages.get(natural_language, natural_language), natural_language_iso639=natural_language)
def test_c_escape(tmp_path: Path, pytestconfig): conf = configuration(pytestconfig, "", "c", 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.CHAR, data="'"))