def test_get_variable_key_name(self, mocked_get_variable_key): """ Ensure Variables.get_variable_key_name properly eliminates curly braces """ # Ensure proper operation from expected input mocked_get_variable_key.return_value = "{variable}" self.assertEqual(Variables.get_variable_key_name("name"), "variable") mocked_get_variable_key.assert_called_with("name") # Ensure missing curly brace non-operate mocked_get_variable_key.return_value = "{variable" self.assertEqual(Variables.get_variable_key_name("name"), "{variable") mocked_get_variable_key.assert_called_with("name") # Ensure missing key mocked_get_variable_key.return_value = None self.assertEqual(Variables.get_variable_key_name("name"), None) mocked_get_variable_key.assert_called_with("name")
def get_applied_language(cls, solutionPath, solutionLanguage): if solutionPath in cls._appliedLanguages: return cls._appliedLanguages[solutionPath] variableDictionary = { Variables.get_variable_key_name(Variables.NAME_FILENAME): fileops.get_basename(solutionPath), Variables.get_variable_key_name(Variables.NAME_FILENAME_LESS_EXT): fileops.get_basename_less_extension(solutionPath), Variables.get_variable_key_name(Variables.NAME_DIRECTORY): fileops.get_parent_dir(solutionPath) } cls._appliedLanguages[solutionPath] = AppliedLanguage(solutionLanguage.name, cls._get_formatted_str_rec(variableDictionary, solutionLanguage._compileExtension), cls._get_formatted_str_rec(variableDictionary, solutionLanguage._compileCommand), cls._get_formatted_str_rec(variableDictionary, solutionLanguage._compileArguments), cls._get_formatted_str_rec(variableDictionary, solutionLanguage._runExtension), cls._get_formatted_str_rec(variableDictionary, solutionLanguage._runCommand), cls._get_formatted_str_rec(variableDictionary, solutionLanguage._runArguments), solutionPath) return cls._appliedLanguages[solutionPath]
def _get_file_problemnumber_type_tuple(path): """ Extracts the problem number and case type from the file name at path :returns: (problemnumber:int, casetype:int) """ filename = fileops.get_basename_less_extension(path) # Extract problem number filenameMatcher = Definitions.get_value_matcher(Case.NAMING_DEFINITION_KEY) problemNumber = filenameMatcher.get_variable_value(filename, Variables.get_variable_key_name(Variables.NAME_PROBLEM_NUMBER)) # Extract case type caseType = filenameMatcher.get_variable_value(filename, Variables.get_variable_key_name(Variables.NAME_CASE_TYPE)) if problemNumber is None: return None # Return the tuple return (int(problemNumber), CaseType.from_string(caseType))
def load_from_path(path): """ Creates a new Solution object from a file at path and returns it """ newSolution = Solution(solutionPath=path) filename = fileops.get_basename_less_extension(path) filenameMatcher = Definitions.get_value_matcher(Solution.NAMING_DEFINITION_KEY) newSolution.problemNumber = filenameMatcher.get_variable_value( filename, Variables.get_variable_key_name(Variables.NAME_PROBLEM_NUMBER) ) from util.writer import Writer newSolution.solutionWriter = fileops.get_basename(fileops.get_parent_dir(path)) newSolution.solutionLanguage = Languages.get_language_from_extension(fileops.get_extension(path)) return newSolution