def test_load_languages(self, mocked_language_fileops, 
            mocked_languages_get_filepath, mocked_get_prev_extension,
            mocked_language_load_from_dict):
        """
        Ensure Languages.load_languages properly delegates to Language's load from dict
        """
        raise DeprecatedTest
        mocked_language_fileops.get_json_dict.return_value = {
                                                            'languages' : [
                                                                        { 'block' : 1 },
                                                                        { 'block' : 2 }
                                                                          ]
                                                             }
        mocked_languages_get_filepath.return_value = 'path'
        mocked_get_prev_extension.side_effect = lambda x : 'ext1' if x == { 'block' : 1} else 'ext2'
        mocked_language_load_from_dict.return_value = 'haha'


        Languages.load_languages()
        self.assertEqual(Languages._languagesDict, {'ext1' : 'haha', 'ext2' : 'haha'})
        mocked_language_fileops.get_json_dict.assert_called_with('path')
        mocked_get_prev_extension.assert_called_any({'block' : 1})
        mocked_get_prev_extension.assert_called_any({'block' : 2})
        mocked_language_load_from_dict.assert_called_any({'block' : 1})
        mocked_language_load_from_dict.assert_called_any({'block' : 2})
    def test_get_prev_extension_from_block(self):
        """
        Ensure Languages.get_prevalent_extension_from_block works as intended
        """
        block = {'compileExtension' : 'cpp',
                 'runExtension'     : 'o'}
        self.assertEqual(Languages.get_prevalent_extension_from_block(block), 'cpp')

        block = { 'runExtension'     : 'o'}
        self.assertEqual(Languages.get_prevalent_extension_from_block(block), 'o')

        block = {'compileExtension' : 'cpp'}
        self.assertEqual(Languages.get_prevalent_extension_from_block(block), 'cpp')
    def test_get_language_from_extension(self, mocked_load_languages):
        """
        Ensure Languages.get_language_from_extension properly gets a language from ext
        """

        def populateDict():
            Languages._languagesDict = {'ext1' : 'lang1', 'ext2' : 'lang2'}
        mocked_load_languages.side_effect = populateDict

        self.assertEqual(Languages.get_language_from_extension('ext1'), 'lang1')
        mocked_load_languages.assert_called_with()

        self.assertEqual(Languages.get_language_from_extension('ext3'), None)
    def count_assignments(self):
        """ Looks through all writers' assigned solutions and counts which have
        been assigned and how many times they have """
        problemsAssignedDict = {} # Maps specificProblems to completed counts
        writersAssignedDict = {}
        for writer in Writers.get_all_writers():
            for (problemNumber, problemLanguage) in writer.assignedProblems:
                languageObject = Languages.get_language_by_name(problemLanguage)

                # Only consider the languages and problems sent into the object
                if (not problemNumber in self.allowedProblemNumbers or
                    not languageObject in self.allowedLanguages):
                    continue

                specificInstance = SpecificProblem(problemNumber, languageObject)
                if not specificInstance in problemsAssignedDict:
                    problemsAssignedDict[specificInstance] = 1
                else:
                    problemsAssignedDict[specificInstance] += 1
            
            if writer in self.writers:
                writersAssignedDict[writer] = len(writer.assignedProblems)


        return (problemsAssignedDict, writersAssignedDict)
Beispiel #5
0
    def _add_known_language_from_name(self, languageName):
        language = Languages.get_language_by_name(languageName)

        if language is None:
            raise PyCException('Error: {} is not a valid language'.format(languageName))

        self._add_known_language(language)
    def test_get_language_by_name(self, mocked_load_languages):
        """
        Ensure Languages.get_language_by_name properly gets a language from name
        """
        mockedLangOne = mock.MagicMock(spec=Language)
        mockedLangTwo = mock.MagicMock(spec=Language)
        mockedLangOne.name = 'Python'
        mockedLangTwo.name = 'C++'
        def populateDict():
            Languages._languagesDict = {'ext1' :mockedLangOne, 'ext2' : mockedLangTwo}
        mocked_load_languages.side_effect = populateDict

        self.assertEqual(Languages.get_language_by_name('C++'), mockedLangTwo)
        mocked_load_languages.assert_called_with()

        self.assertEqual(Languages.get_language_by_name('non'), None)
 def test_get_languages_filepath(self, mocked_get_config_path):
     """
     Ensure Languages.get_languages_filepath properly delegates to PathMapper
     """
     mocked_get_config_path.return_value = 'confPath'
     self.assertEqual(Languages.get_languages_filepath(), os.path.join(
         'confPath', Languages.LANGUAGES_FILE))
def operate(args):
    """
    Takes the passed in args and delegates to proper functionality. This is set
    as the executable function when the `writers assign` subparser is used.

    Arguments:
    args: Namespace - The arguments passed via CLI
    """
    # If the user specified a problem list, use that as the list of problems. 
    problemParser = NumberParse()
    if not args.problems is None:
        specifiedProblems = problemParser.str_list_to_uniq_range(args.problems)
    else:
        specifiedProblems = problemParser.str_list_to_uniq_range(['1+'])

    specifiedLanguages = []
    if not args.language is None:
        for languageName in args.language:
            loadedLanguage = Languages.get_language_by_name(languageName)
            if loadedLanguage is None:
                raise PyCException('Error: {} is an invalid language'.format(languageName))
            specifiedLanguages.append(loadedLanguage)
    else:
        specifiedLanguages = [Languages.get_language_by_name(name) for name in 
                Languages.get_all_language_names()]

    specifiedWriters = []
    if not args.full and not args.writer_names is None and len(args.writer_names) > 0:
        for writerName in args.writer_names:
            loadedWriter = Writer.load_from_folder(writerName)
            if loadedWriter is None:
                raise PyCException('Error: {} is an invalid writer'.format(writerName))
            specifiedWriters.append(loadedWriter)
    else:
        specifiedWriters = Writers.get_all_writers()

    allocator = AssignmentAllocator(specifiedProblems, specifiedLanguages, 
            specifiedWriters, fromScratch=args.full)
    allocator.do_assignment(Definitions.get_value('complete_threshold'), overflow=args.overallocate)
Beispiel #9
0
    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
Beispiel #10
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