# Path: test/test_functionality.py
# class TestForLayersWithOnePointPerSecond(with_metaclass(ABCMeta, TestWithQGISLauncher)):
#     """This class tests the functionality of layers for data that contains one point per second
#     (our own convention to not have to write similar test code a lot of times). See the
#     postgresql and delimited text tests for examples"""
# 
#     @abstractmethod
#     def get_start_time(self):
#         """Get first timestamp in epoch seconds"""
#         pass
# 
#     def _test_layer(self, layer, attr, typ, tf, attr2=None):
#         if attr2 is None:
#             attr2 = attr
#         settings = ls.LayerSettings()
#         settings.layer = layer
#         settings.startTimeAttribute = attr
#         settings.endTimeAttribute = attr2
#         iface = Mock()
#         timeLayer = timevectorlayer.TimeVectorLayer(settings, iface)
#         # TODO
#         # self.assertEqual(settings, ls.getSettingsFromLayer(timeLayer))
#         self.tlm.registerTimeLayer(timeLayer)
#         self.assertEquals(len(self.tlm.getActiveVectors()), 1)
#         self.assertEquals(len(self.tlm.getActiveRasters()), 0)
#         self.assertEquals(timeLayer.getDateType(), typ)
#         if tf is not None:
#             self.assertEquals(timeLayer.getTimeFormat(), tf)
#         expected_datetime = time_util.epoch_to_datetime(self.get_start_time())
#         self.assertEquals(self.tlm.getCurrentTimePosition(), expected_datetime)
#         self.tlm.setTimeFrameType("seconds")
#         self.assertEquals(layer.featureCount(), 1)
#         self.assertEquals(self.tlm.getCurrentTimePosition(), expected_datetime)
#         self.tlm.stepForward()
#         self.assertEquals(layer.featureCount(), 1)
#         expected_datetime = time_util.epoch_to_datetime(self.get_start_time() + 1)
#         self.assertEquals(self.tlm.getCurrentTimePosition(), expected_datetime)
#         self.tlm.setTimeFrameSize(2)
#         self.assertEquals(layer.featureCount(), 2)


import sip
import unittest
import timemanager.utils.time_util as time_util
import timemanager.layers.timevectorlayer as timevectorlayer
import timemanager.layers.layer_settings as ls
import os
import tempfile
import shutil
import glob
from qgis.core import QgsVectorLayer
from mock import Mock
from .test_functionality import TestForLayersWithOnePointPerSecond
from timemanager.conf import FRAME_FILENAME_PREFIX
    def get_start_time(self):
        return STARTTIME

    def setUp(self):
        super(TestDelimitedText, self).setUp()
        self.file = tempfile.NamedTemporaryFile(mode="r", delete=False)
        with open(self.file.name, 'w') as f:
            f.write(TEXT)
        # Very good info on creating layers programmatically from the official docs
        # http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/loadlayer.html
        uri = "file:///{}?&delimiter=,&xField={}&yField={}&spatialIndex=no&subsetIndex=no&watchFile=no" \
              "".format(self.file.name, LON_COL, LAT_COL)
        self.layer = QgsVectorLayer(uri, "jumping_points", 'delimitedtext')
        self.assertTrue(self.layer.isValid())
        self.assertEquals(self.layer.featureCount(), 6)

    def tearDown(self):
        super(TestDelimitedText, self).tearDown()
        os.remove(self.file.name)

    def test_date_str(self):
        self._test_layer(self.layer, DATE_COL, time_util.DateTypes.DatesAsStrings,
                         DFT)
        self.assertEquals(len(self.tlm.getActiveDelimitedText()), 1)

    def test_export_exports_last_frame(self):
        settings = ls.LayerSettings()
        settings.layer = self.layer
        settings.startTimeAttribute = DATE_COL
        settings.endTimeAttribute = DATE_COL

# Path: test/test_functionality.py
# class TestForLayersWithOnePointPerSecond(with_metaclass(ABCMeta, TestWithQGISLauncher)):
#     """This class tests the functionality of layers for data that contains one point per second
#     (our own convention to not have to write similar test code a lot of times). See the
#     postgresql and delimited text tests for examples"""
# 
#     @abstractmethod
#     def get_start_time(self):
#         """Get first timestamp in epoch seconds"""
#         pass
# 
#     def _test_layer(self, layer, attr, typ, tf, attr2=None):
#         if attr2 is None:
#             attr2 = attr
#         settings = ls.LayerSettings()
#         settings.layer = layer
#         settings.startTimeAttribute = attr
#         settings.endTimeAttribute = attr2
#         iface = Mock()
#         timeLayer = timevectorlayer.TimeVectorLayer(settings, iface)
#         # TODO
#         # self.assertEqual(settings, ls.getSettingsFromLayer(timeLayer))
#         self.tlm.registerTimeLayer(timeLayer)
#         self.assertEquals(len(self.tlm.getActiveVectors()), 1)
#         self.assertEquals(len(self.tlm.getActiveRasters()), 0)
#         self.assertEquals(timeLayer.getDateType(), typ)
#         if tf is not None:
#             self.assertEquals(timeLayer.getTimeFormat(), tf)
#         expected_datetime = time_util.epoch_to_datetime(self.get_start_time())
#         self.assertEquals(self.tlm.getCurrentTimePosition(), expected_datetime)
#         self.tlm.setTimeFrameType("seconds")
#         self.assertEquals(layer.featureCount(), 1)
#         self.assertEquals(self.tlm.getCurrentTimePosition(), expected_datetime)
#         self.tlm.stepForward()
#         self.assertEquals(layer.featureCount(), 1)
#         expected_datetime = time_util.epoch_to_datetime(self.get_start_time() + 1)
#         self.assertEquals(self.tlm.getCurrentTimePosition(), expected_datetime)
#         self.tlm.setTimeFrameSize(2)
#         self.assertEquals(layer.featureCount(), 2)


# Path: test/test_with_delimited_text.py
import sip
import unittest
import timemanager.utils.time_util as time_util
import timemanager.layers.timevectorlayer as timevectorlayer
import timemanager.layers.layer_settings as ls
import os
import tempfile
import shutil
import glob
from qgis.core import QgsVectorLayer
from mock import Mock
from .test_functionality import TestForLayersWithOnePointPerSecond
from timemanager.conf import FRAME_FILENAME_PREFIX

    def get_start_time(self):
        return STARTTIME

    def setUp(self):
        super(TestDelimitedText, self).setUp()
        self.file = tempfile.NamedTemporaryFile(mode="r", delete=False)
        with open(self.file.name, 'w') as f:
            f.write(TEXT)
        # Very good info on creating layers programmatically from the official docs
        # http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/loadlayer.html
        uri = "file:///{}?&delimiter=,&xField={}&yField={}&spatialIndex=no&subsetIndex=no&watchFile=no" \
              "".format(self.file.name, LON_COL, LAT_COL)
        self.layer = QgsVectorLayer(uri, "jumping_points", 'delimitedtext')
        self.assertTrue(self.layer.isValid())
        self.assertEquals(self.layer.featureCount(), 6)

    def tearDown(self):
        super(TestDelimitedText, self).tearDown()
        os.remove(self.file.name)

    def test_date_str(self):
        self._test_layer(self.layer, DATE_COL, time_util.DateTypes.DatesAsStrings,
                         DFT)
        self.assertEquals(len(self.tlm.getActiveDelimitedText()), 1)

    def test_export_exports_last_frame(self):
        settings = ls.LayerSettings()
        settings.layer = self.layer
        settings.startTimeAttribute = DATE_COL
        settings.endTimeAttribute = DATE_COL

        iface = Mock()