diff --git a/dcm/dcm_core.py b/dcm/dcm_core.py index 8b92bac..d6dea4e 100644 --- a/dcm/dcm_core.py +++ b/dcm/dcm_core.py @@ -565,7 +565,12 @@ def get_examples(cls, content_class=CompetenceTree, markup: str = "json") -> dic @classmethod def from_definition_string( - cls, name: str, definition_string: str, content_class, markup: str = "json" + cls, + name: str, + definition_string: str, + content_class, + markup: str = "json", + debug:bool = False ) -> Any: """ Load a DynamicCompetenceMap or Learner instance from a definition string (either JSON or YAML). @@ -575,7 +580,7 @@ def from_definition_string( definition_string (str): The string content of the definition. content_class (dataclass_json): The class which will be instantiated with the parsed data. markup (str): The markup format of the data. Defaults to 'json'. Supported values are 'json' and 'yaml'. - + debug(bool): if True supply a JSON dump of the data in /tmp/{name}.json Returns: DynamicCompetenceMap: An instance of DynamicCompetenceMap loaded with the parsed data. @@ -584,7 +589,12 @@ def from_definition_string( """ try: data = cls.parse_markup(definition_string, markup) - content = content_class.from_dict(data) + if debug: + # Save the parsed data to a JSON file in /tmp directory + debug_file_path = os.path.join('/tmp', f'{name}.json') + with open(debug_file_path, 'w') as debug_file: + json.dump(data, debug_file, indent=2,default=str) + content = content_class.from_dict(data) if isinstance(content, CompetenceTree): return DynamicCompetenceMap(content) else: diff --git a/dcm/dcm_webserver.py b/dcm/dcm_webserver.py index fa98a15..d08a39d 100644 --- a/dcm/dcm_webserver.py +++ b/dcm/dcm_webserver.py @@ -227,7 +227,7 @@ async def render(self, _click_args=None): else: self.learner = item self.assess(item) - except BaseException as ex: + except Exception as ex: self.handle_exception(ex, self.do_trace) def render_dcm(self, diff --git a/tests/test_rwth_aachen_module.py b/tests/test_rwth_aachen_module.py index 2dfd3f0..2957c7d 100644 --- a/tests/test_rwth_aachen_module.py +++ b/tests/test_rwth_aachen_module.py @@ -15,6 +15,7 @@ CompetenceFacet, CompetenceLevel, CompetenceTree, + DynamicCompetenceMap ) class TestModule(Basetest): @@ -149,11 +150,18 @@ def test_master_informatik(self): # Create the competence tree competence_tree = self.create_competence_tree(competence_elements, url=url) # Pretty print the JSON with specified indentation - pretty_json = competence_tree.to_pretty_json() + #pretty_json = competence_tree.to_pretty_json() yaml_str = competence_tree.to_yaml() debug = self.debug - # debug=True + debug=True if debug: print(yaml_str) with open("/tmp/rwth_aachen_master_informatik.yaml", "w") as yaml_file: yaml_file.write(yaml_str) + dcm=DynamicCompetenceMap.from_definition_string( + name="RWTH Aachen Master Informatik", + definition_string=yaml_str, + content_class=CompetenceTree, + markup="yaml", + debug=debug) + self.assertIsNotNone(dcm)