Ejemplo n.º 1
0
def ensure_valid_recipe_types(
        calculator_name: str, resources: OrderedDict[str, Resource],
        recipe_types: OrderedDict[str, str]) -> List[TokenError]:
    used_recipe_types: Set[str] = set()
    errors: List[TokenError] = []

    for resource in resources:
        for recipe in resources[resource].recipes:
            recipe_type: str = recipe.recipe_type

            # add this to the list of found recipe types to later check to make sure all the recipe_types in the list are used
            if recipe_type != "Raw Resource":
                used_recipe_types.add(recipe_type)

            # check if this recipe exists in the recipe type list
            if recipe_type not in recipe_types and recipe_type != "Raw Resource":
                # TODO: Have a better token associated with this error
                errors.append(
                    TokenError(
                        resource + " has an undefined resource_type" + ": \"" +
                        recipe_type + "\"", Token()))

    for recipe_type in recipe_types:
        if recipe_type not in used_recipe_types:
            errors.append(
                TokenError("Unused recipe_type \"" + recipe_type + "\"",
                           Token()))

    return errors
Ejemplo n.º 2
0
 def test_non_string_authors_error(self) -> None:
     errors = test_load("tests/non_string_authors.yaml")
     desired_errors: List[TokenError] = [
         TokenError("authors key should be a string not a <class 'int'>", Token(2, 2, 2, 4)),
         TokenError("authors value should be a string not a <class 'int'>", Token(2, 2, 6, 12))
     ]
     self.assertListEqual(errors, desired_errors)
Ejemplo n.º 3
0
 def test_invalid_raw_resource_error(self) -> None:
     errors = test_load("tests/invalid_raw_resource.yaml")
     desired_errors: List[TokenError] = [
         TokenError('MyResource has an invalid "Raw Resource"', Token(0, 0, 0, 0)),
         TokenError('MyResource must have a "Raw Resource" which outputs 1 and has a requirement of 0 of itself', Token(0, 0, 0, 0))
     ]
     self.assertListEqual(errors, desired_errors)
Ejemplo n.º 4
0
def lint_recipes(calculator_name: str, item_name: str,
                 recipes: List[Recipe]) -> List[TokenError]:
    errors: List[TokenError] = []

    # Check that every resource has a raw recipe
    raw_resource_count = 0
    for recipe in recipes:
        if (recipe.recipe_type == "Raw Resource"):
            if (recipe.output == 1
                    and recipe.requirements == OrderedDict([(item_name, 0)])):
                raw_resource_count += 1
            else:
                # TODO: Have a better token associated with this error
                errors.append(
                    TokenError(item_name + " has an invalid \"Raw Resource\"",
                               Token()))

    # Lint that every resource has a raw resource and only one
    if raw_resource_count == 0:
        # TODO: Have a better token associated with this error
        errors.append(
            TokenError(
                item_name +
                " must have a \"Raw Resource\" which outputs 1 and has a requirement of 0 of itself",
                Token()))
    elif raw_resource_count > 1:
        # TODO: Have a better token associated with this error
        errors.append(
            TokenError(item_name + " must have only one \"Raw Resource\"",
                       Token()))

    return errors
Ejemplo n.º 5
0
 def test_non_string_recipe_types(self) -> None:
     errors = test_load("tests/non_string_recipe_types.yaml")
     desired_errors: List[TokenError] = [
         TokenError("recipe_types key should be a string not a <class 'int'>", Token(9, 9, 2, 6)),
         TokenError("recipe_types value should be a string not a <class 'int'>", Token(9, 9, 8, 13)),
         TokenError('Unused recipe_type "-999"', Token(0, 0, 0, 0))
     ]
     self.assertListEqual(errors, desired_errors)
Ejemplo n.º 6
0
 def test_invalid_resource_list_key_error(self) -> None:
     errors = test_load("tests/invalid_resource_list_key.yaml")
     desired_errors: List[TokenError] = [
         TokenError(
             "Found Invalid ResourceList key, valid ResourceList keys are ['authors', 'index_page_display_name', 'recipe_types', 'stack_sizes', 'default_stack_size', 'resources', 'game_version', 'banner_message', 'requirement_groups', 'row_group_count']",
             Token(10, 10, 0, 16)
         )
     ]
     self.assertListEqual(errors, desired_errors)
