Esempio n. 1
0
    def test_load_from_path(self, mocked_solution_fileops, mocked_def_val_match,
            mocked_variables_get_var_key_name, mocked_languages_from_ext):
        """
        Ensure Solution.load_from_path calls necessary functions and returns
        """
        raise DeprecatedTest
        mocked_solution_fileops.get_basename_less_extension.return_value = 'filename'
        mockedValMatcher = mock.MagicMock()
        mockedValMatcher.get_variable_value.return_value = 'lol'
        mocked_def_val_match.return_value = mockedValMatcher
        mocked_variables_get_var_key_name.return_value = 'keyname'
        mocked_solution_fileops.get_parent_dir.return_value = 'parent'
        mocked_solution_fileops.get_basename.return_value = 'basename'
        mocked_solution_fileops.get_extension.return_value = 'extension'
        mocked_languages_from_ext.return_value = 'lang'

        createdSolution = Solution.load_from_path('path')
        self.assertEquals(createdSolution._path, 'path')
        self.assertEquals(createdSolution.problemNumber, 'lol')
        self.assertEquals(createdSolution.solutionWriter, 'basename')
        self.assertEquals(createdSolution.solutionLanguage, 'lang')

        mocked_solution_fileops.get_basename_less_extension.assert_called_with('path')
        mocked_def_val_match.assert_called_with(Solution.NAMING_DEFINITION_KEY)
        mocked_variables_get_var_key_name.assert_called_with(Variables.NAME_PROBLEM_NUMBER)
        mockedValMatcher.get_variable_value.assert_called_with('filename',
                'keyname')
        mocked_solution_fileops.get_parent_dir.assert_called_with('path')
        mocked_solution_fileops.get_basename.assert_called_with('parent')
        mocked_solution_fileops.get_extension.assert_called_with('path')
        mocked_languages_from_ext.assert_calle_with('extension')
Esempio n. 2
0
    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
Esempio n. 3
0
    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')