def test_make_intervals_closed(self):
        intervals = publishing.make_interval_list([
            {
                'timestamp': datetime(2018, 3, 5),
                'event': 'commissioned'
            },
            {
                'timestamp': datetime(2018, 3, 11),
                'event': 'decommissioned'
            },
            {
                'timestamp': datetime(2018, 4, 10),
                'event': 'commissioned'
            },
            {
                'timestamp': datetime(2018, 4, 15),
                'event': 'decommissioned'
            },
            {
                'timestamp': datetime(2018, 7, 20),
                'event': 'commissioned'
            },
            {
                'timestamp': datetime(2018, 7, 21),
                'event': 'retired'
            },
        ])

        self.assertEqual(intervals, [
            publishing.Interval(datetime(2018, 3, 5), datetime(2018, 3, 11)),
            publishing.Interval(datetime(2018, 4, 10), datetime(2018, 4, 15)),
            publishing.Interval(datetime(2018, 7, 20), datetime(2018, 7, 21)),
        ])
Example #2
0
    def test_make_intervals_open_union(self):
        intervals = publishing.make_interval_list([
            {'timestamp': datetime(2018, 3, 5), 'event': 'commissioned'},
            {'timestamp': datetime(2018, 3, 11), 'event': 'commissioned'},
        ])

        self.assertEqual(intervals, [
            publishing.Interval(datetime(2018, 3, 5), None),
        ])
Example #3
0
    def test_make_intervals_start_before_end(self):
        intervals = publishing.make_interval_list([
            {'timestamp': datetime(2018, 3, 1), 'event': 'decommissioned'},
            {'timestamp': datetime(2018, 3, 2), 'event': 'decommissioned'},
            {'timestamp': datetime(2018, 3, 5), 'event': 'commissioned'},
            {'timestamp': datetime(2018, 3, 17), 'event': 'decommissioned'},
        ])

        self.assertEqual(intervals, [
            publishing.Interval(datetime(2018, 3, 5), datetime(2018, 3, 17)),
        ])
Example #4
0
    def test_make_intervals_unordered(self):
        from itertools import permutations

        input_permutations = permutations([
            {'timestamp': datetime(2018, 3, 5), 'event': 'commissioned'},
            {'timestamp': datetime(2018, 4, 10), 'event': 'commissioned'},
            {'timestamp': datetime(2018, 7, 20), 'event': 'commissioned'},
            {'timestamp': datetime(2018, 3, 11), 'event': 'decommissioned'},
            {'timestamp': datetime(2018, 4, 15), 'event': 'decommissioned'},
            {'timestamp': datetime(2020, 1, 1), 'event': 'retired'},
        ])

        output_intervals = [
            publishing.Interval(datetime(2018, 3, 5), datetime(2018, 3, 11)),
            publishing.Interval(datetime(2018, 4, 10), datetime(2018, 4, 15)),
            publishing.Interval(datetime(2018, 7, 20), datetime(2020, 1, 1)),
        ]

        for p in input_permutations:
            self.assertEqual(publishing.make_interval_list(p), output_intervals)
Example #5
0
 def test_make_intervals_empty(self):
     self.assertEqual(publishing.make_interval_list([]), [])