Ejemplo n.º 7
0
def ensure_valid_requirements(
        resources: OrderedDict[str, Resource]) -> List[TokenError]:
    errors: List[TokenError] = []
    for resource in resources:
        for recipe in resources[resource].recipes:
            for requirement in recipe.requirements:
                if requirement not in resources:
                    # TODO: Have a better token associated with this error
                    errors.append(
                        TokenError(
                            "ERROR: Invalid requirement for resource:" +
                            resource + ". \"" + requirement +
                            "\" does not exist as a resource", Token()))
                elif recipe.requirements[requirement] > 0:
                    # TODO: Have a better token associated with this error
                    errors.append(
                        TokenError(
                            "ERROR: Invalid requirement for resource:" +
                            resource + ". \"" + requirement +
                            "\" must be a negative number", Token()))
    return errors
Ejemplo n.º 8
0
def lint_custom_stack_multipliers(
        calculator_name: str, item_name: str,
        custom_stack_multipliers: OrderedDict[str, int],
        stack_sizes: OrderedDict[str, StackSize]) -> List[TokenError]:
    errors: List[TokenError] = []
    for stack_name in custom_stack_multipliers:
        custom_size = custom_stack_multipliers[stack_name]

        if stack_name not in stack_sizes:
            # TODO: Have a better token associated with this error
            errors.append(
                TokenError(
                    "custom_stack_size \"" + stack_name + "\" for" +
                    item_name + "is not a valid stack size. (" +
                    ", ".join([x for x in stack_sizes]) + ")", Token()))

        if custom_size < 1:
            # TODO: Have a better token associated with this error
            errors.append(
                TokenError(
                    "custom_stack_size \"" + stack_name + "\" for" +
                    item_name + "cannot be less than 1.", Token()))

    return errors
Ejemplo n.º 9
0
def ensure_unique_simple_names(
        calculator_name: str,
        resources: OrderedDict[str, Resource]) -> List[TokenError]:
    errors: List[TokenError] = []
    simple_names: Dict[str, List[str]] = {}

    for resource in resources:
        simple_name: str = get_simple_name(resource, resources)
        if simple_name not in simple_names:
            simple_names[simple_name] = []
        simple_names[simple_name].append(resource)

    for simple_name in simple_names:
        if len(simple_names[simple_name]) > 1:
            # TODO: Have a better token associated with this error
            errors.append(
                TokenError(
                    ", ".join(simple_names[simple_name]) +
                    "all share the same simple name" + simple_name, Token()))

    return errors
Ejemplo n.º 10
0
 def test_non_string_index_display_name(self) -> None:
     errors = test_load("tests/non_string_index_display_name.yaml")
     desired_errors: List[TokenError] = [
         TokenError("index_page_display_name should be a string not a <class 'int'>", Token(5, 5, 25, 27))
     ]
     self.assertListEqual(errors, desired_errors)
Ejemplo n.º 11
0
 def test_invalid_requirement_count(self) -> None:
     errors = test_load("tests/invalid_requirement_count.yaml")
     desired_errors: List[TokenError] = [
         TokenError('ERROR: Invalid requirement for resource:MyResource. "MySubResource" must be a negative number', Token(0, 0, 0, 0))
     ]
     self.assertListEqual(errors, desired_errors)
Ejemplo n.º 12
0
 def test_invalid_requirement_name(self) -> None:
     errors = test_load("tests/invalid_requirement_name.yaml")
     desired_errors: List[TokenError] = [
         TokenError('ERROR: Invalid requirement for resource:MyResource. "MyMissingSubResource" does not exist as a resource', Token(0, 0, 0, 0))
     ]
     self.assertListEqual(errors, desired_errors)
Ejemplo n.º 13
0
 def test_unused_recipe_type(self) -> None:
     errors = test_load("tests/unused_recipe_type.yaml")
     desired_errors: List[TokenError] = [
         TokenError('Unused recipe_type "UnusedRecipeType"', Token(0, 0, 0, 0))
     ]
     self.assertListEqual(errors, desired_errors)
Ejemplo n.º 14
0
 def test_invalid_recipe_type(self) -> None:
     errors = test_load("tests/invalid_recipe_type.yaml")
     desired_errors: List[TokenError] = [
         TokenError('MyResource has an undefined resource_type: "UnkonwnRecipeType"', Token(0, 0, 0, 0))
     ]
     self.assertListEqual(errors, desired_errors)