Esempio n. 1
0
    def test_vector_with_int_timestamps(self):
        layer = Mock()
        layer.subsetString.return_value = ""
        layer.minimumValue.return_value = 60
        layer.maximumValue.return_value = 260
        layer.uniqueValues.return_value = [60, 260]
        settings = ls.LayerSettings()
        settings.layer = layer
        settings.startTimeAttribute = self.from_attr
        settings.endTimeAttribute = self.to_attr
        vector = TimeVectorLayer(settings, iface=Mock())

        assert (vector.getTimeFormat() == UTC)
        td = timedelta(minutes=5)
        currTime = datetime(1970, 1, 1, 0, 3, 0)
        vector.setTimeRestriction(currTime, td)
        layer.setSubsetString.assert_called_with(
            INT_FORMAT.format(self.from_attr, self.comparison_op,
                              datetime_to_epoch(currTime + td), self.to_attr,
                              datetime_to_epoch(currTime)))

        currTime = datetime(1980, 1, 1, 0, 0, 2)

        vector.setTimeRestriction(currTime, td)
        layer.setSubsetString.assert_called_with(
            INT_FORMAT.format(self.from_attr, self.comparison_op,
                              datetime_to_epoch(currTime + td), self.to_attr,
                              datetime_to_epoch(currTime)))
Esempio n. 2
0
    def test_vector(self):
        layer = Mock()
        layer.subsetString.return_value = ""
        layer.minimumValue.return_value = "1970-01-01 00:01:00"
        layer.maximumValue.return_value = "1970-01-01 00:04:20"
        layer.uniqueValues.return_value = [
            "1970-01-01 00:04:20", "1970-01-01 00:01:00"
        ]
        settings = ls.LayerSettings()
        settings.layer = layer
        settings.startTimeAttribute = self.from_attr
        settings.endTimeAttribute = self.to_attr

        vector = TimeVectorLayer(settings, iface=Mock())

        assert (vector.getTimeFormat() == DEFAULT_FORMAT)
        td = timedelta(minutes=5)
        vector.setTimeRestriction(datetime(1970, 1, 1, 0, 0, 2), td)
        layer.setSubsetString.assert_called_with(
            STRING_FORMAT.format(self.from_attr, self.comparison_op,
                                 "1970-01-01 00:05:02", self.to_attr,
                                 "1970-01-01 "
                                 "00:00:02"))

        vector.setTimeRestriction(datetime(1980, 1, 1, 0, 0, 2), td)
        layer.setSubsetString.assert_called_with(
            STRING_FORMAT.format(self.from_attr, self.comparison_op,
                                 "1980-01-01 00:05:02", self.to_attr,
                                 "1980-01-01 "
                                 "00:00:02"))
Esempio n. 3
0
    def test_vector_with_int_timestamps(self):
        layer = Mock()
        provider = Mock()
        layer.dataProvider.return_value = provider
        layer.subsetString.return_value = ""
        provider.minimumValue.return_value = 60
        provider.maximumValue.return_value = 260
        provider.storageType.return_value = 'PostgreSQL database with PostGIS extension'

        vector = TimeVectorLayer(layer,
                                 fromTimeAttribute=self.from_attr,
                                 toTimeAttribute=self.to_attr,
                                 enabled=True,
                                 timeFormat=DEFAULT_FORMAT,
                                 offset=0)

        assert (vector.getTimeFormat() == UTC)
        td = timedelta(minutes=5)
        currTime = datetime(1970, 1, 1, 0, 3, 0)
        vector.setTimeRestriction(currTime, td)
        layer.setSubsetString.assert_called_with(
            INT_FORMAT.format(self.from_attr, self.comparison_op,
                              datetime_to_epoch(currTime + td), self.to_attr,
                              datetime_to_epoch(currTime)))

        currTime = datetime(1980, 1, 1, 0, 0, 2)

        vector.setTimeRestriction(currTime, td)
        layer.setSubsetString.assert_called_with(
            INT_FORMAT.format(self.from_attr, self.comparison_op,
                              datetime_to_epoch(currTime + td), self.to_attr,
                              datetime_to_epoch(currTime)))
