Exemple #1
0
 def to_string(caseType: int) -> str:
     """
     Converts the casetype enum int into a readable string
     """
     if caseType == CaseType.SAMPLE:
         return Definitions.get_value(CaseType.SAMPLE_STRING_KEY)
     elif caseType == CaseType.CORNER_CASE:
         return Definitions.get_value(CaseType.CORNER_STRING_KEY)
     else:
         return Definitions.get_value(CaseType.GENERATED_STRING_KEY)
Exemple #2
0
    def from_string(string: str) -> int:
        """
        Converts the CaseType strings defined in the definitions file to
        their respective enum int values. If invalid string, assumed generated

        :param string: The string to convert to enum
        """
        if string == Definitions.get_value(CaseType.SAMPLE_STRING_KEY):
            return CaseType.SAMPLE
        elif string == Definitions.get_value(CaseType.CORNER_STRING_KEY):
            return CaseType.CORNER_CASE
        else:
            return CaseType.GENERATED
Exemple #3
0
def get_all_cases(problemNumber=None):
    """
    Resolves the cases directory from the definitions file and delegates to
    _get_all_cases

    :return: {problemNumber: [Case]}
    """
    return _get_all_cases(fileops.join_path(PathMapper._rootPath, 
        Definitions.get_value('test_directory')), problemNumber=problemNumber)
    def test_get_value_unit(self, mocked_load_definitions):
        """
        Ensure Definitions.get_value functions properly as a unit
        """
        
        # Before doing anything, definitionsDict should be None and load called
        def setDefDict():
            Definitions._definitionsDict = {}
        mocked_load_definitions.side_effect = setDefDict
        self.assertEqual(Definitions.get_value('invalidKey'), None)
        mocked_load_definitions.assert_called_with()

        # With a good definitions dict, ensure a key inside the dict returns val
        mocked_load_definitions.side_effect = None
        Definitions._definitionsDict = {
                                            'key1' : 'val1',
                                            'key2' : 'val2'
                                       }
        self.assertEqual(Definitions.get_value('key1'), 'val1')
        self.assertEqual(Definitions.get_value('nonkey'), None)
        Definitions._definitionsDict = None
Exemple #5
0
def package_into_path(path: str, layoutDict: dict):
    """
    Follows the users provided configuration file to package all cases into
    the provided path. Delegates most functionality to other functions.

    Arguments:
    path: str - The path to package into
    layoutDict: dict - The dict provided by the user's configuration
    """
    # Look through all cases...
    for problemNumber, caseList in case.get_all_cases().items():
        # Make the directories for the problem numbers
        problemDirName = Definitions.get_value('solution_naming').format(
                **dict(problem=problemNumber))
        problemPath = fileops.join_path(path, problemDirName)
        fileops.make(problemPath, FileType.DIRECTORY)

        # Go through each type in the config file and package it
        for packageTypeName, packageType in layoutDict[TYPES_KEY].items():
            package_type(problemPath, caseList, packageType, 
                _get_compression_from_layout_dict(layoutDict),
                packageTypeName)
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)
Exemple #7
0
def validate_defined_case_dir():
    testDir = Definitions.get_value('test_directory')
    validate_casefiles(fileops.get_files_in_dir(testDir))
Exemple #8
0
 def str_to_list_range(self, string):
     lowerBound = 1
     upperBound = Definitions.get_value('problem_count')
     return self.str_to_list_range_with_bounds(string, upperBound, 
                                               lowerBound)