def _get_result(self, primary_arg):
        ds = primary_arg

        score = 0
        messages = []

        # Check main variable is identifiable first
        try:
            variable = nc_util.get_main_variable(ds)
            score += 1
        except:
            messages = [self.get_messages()[score]]
            return Result(self.level, (score, self.out_of),
                          self.get_short_name(), messages)

        # Now check attribute
        attr_name = self.kwargs["attr_name"]

        if attr_name not in variable.ncattrs():
            messages = [self.get_messages()[score]]

        else:
            score += 1
            # Check the value of attribute

            expected_value = self.kwargs["attr_value"]
            check = nc_util.check_nc_attribute(variable, attr_name, expected_value)

            if check:
                score += 1
            else:
                messages.append(self.get_messages()[score])

        return Result(self.level, (score, self.out_of),
                      self.get_short_name(), messages)
    def _get_result(self, primary_arg):
        ds = primary_arg
        score = 0
        var_id = self._get_var_id(ds)

        # Check the variable first (will match if `var_id` is None from previous call)
        if var_id not in ds.variables:
            messages = self.get_messages()[:1]
            return Result(self.level, (score, self.out_of),
                          self.get_short_name(), messages)

        # Work out the overall 'out of' value based on number of attributes
        vocabs = ESSVocabs(*self.vocabulary_ref.split(":")[:2])
        lookup = ":".join([self.kwargs["pyessv_namespace"], var_id])
        expected_attr_dict = vocabs.get_value(lookup, "data")

        self.out_of = 1 + len(expected_attr_dict) * 2

        score += 1
        variable = ds.variables[var_id]
        messages = []

        # Check the variable attributes one-by-one
        for attr, expected_value in expected_attr_dict.items():

            # Check items to ignore
            ignores = self.kwargs["ignores"]

            if ignores and attr in ignores:
                self.out_of -= 2
                continue

            KNOWN_IGNORE_VALUES = ("<derived from file>",)

            if expected_value in KNOWN_IGNORE_VALUES:
                self.out_of -= 2
                continue

            if attr not in variable.ncattrs():
                messages.append("Required variable attribute '{}' is not present for "
                                "variable: '{}'.".format(attr, var_id))
            else:
                score += 1
                # Check the value of attribute
                check = nc_util.check_nc_attribute(variable, attr, expected_value)
                if check:
                    score += 1
                else:
                    messages.append(u"Required variable attribute '{}' has incorrect value ('{}') "
                                    u"for variable: '{}'. Value should be: '{}'.".format(attr,
                                                                                        getattr(variable, attr), var_id,
                                                                                        expected_value))

        return Result(self.level, (score, self.out_of),
                      self.get_short_name(), messages)
    def _get_result(self, primary_arg):
        ds = primary_arg
        dim_id = self.kwargs["dim_id"]
        ignore_coord_var_check = util._parse_boolean(self.kwargs["ignore_coord_var_check"])

        score = 0
        messages = []

        if dim_id in ds.dimensions:
            score += 1
            self.out_of = 1
        else:
            messages = [self.get_messages()[score],
                        "Cannot look up coordinate variable because dimension does not exist.",
                        "Cannot assess coordinate variable properties because dimension does not exist."]
            self.out_of = len(messages)

            # Now return because all other checks are irrelevant
            return Result(self.level, (score, self.out_of), self.get_short_name(), messages)

        # Now test coordinate variable using look-up in vocabularies
        # First, work out the overall 'out of' value based on number of attributes
        vocabs = ESSVocabs(*self.vocabulary_ref.split(":")[:2])
        lookup = ":".join([self.kwargs["pyessv_namespace"], dim_id])
        expected_attr_dict = vocabs.get_value(lookup, "data")

        # Check length if needed
        if "length" in expected_attr_dict:
            req_length = expected_attr_dict["length"]

            # If expected length is <i> or <n> etc then dimension length does
            # not matter, so give +1 without checking
            skip_check = req_length.startswith("<") and req_length.endswith(">")
            if skip_check or int(req_length) == ds.dimensions[dim_id].size:
                score += 1
            else:
                messages.append("Dimension '{}' does not have required length: {}.".format(dim_id, req_length))

            self.out_of += 1

        # Ignore coordinate variable check if instructed to
        if ignore_coord_var_check:
            pass
        # Check coordinate variable exists for dimension
        elif dim_id in ds.variables:
            score += 1
            self.out_of += 1

            variable = ds.variables[dim_id]

            # Check the coordinate variable attributes one-by-one
            for attr, expected_value in expected_attr_dict.items():
                # Length has already been checked - so ignore here
                if attr == "length": continue

                self.out_of += 1

                if attr not in variable.ncattrs():
                    messages.append("Required variable attribute '{}' is not present for "
                                    "coorinate variable: '{}'.".format(attr, dim_id))
                else:
                    score += 1
                    self.out_of += 1

                    # Check the value of attribute
                    check = nc_util.check_nc_attribute(variable, attr, expected_value)
                    if check:
                        score += 1
                    else:
                        messages.append("Required variable attribute '{}' has incorrect value ('{}') "
                                        "for variable: '{}'. Value should be: '{}'.".format(attr,
                                        getattr(variable, attr), dim_id, expected_value))
        # If coordinate variable not found
        else:
            messages.append("Coordinate variable for dimension not found: {}.".format(dim_id))
            self.out_of += 1

        return Result(self.level, (score, self.out_of), self.get_short_name(), messages)