def test_is_solution_file(self, mocked_solution_fileops, mocked_definitions_get_value_matcher): """ Ensure Solution.is_solution_file delegates to Matcher's match """ mocked_solution_fileops.get_basename_less_extension.return_value = 'basename' mockedMatcher = mock.MagicMock() mockedMatcher.matches.return_value = True mocked_definitions_get_value_matcher.return_value = mockedMatcher self.assertTrue(Solution.is_solution_file('Problem1.cpp')) mocked_solution_fileops.get_basename_less_extension.assert_called_with('Problem1.cpp') mocked_definitions_get_value_matcher.assert_called_with(Solution.NAMING_DEFINITION_KEY) mockedMatcher.matches.assert_called_with('basename')
def load_from_path(cls, path): """ Loads a writer and all their solutions from a specified path """ # Check if writer directoroy exists. If not, return nothing if not fileops.exists(path, fileops.FileType.DIRECTORY): return None loadedWriter = Writer(writerPath=path) # Load the user data from the data file dataDictionary = fileops.get_json_dict(loadedWriter._get_datafile_path()) # Populate the data if available # Load name if cls.DATAFILE_NAME_FIELD in dataDictionary: loadedWriter.name = dataDictionary[cls.DATAFILE_NAME_FIELD] # Load email if cls.DATAFILE_EMAIL_FIELD in dataDictionary: loadedWriter.email = dataDictionary[cls.DATAFILE_EMAIL_FIELD] # Load languages if cls.DATAFILE_LANGS_FIELD in dataDictionary: for languageName in dataDictionary[cls.DATAFILE_LANGS_FIELD]: loadedWriter._add_known_language_from_name(languageName) # Load assigned if cls.DATAFILE_ASSIGNED_PROBLEMS in dataDictionary: for assignedProblem in dataDictionary[cls.DATAFILE_ASSIGNED_PROBLEMS]: loadedWriter._add_assigned_problem(assignedProblem[0], assignedProblem[1]) # Load all solutions for possibleSolution in fileops.get_files_in_dir(path): if Solution.is_solution_file(possibleSolution): if not Languages.is_prevalent_extension(fileops.get_extension(possibleSolution)): continue solutionObject = Solution.load_from_path(possibleSolution) loadedWriter._add_solution(solutionObject) return loadedWriter