Exemplo n.º 1
0
 def test_get_with_restrictive_interval_with_tzs(self):
     start = datetime.datetime(2012, 7, 13, 10, tzinfo=utils.UTC(10))
     end = datetime.datetime(2012, 7, 13, 20, tzinfo=utils.UTC(10))
     channel_data = self.archiver.get('EXAMPLE:DOUBLE_SCALAR',
                                      start,
                                      end,
                                      interpolation=codes.interpolation.RAW)
     self.assertEqual(channel_data.values, [199.9, 198.7])
     self.assertEqual(channel_data.times, [
         datetime.datetime(2012, 7, 13, 2, 5, 1, 443589, utc),
         datetime.datetime(2012, 7, 13, 7, 19, 31, 806097, utc)
     ])
     self.assertEqual(repr(channel_data.times[0].tzinfo), 'UTC(+10)')
Exemplo n.º 2
0
def test_get_with_restrictive_interval_with_tzs(archiver):
    start = datetime(2012, 7, 13, 10, tzinfo=utils.UTC(10))
    end = datetime(2012, 7, 13, 20, tzinfo=utils.UTC(10))
    channel_data = archiver.get("EXAMPLE:DOUBLE_SCALAR",
                                start,
                                end,
                                interpolation=codes.interpolation.RAW)
    assert channel_data.values == [199.9, 198.7]
    assert channel_data.times == [
        datetime(2012, 7, 13, 2, 5, 1, 443589, utc),
        datetime(2012, 7, 13, 7, 19, 31, 806097, utc),
    ]
    assert repr(channel_data.times[0].tzinfo) == "UTC(+10)"
Exemplo n.º 3
0
 def test_get_scalar_in_tz(self):
     start = datetime.datetime(2012, 1, 1, tzinfo=utc)
     end = datetime.datetime(2013, 1, 1, tzinfo=utc)
     data = self.archiver.get('EXAMPLE:DOUBLE_SCALAR{TD:1}',
                              start,
                              end,
                              interpolation=codes.interpolation.RAW,
                              tz=utils.UTC(11.5))
     self.assertEqual(str(data.times[0].tzinfo), 'UTC+11:30')
     self.assertEqual(repr(data.times[0].tzinfo), 'UTC(+11.5)')
Exemplo n.º 4
0
def test_get_scalar_in_tz(archiver):
    start = datetime(2012, 1, 1, tzinfo=utc)
    end = datetime(2013, 1, 1, tzinfo=utc)
    data = archiver.get(
        "EXAMPLE:DOUBLE_SCALAR",
        start,
        end,
        interpolation=codes.interpolation.RAW,
        tz=utils.UTC(11.5),
    )
    assert str(data.times[0].tzinfo) == "UTC+11:30"
    assert repr(data.times[0].tzinfo) == "UTC(+11.5)"
Exemplo n.º 5
0
    def setUp(self):

        values = [200.5, 199.9, 198.7, 196.1]
        times = [
            datetime.datetime(2012, 7, 12, 21, 47, 23, 664000, utc),
            datetime.datetime(2012, 7, 13, 2, 5, 1, 443589, utc),
            datetime.datetime(2012, 7, 13, 7, 19, 31, 806097, utc),
            datetime.datetime(2012, 7, 13, 11, 18, 55, 671259, utc)
        ]

        self.scalar_channel = ChannelData(
            channel='EXAMPLE:DOUBLE_SCALAR{TD:1}',
            values=values,
            times=times,
            statuses=[0, 6, 6, 5],
            severities=[0, 1, 1, 2],
            units='mA',
            states=None,
            data_type=codes.data_type.DOUBLE,
            elements=1,
            display_limits=Limits(0, 220),
            warn_limits=Limits(199, 210),
            alarm_limits=Limits(198, 220),
            display_precision=3,
            archive_key=1001)
        array_values = [[
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
            19
        ],
                        [
                            100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89,
                            88, 87, 86, 85, 84, 83, 82, 81
                        ]]
        tz = utils.UTC(10)
        array_times = [
            datetime.datetime(2012, 7, 12, 21, 47, 23, 664000, tz),
            datetime.datetime(2012, 7, 13, 2, 5, 1, 443589, tz)
        ]

        self.array_channel = ChannelData(channel='EXAMPLE:DOUBLE_SCALAR{TD:1}',
                                         values=array_values,
                                         times=array_times,
                                         statuses=[0, 6],
                                         severities=[0, 1],
                                         units='mA',
                                         states=None,
                                         data_type=codes.data_type.DOUBLE,
                                         elements=20,
                                         display_limits=Limits(0, 220),
                                         warn_limits=Limits(199, 210),
                                         alarm_limits=Limits(198, 220),
                                         display_precision=3,
                                         archive_key=1001)
