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
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 is_solution_file(path): """ Checks to see if basename of file matches solution naming scheme from definitions """ filename = fileops.get_basename_less_extension(path) return Definitions.get_value_matcher(Solution.NAMING_DEFINITION_KEY).matches(filename)
def test_get_value_matcher(self, mocked_matcher_from_var_string, mocked_get_value): mocked_get_value.return_value = 'hello' mocked_matcher_from_var_string.return_value = 'hi' self.assertEqual(Definitions.get_value_matcher('key'), 'hi') mocked_get_value.assert_called_with('key') mocked_matcher_from_var_string.assert_called_with('hello')