Esempio n. 1
0
    def test_has_tzinfo(self):
        # No timezone
        now = datetime.datetime.now()
        tz_set = utils.has_tzinfo(now)
        self.assertEqual(False, tz_set)

        hastz = (
            datetime.datetime.now(tz=dateutil.tz.tzutc()),  # UTC
            dateutil.parser.parse('2015-04-14T16:10:50.658617Z'),  # Zulu
        )

        for ts in hastz:
            tz_set = utils.has_tzinfo(ts)
            self.assertEqual(True, tz_set)
Esempio n. 2
0
    def test_has_tzinfo(self):
        # No timezone
        now = datetime.datetime.now()
        tz_set = utils.has_tzinfo(now)
        self.assertEqual(False, tz_set)

        hastz = (
            datetime.datetime.now(tz=dateutil.tz.tzutc()),  # UTC
            dateutil.parser.parse('2015-04-14T16:10:50.658617Z'),  # Zulu
        )

        for ts in hastz:
            tz_set = utils.has_tzinfo(ts)
            self.assertEqual(True, tz_set)
    def _check_timestamp_usage(self, root, namespaces, selectors):
        """Inspects each node in `nodes` for correct timestamp use.

        """
        results = BestPracticeWarningCollection("Timestamp Use")
        xpath = " | ".join("//%s" % x for x in selectors)
        nodes = root.xpath(xpath, namespaces=namespaces)

        for node in nodes:
            attrib      = node.attrib.get
            id_         = attrib('id')
            idref       = attrib('idref')
            timestamp   = attrib('timestamp')

            if timestamp:
                tz_set = utils.has_tzinfo(timestamp)

                if not tz_set:
                    warning = BestPracticeWarning(
                        node = node,
                        message="Timestamp without timezone information."
                    )
                    warning['timestamp'] = timestamp
                    results.append(warning)

            if id_ and not timestamp:
                warning = BestPracticeWarning(
                    node=node,
                    message="ID present but missing timestamp"
                )
            elif idref and not timestamp:
                warning = BestPracticeWarning(
                    node=node,
                    message="IDREF present but missing timestamp"
                )
            elif idref and timestamp:
                resolves = common.idref_timestamp_resolves(
                    root=root,
                    idref=idref,
                    timestamp=timestamp,
                    namespaces=namespaces
                )

                if resolves:
                    continue

                warning = BestPracticeWarning(
                    node=node,
                    message="IDREF and timestamp combination do not resolve "
                            "to a node in the input document."
                )

                warning['timestamp'] = timestamp
            else:
                continue

            results.append(warning)

        return results
Esempio n. 4
0
    def _check_timestamp_usage(self, root, namespaces, selectors):
        """Inspects each node in `nodes` for correct timestamp use.

        """
        results = BestPracticeWarningCollection("Timestamp Use")
        xpath = " | ".join("//%s" % x for x in selectors)
        nodes = root.xpath(xpath, namespaces=namespaces)

        for node in nodes:
            attrib = node.attrib.get
            id_ = attrib('id')
            idref = attrib('idref')
            timestamp = attrib('timestamp')

            if timestamp:
                tz_set = utils.has_tzinfo(timestamp)

                if not tz_set:
                    warning = BestPracticeWarning(
                        node=node,
                        message="Timestamp without timezone information.")
                    warning['timestamp'] = timestamp
                    results.append(warning)

            if id_ and not timestamp:
                warning = BestPracticeWarning(
                    node=node, message="ID present but missing timestamp")
            elif idref and not timestamp:
                warning = BestPracticeWarning(
                    node=node, message="IDREF present but missing timestamp")
            elif idref and timestamp:
                resolves = common.idref_timestamp_resolves(
                    root=root,
                    idref=idref,
                    timestamp=timestamp,
                    namespaces=namespaces)

                if resolves:
                    continue

                warning = BestPracticeWarning(
                    node=node,
                    message="IDREF and timestamp combination do not resolve "
                    "to a node in the input document.")

                warning['timestamp'] = timestamp
            else:
                continue

            results.append(warning)

        return results