# 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.utils.qgis_utils as qgis_utils
import psycopg2
from qgis.core import QgsDataSourceUri, QgsVectorLayer
from datetime import datetime
from .test_functionality import TestForLayersWithOnePointPerSecond
from nose.tools import raises
# if using ipython: do this on bash before
# export QT_API=pyqt




DBNAME = "gis"
TABLE = "pts"

GEOMETRY_COL = "geom"
DATE_COL = "_date"
DATE_TZ_COL = "_datetz"
EPOCH_COL = "epoch"
DATE_STR_COL = "datestr"
DATE_STR_COL_DMY = "datestr_dmy"

DATE_WITHOUT_TIME_COL = "date_without_time"

STARTTIME = time_util.datetime_to_epoch(datetime(2014, 12, 31, 23, 59, 59))

TZ_STATEMENT = "SET timezone='UTC';"

SQL_STATEMENT = """
DROP TABLE IF EXISTS {0:s};
CREATE TABLE {0:s} (

   {1:s} geometry,
   {2:s} timestamp, -- date with time of day without timezone
   {3:s} timestamp with time zone, -- has timezone in format +xx
   {4:s} integer,

# 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_postgresql.py
import sip
import unittest
import timemanager.utils.time_util as time_util
import timemanager.utils.qgis_utils as qgis_utils
import psycopg2
from qgis.core import QgsDataSourceUri, QgsVectorLayer
from datetime import datetime
from .test_functionality import TestForLayersWithOnePointPerSecond
from nose.tools import raises

# if using ipython: do this on bash before
# export QT_API=pyqt




DBNAME = "gis"
TABLE = "pts"

GEOMETRY_COL = "geom"
DATE_COL = "_date"
DATE_TZ_COL = "_datetz"
EPOCH_COL = "epoch"
DATE_STR_COL = "datestr"
DATE_STR_COL_DMY = "datestr_dmy"

DATE_WITHOUT_TIME_COL = "date_without_time"

STARTTIME = time_util.datetime_to_epoch(datetime(2014, 12, 31, 23, 59, 59))

TZ_STATEMENT = "SET timezone='UTC';"

SQL_STATEMENT = """
DROP TABLE IF EXISTS {0:s};
CREATE TABLE {0:s} (

   {1:s} geometry,
   {2:s} timestamp, -- date with time of day without timezone
   {3:s} timestamp with time zone, -- has timezone in format +xx
   {4:s} integer,

   {5:s} text,