Пример #1
0
    def test_add_list_of_interval(self):
        interval = Interval('test', ('PT0H', 'PT1H'))
        interval.interval = [('PT1H', 'PT2H')]

        assert interval.name == 'test'
        assert interval.start == ['PT0H', 'PT1H']
        assert interval.end == ['PT1H', 'PT2H']
Пример #2
0
    def test_to_hours_list(self):

        interval = Interval('test', [('PT0H', 'PT1H'), ('PT2H', 'PT3H'),
                                     ('PT5H', 'PT7H')])
        actual = interval.to_hours()

        assert actual == [(0, 1), (2, 3), (5, 7)]
Пример #3
0
    def test_convert_month_to_hours(self):
        interval = Interval('test', ('P1M', 'P2M'))
        actual = interval._convert_to_hours(interval.start)
        expected = 744
        assert actual == expected

        actual = interval._convert_to_hours(interval.end)
        expected = 1416
        assert actual == expected
Пример #4
0
    def test_convert_hour_to_hours(self):
        interval = Interval('test', ('PT0H', 'PT1H'))
        actual = interval._convert_to_hours(interval.start)
        expected = 0
        assert actual == expected

        actual = interval._convert_to_hours(interval.end)
        expected = 1
        assert actual == expected
Пример #5
0
    def test_convert_week_to_hours(self):
        interval = Interval('test', ('P2D', 'P3D'))
        actual = interval._convert_to_hours(interval.start)
        expected = 48
        assert actual == expected

        actual = interval._convert_to_hours(interval.end)
        expected = 72
        assert actual == expected
Пример #6
0
    def test_time_interval_start_before_end(get_time_intervals):
        with raises(ValueError) as excinfo:
            Interval('backwards', ('P1Y', 'P3M'))
        assert "A time interval must not end before it starts" in str(excinfo)

        interval = Interval('starts_ok', ('P0Y', 'P1M'))
        with raises(ValueError) as excinfo:
            interval.interval = ('P2M', 'P1M')
        assert "A time interval must not end before it starts" in str(excinfo)
Пример #7
0
    def test_equality(self):
        a = Interval('test', ('PT0H', 'PT1H'))
        b = Interval('test', ('PT0H', 'PT1H'))
        c = Interval('another_test', ('PT0H', 'PT1H'))
        d = Interval('another_test', ('PT1H', 'PT2H'))

        assert a == b
        assert a != c
        assert b != c
        assert c != d
Пример #8
0
    def test_load_multiple_interval(self):

        interval = Interval('test', [('PT0H', 'PT1H'), ('PT1H', 'PT2H')])

        assert interval.name == 'test'
        assert interval.start == ['PT0H', 'PT1H']
        assert interval.end == ['PT1H', 'PT2H']
Пример #9
0
    def test_load_interval(self):

        interval = Interval('test', ('PT0H', 'PT1H'))

        assert interval.name == 'test'
        assert interval.start == 'PT0H'
        assert interval.end == 'PT1H'
Пример #10
0
 def test_str_multiple_intervals(self):
     interval = Interval('test', [('PT0H', 'PT1H'), ('PT2H', 'PT3H'),
                                  ('PT5H', 'PT7H')])
     actual = str(interval)
     assert actual == \
         "Interval 'test' maps to:\n  hour 0 to hour 1\n  hour 2 to hour 3\n  "\
         "hour 5 to hour 7\n"
Пример #11
0
    def test_interval_loads(self):
        """Pass a time-interval definition into the register

        """
        data = [{'id': '1_1', 'start': 'PT0H', 'end': 'PT1H'}]

        register = TimeIntervalRegister()
        register.register(IntervalSet('energy_supply_hourly', data))
        assert register.names == ['energy_supply_hourly']

        actual = register.get_entry('energy_supply_hourly')

        element = Interval('1_1', ('PT0H', 'PT1H'), base_year=2010)
        expected = OrderedDict()
        expected['1_1'] = element

        assert actual.data == expected
