def test_load_variables(self, mocked_variables_fileops, mocked_variables_get_variables_filepath):
     """
     Ensure Variables.load_variables delegates to fileops properly
     """
     raise DeprecatedTest
     mocked_variables_fileops.get_json_dict.return_value = {"hello": "hi"}
     mocked_variables_get_variables_filepath.return_value = "tshirt"
     Variables.load_variables()
     self.assertEqual(Variables._variablesDict, {"hello": "hi"})
     mocked_variables_fileops.get_json_dict.assert_caled_with("tshirt")
     mocked_variables_get_variables_filepath.assert_called_with()
 def test_get_variables_filepath(self, mocked_variables_fileops, mocked_pathmapper_get_conf_path):
     """
     Ensure Variables.get_variables_filepath delegates to PathMapper and fileops
     """
     mocked_variables_fileops.join_path.return_value = "leaves"
     mocked_pathmapper_get_conf_path.return_value = "fake_config_path"
     self.assertEqual(Variables.get_variables_filepath(), "leaves")
     mocked_variables_fileops.join_path.assert_called_with("fake_config_path", Variables.VARIABLES_FILE)
    def test_get_variable_key_name(self, mocked_get_variable_key):
        """
        Ensure Variables.get_variable_key_name properly eliminates curly braces
        """
        # Ensure proper operation from expected input
        mocked_get_variable_key.return_value = "{variable}"
        self.assertEqual(Variables.get_variable_key_name("name"), "variable")
        mocked_get_variable_key.assert_called_with("name")

        # Ensure missing curly brace non-operate
        mocked_get_variable_key.return_value = "{variable"
        self.assertEqual(Variables.get_variable_key_name("name"), "{variable")
        mocked_get_variable_key.assert_called_with("name")

        # Ensure missing key
        mocked_get_variable_key.return_value = None
        self.assertEqual(Variables.get_variable_key_name("name"), None)
        mocked_get_variable_key.assert_called_with("name")
    def test_get_variable_key(self, mocked_load_variables):
        """
        Ensure Variables.get_variable_key properly calls to the variables dict
        """
        # Ensure that before a dict exists, it is created
        def setVarDict():
            Variables._variablesDict = {}

        mocked_load_variables.side_effect = setVarDict
        self.assertEqual(Variables.get_variable_key("varName"), None)
        mocked_load_variables.assert_called_with()

        # Ensure that if a dict exists and key exists, it is returned
        mocked_load_variables.side_effect = None
        Variables._variablesDict = {"key": "{varVal}", "key2": "{varVal2}"}
        self.assertEqual(Variables.get_variable_key("key"), "{varVal}")

        # Ensure that if the key doesnt exist, none is returned
        self.assertEqual(Variables.get_variable_key("nonkey"), None)
Example #5
0
    def get_applied_language(cls, solutionPath, solutionLanguage):
        if solutionPath in cls._appliedLanguages:
            return cls._appliedLanguages[solutionPath]

        variableDictionary = {
                Variables.get_variable_key_name(Variables.NAME_FILENAME): fileops.get_basename(solutionPath),
                Variables.get_variable_key_name(Variables.NAME_FILENAME_LESS_EXT): fileops.get_basename_less_extension(solutionPath),
                Variables.get_variable_key_name(Variables.NAME_DIRECTORY): fileops.get_parent_dir(solutionPath)
                }

        cls._appliedLanguages[solutionPath] = AppliedLanguage(solutionLanguage.name,
                cls._get_formatted_str_rec(variableDictionary, solutionLanguage._compileExtension),
                cls._get_formatted_str_rec(variableDictionary, solutionLanguage._compileCommand),
                cls._get_formatted_str_rec(variableDictionary, solutionLanguage._compileArguments),
                cls._get_formatted_str_rec(variableDictionary, solutionLanguage._runExtension),
                cls._get_formatted_str_rec(variableDictionary, solutionLanguage._runCommand),
                cls._get_formatted_str_rec(variableDictionary, solutionLanguage._runArguments),
                solutionPath)

        return cls._appliedLanguages[solutionPath]
Example #6
0
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))
Example #7
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