From 3b56d8259d6aa8311f86e0561e40d0b17bc62534 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Fri, 4 Mar 2016 14:55:09 +0530 Subject: Language registry altered, Name cleanup: - set_registry will only act when registry is None - _setup, _teardown and _check_code are setup,teardown,check_code - Corresponding name changes in evaluator modules --- yaksh/language_registry.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'yaksh/language_registry.py') diff --git a/yaksh/language_registry.py b/yaksh/language_registry.py index 76a23d7..ee311ec 100644 --- a/yaksh/language_registry.py +++ b/yaksh/language_registry.py @@ -3,11 +3,18 @@ import importlib registry = None -def set_registry(): +# def set_registry(): +# global registry +# registry = _LanguageRegistry() + +def _set_registry(): global registry - registry = _LanguageRegistry() + if registry is None: + registry = _LanguageRegistry() + return registry def get_registry(): + registry = _set_registry() return registry class _LanguageRegistry(object): -- cgit From 1e993bee18028c59d809f49d853b60e41326991c Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Fri, 11 Mar 2016 12:11:49 +0530 Subject: Add a python standard out evaluator --- yaksh/language_registry.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'yaksh/language_registry.py') diff --git a/yaksh/language_registry.py b/yaksh/language_registry.py index ee311ec..512e2f5 100644 --- a/yaksh/language_registry.py +++ b/yaksh/language_registry.py @@ -1,21 +1,31 @@ from settings import code_evaluators import importlib +import json registry = None # def set_registry(): # global registry # registry = _LanguageRegistry() - -def _set_registry(): + +def get_registry(): #@@@get_evaluator_registry global registry if registry is None: registry = _LanguageRegistry() return registry - -def get_registry(): - registry = _set_registry() - return registry + +def unpack_json(json_data): + data = json.loads(json_data) + return data + +def create_evaluator_instance(language, test_case_type, json_data, in_dir): + """Create instance of relevant EvaluateCode class based on language""" + # set_registry() + registry = get_registry() + cls = registry.get_class(language, test_case_type) #@@@get_evaluator_for_language + instance = cls(in_dir) + # instance = cls.from_json(language, json_data, in_dir) + return instance class _LanguageRegistry(object): def __init__(self): @@ -24,12 +34,13 @@ class _LanguageRegistry(object): self._register[language] = None # Public Protocol ########## - def get_class(self, language): + def get_class(self, language, test_case_type): """ Get the code evaluator class for the given language """ if not self._register.get(language): self._register[language] = code_evaluators.get(language) - cls = self._register[language] + test_case_register = self._register[language] + cls = test_case_register.get(test_case_type) module_name, class_name = cls.rsplit(".", 1) # load the module, will raise ImportError if module cannot be loaded get_module = importlib.import_module(module_name) -- cgit From e8e6b4bc35c7d012d9c41fb37d91687eb605b56c Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 29 Mar 2016 19:00:12 +0530 Subject: - Refactor Scilab, Bash, Java and C - Add Test Cases to reflect refactoring changes - Fix language registry - Add test case for language registry - Fix register in settings - Keep snippet field for now --- yaksh/language_registry.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh/language_registry.py') diff --git a/yaksh/language_registry.py b/yaksh/language_registry.py index 512e2f5..3205279 100644 --- a/yaksh/language_registry.py +++ b/yaksh/language_registry.py @@ -48,7 +48,7 @@ class _LanguageRegistry(object): get_class = getattr(get_module, class_name) return get_class - def register(self, language, class_name): + def register(self, language, class_names): """ Register a new code evaluator class for language""" - self._register[language] = class_name + self._register[language] = class_names -- cgit From 23b7abd3c1125e4c875e214e4f673c48c4bf4752 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 2 May 2016 11:52:58 +0530 Subject: Remove commented code and cleanup --- yaksh/language_registry.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'yaksh/language_registry.py') diff --git a/yaksh/language_registry.py b/yaksh/language_registry.py index 3205279..398e1aa 100644 --- a/yaksh/language_registry.py +++ b/yaksh/language_registry.py @@ -3,12 +3,8 @@ import importlib import json registry = None - -# def set_registry(): -# global registry -# registry = _LanguageRegistry() -def get_registry(): #@@@get_evaluator_registry +def get_registry(): global registry if registry is None: registry = _LanguageRegistry() @@ -20,11 +16,9 @@ def unpack_json(json_data): def create_evaluator_instance(language, test_case_type, json_data, in_dir): """Create instance of relevant EvaluateCode class based on language""" - # set_registry() registry = get_registry() - cls = registry.get_class(language, test_case_type) #@@@get_evaluator_for_language + cls = registry.get_class(language, test_case_type) instance = cls(in_dir) - # instance = cls.from_json(language, json_data, in_dir) return instance class _LanguageRegistry(object): -- cgit From c384c60c6d7fb5d30f3f929c518e0b41e084c4c4 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 9 May 2016 13:00:04 +0530 Subject: - Adhere to 80 columns - add docstrings - Fix further tests --- yaksh/language_registry.py | 1 + 1 file changed, 1 insertion(+) (limited to 'yaksh/language_registry.py') diff --git a/yaksh/language_registry.py b/yaksh/language_registry.py index 398e1aa..24aef7d 100644 --- a/yaksh/language_registry.py +++ b/yaksh/language_registry.py @@ -36,6 +36,7 @@ class _LanguageRegistry(object): test_case_register = self._register[language] cls = test_case_register.get(test_case_type) module_name, class_name = cls.rsplit(".", 1) + import yaksh.python_assertion_evaluator # load the module, will raise ImportError if module cannot be loaded get_module = importlib.import_module(module_name) # get the class, will raise AttributeError if class cannot be found -- cgit