def array_channel():
    array_values = [
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
        [
            100,
            99,
            98,
            97,
            96,
            95,
            94,
            93,
            92,
            91,
            90,
            89,
            88,
            87,
            86,
            85,
            84,
            83,
            82,
            81,
        ],
    ]
    tz = utils.UTC(10)
    array_times = [
        datetime.datetime(2012, 7, 12, 21, 47, 23, 664000, tz),
        datetime.datetime(2012, 7, 13, 2, 5, 1, 443589, tz),
    ]
    return ChannelData(
        channel="EXAMPLE:DOUBLE_SCALAR",
        values=array_values,
        times=array_times,
        statuses=[0, 6],
        severities=[0, 1],
        units="mA",
        states=None,
        data_type=codes.data_type.DOUBLE,
        elements=20,
        display_limits=Limits(0, 220),
        warn_limits=Limits(199, 210),
        alarm_limits=Limits(198, 220),
        display_precision=3,
        archive_key=1001,
    )
Exemplo n.º 7
0
 def test_datetime_isoformat_with_tz(self):
     iso_str = '2013-08-07 10:21:55.012345+08'
     dt = utils.datetime_from_isoformat(iso_str)
     self.assertEqual(
         dt, datetime.datetime(2013, 8, 7, 10, 21, 55, 12345, utils.UTC(8)))
Exemplo n.º 8
0
def test_utc_with_offset_seconds():
    hours = 23 + 15. / 60. + 8. / 3600.
    tz = utils.UTC(hours)
    assert tz.tzname() == "UTC+23:15:08"
    assert repr(tz) == "UTC(+23.252222)"
Exemplo n.º 9
0
 def test_utc_with_negative_offset(self):
     hours = -(6 + 45. / 60.)
     tz = utils.UTC(hours)
     self.assertEqual(tz.tzname(), 'UTC-06:45')
     self.assertEqual(repr(tz), 'UTC(-6.75)')
Exemplo n.º 10
0
 def test_utc_with_offset_seconds(self):
     hours = 23 + 15. / 60. + 8. / 3600.
     tz = utils.UTC(hours)
     self.assertEqual(tz.tzname(), 'UTC+23:15:08')
     self.assertEqual(repr(tz), 'UTC(+23.252222)')
Exemplo n.º 11
0
 def test_utc(self):
     tz = utils.UTC()
     self.assertEqual(tz.tzname(), 'UTC')
     self.assertEqual(repr(tz), 'UTC()')
Exemplo n.º 12
0
 def test_utc_with_offset(self):
     hours = 6 + 3. / 60.
     tz = utils.UTC(hours)
     self.assertEqual(tz.tzname(), 'UTC+06:03')
     self.assertEqual(repr(tz), 'UTC(+6.05)')
Exemplo n.º 13
0
 def test_datetime_isoformat_no_secs_tz(self):
     iso_str = '2013-08-07 10:21-09:00'
     dt = utils.datetime_from_isoformat(iso_str)
     self.assertEqual(
         dt, datetime.datetime(2013, 8, 7, 10, 21, 0, 0, utils.UTC(-9)))
Exemplo n.º 14
0
def test_datetime_isoformat_no_secs_tz():
    iso_str = "2013-08-07 10:21-09:00"
    dt = utils.datetime_from_isoformat(iso_str)
    assert dt == datetime(2013, 8, 7, 10, 21, 0, 0, utils.UTC(-9))
Exemplo n.º 15
0
def test_utc():
    tz = utils.UTC()
    assert tz.tzname() == "UTC"
    assert repr(tz) == "UTC()"
Exemplo n.º 16
0
def test_utc_with_negative_offset():
    hours = -(6 + 45. / 60.)
    tz = utils.UTC(hours)
    assert tz.tzname() == "UTC-06:45"
    assert repr(tz) == "UTC(-6.75)"
Exemplo n.º 17
0
def test_utc_with_offset():
    hours = 6 + 3. / 60.
    tz = utils.UTC(hours)
    assert tz.tzname() == "UTC+06:03"
    assert repr(tz) == "UTC(+6.05)"
Exemplo n.º 18
0
import unittest
import datetime
from channelarchiver import Archiver, utils
from tests.mock_archiver import MockArchiver
import nose

utc = utils.UTC()
local_tz = utils.local_tz


class TestArchiverPlot(unittest.TestCase):
    def setUp(self):
        self.archiver = Archiver(
            'https://xf23id-ca/cgi-bin/ArchiveDataServer.cgi')
        self.archiver.archiver = MockArchiver()

    def test_plot(self):
        try:
            import matplotlib
        except ImportError:
            raise nose.SkipTest("This tests featuring requiring matplotlib.")
        from channelarchiver import plot_channels
        start = datetime.datetime(2012, 1, 1, tzinfo=utc)
        end = datetime.datetime(2013, 1, 1, tzinfo=utc)
        plot_channels.plot(self.archiver, 'EXAMPLE:DOUBLE_SCALAR{TD:1}',
                           'EXAMPLE:INT_WAVEFORM', start, end)


if __name__ == '__main__':
    unittest.main()
Exemplo n.º 19
0
def test_datetime_isoformat_with_short_tz():
    iso_str = "2013-08-07 10:21:55.012345+08"
    dt = utils.datetime_from_isoformat(iso_str)
    assert dt == datetime(2013, 8, 7, 10, 21, 55, 12345, utils.UTC(8))