Esempio n. 4
0
    def test_vector(self):
        layer = Mock()
        provider = Mock()
        layer.dataProvider.return_value = provider
        layer.subsetString.return_value = ""
        provider.minimumValue.return_value = "1970-01-01 00:01:00"
        provider.maximumValue.return_value = "1970-01-01 00:04:20"
        provider.storageType.return_value = 'PostgreSQL database with PostGIS extension'

        vector = TimeVectorLayer(layer,
                                 fromTimeAttribute=self.from_attr,
                                 toTimeAttribute=self.to_attr,
                                 enabled=True,
                                 timeFormat=DEFAULT_FORMAT,
                                 offset=0)

        assert (vector.getTimeFormat() == DEFAULT_FORMAT)
        td = timedelta(minutes=5)
        vector.setTimeRestriction(datetime(1970, 1, 1, 0, 0, 2), td)
        layer.setSubsetString.assert_called_with(
            STRING_FORMAT.format(self.from_attr, self.comparison_op,
                                 "1970-01-01 00:05:02", self.to_attr,
                                 "1970-01-01 "
                                 "00:00:02"))

        vector.setTimeRestriction(datetime(1980, 1, 1, 0, 0, 2), td)
        layer.setSubsetString.assert_called_with(
            STRING_FORMAT.format(self.from_attr, self.comparison_op,
                                 "1980-01-01 00:05:02", self.to_attr,
                                 "1980-01-01 "
                                 "00:00:02"))
Esempio n. 5
0
    def test_vector_with_int_timestamps(self):
        layer = Mock()
        layer.subsetString.return_value = ""
        layer.minimumValue.return_value = 60
        layer.maximumValue.return_value = 260
        layer.uniqueValues.return_value = [60, 260]
        settings = ls.LayerSettings()
        settings.layer = layer
        settings.startTimeAttribute = self.from_attr
        settings.endTimeAttribute = self.to_attr
        vector = TimeVectorLayer(settings, iface=Mock())

        assert (vector.getTimeFormat() == UTC)
        td = timedelta(minutes=5)
        currTime = datetime(1970, 1, 1, 0, 3, 0)
        vector.setTimeRestriction(currTime, td)
        layer.setSubsetString.assert_called_with(INT_FORMAT.format(self.from_attr,
                                                                   self.comparison_op,
                                                                   datetime_to_epoch(
                                                                       currTime + td),
                                                                   self.to_attr,
                                                                   datetime_to_epoch(currTime)))

        currTime = datetime(1980, 1, 1, 0, 0, 2)

        vector.setTimeRestriction(currTime, td)
        layer.setSubsetString.assert_called_with(INT_FORMAT.format(self.from_attr,
                                                                   self.comparison_op,
                                                                   datetime_to_epoch(
                                                                       currTime + td),
                                                                   self.to_attr,
                                                                   datetime_to_epoch(
                                                                       currTime)))
Esempio n. 6
0
    def test_vector(self):
        layer = Mock()
        layer.subsetString.return_value = ""
        layer.minimumValue.return_value = "1970-01-01 00:01:00"
        layer.maximumValue.return_value = "1970-01-01 00:04:20"
        layer.uniqueValues.return_value = ["1970-01-01 00:04:20", "1970-01-01 00:01:00"]
        settings = ls.LayerSettings()
        settings.layer = layer
        settings.startTimeAttribute = self.from_attr
        settings.endTimeAttribute = self.to_attr

        vector = TimeVectorLayer(settings, iface=Mock())

        assert (vector.getTimeFormat() == DEFAULT_FORMAT)
        td = timedelta(minutes=5)
        vector.setTimeRestriction(datetime(1970, 1, 1, 0, 0, 2), td)
        layer.setSubsetString.assert_called_with(STRING_FORMAT.format(self.from_attr,
                                                                      self.comparison_op,
                                                                      "1970-01-01 00:05:02",
                                                                      self.to_attr, "1970-01-01 "
                                                                                    "00:00:02"))

        vector.setTimeRestriction(datetime(1980, 1, 1, 0, 0, 2), td)
        layer.setSubsetString.assert_called_with(STRING_FORMAT.format(self.from_attr,
                                                                      self.comparison_op,
                                                                      "1980-01-01 00:05:02",
                                                                      self.to_attr,
                                                                      "1980-01-01 "
                                                                      "00:00:02"))