Пример #12
0
    def test_interval_loads(self):
        """Pass a time-interval definition into the register

        """
        data = [{'name': '1_1', 'interval': [('PT0H', 'PT1H')]}]

        register = NDimensionalRegister()
        register.register(IntervalSet('energy_supply_hourly', data))
        assert register.names == ['energy_supply_hourly']

        actual = register.get_entry('energy_supply_hourly')

        element = Interval('1_1', ('PT0H', 'PT1H'), base_year=2010)
        expected = []
        expected.append(element)

        assert actual.data == expected
Пример #13
0
 def test_empty_interval_list_tuple(self):
     with raises(ValueError):
         Interval('test', [()])
Пример #14
0
    def test_months_load(self, months):
        """Pass a monthly time-interval definition into the register

        """
        register = TimeIntervalRegister()
        register.register(IntervalSet('months', months))

        actual = register.get_entry('months')

        expected_names = \
            ['1_0', '1_1', '1_2', '1_3', '1_4', '1_5',
             '1_6', '1_7', '1_8', '1_9', '1_10', '1_11']

        expected = [Interval('1_0', ('P0M', 'P1M')),
                    Interval('1_1', ('P1M', 'P2M')),
                    Interval('1_2', ('P2M', 'P3M')),
                    Interval('1_3', ('P3M', 'P4M')),
                    Interval('1_4', ('P4M', 'P5M')),
                    Interval('1_5', ('P5M', 'P6M')),
                    Interval('1_6', ('P6M', 'P7M')),
                    Interval('1_7', ('P7M', 'P8M')),
                    Interval('1_8', ('P8M', 'P9M')),
                    Interval('1_9', ('P9M', 'P10M')),
                    Interval('1_10', ('P10M', 'P11M')),
                    Interval('1_11', ('P11M', 'P12M'))]

        for name, interval in zip(expected_names, expected):
            assert actual.data[name] == interval
Пример #15
0
 def test_load_remap_timeslices(self):
     interval = Interval('1', [('P2M', 'P3M'),
                               ('P3M', 'P4M'),
                               ('P4M', 'P5M')])
     actual = interval.to_hours()
     assert actual == [(1416, 2160), (2160, 2880), (2880, 3624)]
Пример #16
0
 def test_repr(self):
     interval = Interval('test', ('P2M', 'P3M'), 2011)
     actual = repr(interval)
     assert actual == "Interval('test', [('P2M', 'P3M')], base_year=2011)"
Пример #17
0
 def test_str_one_interval(self):
     interval = Interval('test', ('P2M', 'P3M'))
     actual = str(interval)
     assert actual == \
         "Interval 'test' maps to:\n  hour 1416 to hour 2160\n"
Пример #18
0
    def test_to_hours_month(self):

        interval = Interval('test', ('P2M', 'P3M'))
        actual = interval.to_hours()

        assert actual == [(1416, 2160)]
Пример #19
0
    def test_to_hours_zero(self):

        interval = Interval('test', ('PT0H', 'PT1H'))
        actual = interval.to_hours()

        assert actual == [(0, 1)]
Пример #20
0
 def test_raise_error_load_illegal(self):
     with raises(ValueError):
         Interval('test', 'start', 'end')
Пример #21
0
 def test_invalid_set_interval(self):
     interval = Interval('test', ('PT0H', 'PT1H'))
     with raises(ValueError) as excinfo:
         interval.interval = None
     msg = "A time interval must add either a single tuple or a list of tuples"
     assert msg in str(excinfo)
Пример #22
0
    def test_months_load(self, months):
        """Pass a monthly time-interval definition into the register
        """
        register = NDimensionalRegister()
        register.register(IntervalSet('months', months))

        actual = register.get_entry('months')

        expected = [
            Interval('jan', ('P0M', 'P1M')),
            Interval('feb', ('P1M', 'P2M')),
            Interval('mar', ('P2M', 'P3M')),
            Interval('apr', ('P3M', 'P4M')),
            Interval('may', ('P4M', 'P5M')),
            Interval('jun', ('P5M', 'P6M')),
            Interval('jul', ('P6M', 'P7M')),
            Interval('aug', ('P7M', 'P8M')),
            Interval('sep', ('P8M', 'P9M')),
            Interval('oct', ('P9M', 'P10M')),
            Interval('nov', ('P10M', 'P11M')),
            Interval('dec', ('P11M', 'P12M'))
        ]

        for idx, interval in enumerate(expected):
            assert actual.data[idx] == interval