Exemple #1
0
    def test_data_accessors(self):
        """methods to get metadata and such."""
        self.assertEqual(self._canned_wire_series.name(), 'traffic')
        self.assertTrue(self._canned_wire_series.is_utc())

        # index stuff
        self.assertEqual(self._canned_index_series.index_as_string(),
                         INDEXED_DATA.get('index'))
        self.assertTrue(isinstance(self._canned_index_series.index(), Index))
        self.assertEqual(self._canned_index_series.index_as_range().to_json(),
                         [54000000000, 54086400000])

        self.assertEqual(self._canned_wire_series.meta(), {
            'utc': True,
            'name': 'traffic'
        })

        self.assertEqual(self._canned_wire_series.meta('name'), 'traffic')

        self.assertEqual(len(list(self._canned_wire_series.events())), 4)
        self.assertEqual(self._canned_event_series.collection(),
                         self._canned_event_series._collection)  # pylint: disable=protected-access

        self.assertEqual(self._canned_event_series.size_valid('in'), 3)

        # at_first() and at_last() and at_time()
        self.assertTrue(
            Event.same(self._canned_event_series.at_first(), EVENT_LIST[0]))
        self.assertTrue(
            Event.same(self._canned_event_series.at_last(), EVENT_LIST[2]))

        ref_dtime = EVENT_LIST[1].timestamp() + datetime.timedelta(seconds=3)
        self.assertTrue(
            Event.same(self._canned_event_series.at_time(ref_dtime),
                       EVENT_LIST[1]))
Exemple #2
0
    def test_data_accessors(self):
        """methods to get metadata and such."""
        self.assertEqual(self._canned_wire_series.name(), 'traffic')
        self.assertTrue(self._canned_wire_series.is_utc())

        # index stuff
        self.assertEqual(
            self._canned_index_series.index_as_string(),
            INDEXED_DATA.get('index'))
        self.assertTrue(isinstance(self._canned_index_series.index(), Index))
        self.assertEqual(
            self._canned_index_series.index_as_range().to_json(),
            [54000000000, 54086400000])

        self.assertEqual(
            self._canned_wire_series.meta(),
            {'utc': True, 'name': 'traffic'})

        self.assertEqual(self._canned_wire_series.meta('name'), 'traffic')

        self.assertEqual(len(list(self._canned_wire_series.events())), 4)
        self.assertEqual(
            self._canned_event_series.collection(),
            self._canned_event_series._collection)  # pylint: disable=protected-access

        self.assertEqual(self._canned_event_series.size_valid('in'), 3)

        # at_first() and at_last() and at_time()
        self.assertTrue(Event.same(self._canned_event_series.at_first(), EVENT_LIST[0]))
        self.assertTrue(Event.same(self._canned_event_series.at_last(), EVENT_LIST[2]))

        ref_dtime = EVENT_LIST[1].timestamp() + datetime.timedelta(seconds=3)
        self.assertTrue(Event.same(self._canned_event_series.at_time(ref_dtime),
                                   EVENT_LIST[1]))
Exemple #3
0
    def test_event_same(self):
        """test Event.same() static method."""
        ev1 = copy.copy(self.canned_event)
        ev2 = copy.copy(self.canned_event)
        self.assertTrue(Event.same(ev1, ev2))

        # make a new one with same data but new timestamp.
        ev3 = Event(freeze(dict(time=self.aware_ts, data=ev1.data())))
        self.assertFalse(Event.same(ev1, ev3))
Exemple #4
0
    def test_event_same(self):
        """test Event.same() static method."""
        ev1 = copy.copy(self.canned_event)
        ev2 = copy.copy(self.canned_event)
        self.assertTrue(Event.same(ev1, ev2))

        # make a new one with same data but new timestamp.
        ev3 = Event(freeze(dict(time=self.aware_ts, data=ev1.data())))
        self.assertFalse(Event.same(ev1, ev3))
Exemple #5
0
    def test_mutators(self):
        """test collection mutation."""

        extra_event = Event(1429673580000, {'in': 7, 'out': 8})

        new_coll = self._canned_collection.add_event(extra_event)
        self.assertEqual(new_coll.size(), 4)

        # test slice() here since this collection is longer.
        sliced = new_coll.slice(1, 3)
        self.assertEqual(sliced.size(), 2)
        self.assertTrue(Event.same(sliced.at(0), EVENT_LIST[1]))

        # work stddev as well
        self.assertEqual(new_coll.stdev('in'), 2.23606797749979)
        self.assertEqual(new_coll.median('in'), 4)
Exemple #6
0
    def test_mutators(self):
        """test collection mutation."""

        extra_event = Event(1429673580000, {'in': 7, 'out': 8})

        new_coll = self._canned_collection.add_event(extra_event)
        self.assertEqual(new_coll.size(), 4)

        # test slice() here since this collection is longer.
        sliced = new_coll.slice(1, 3)
        self.assertEqual(sliced.size(), 2)
        self.assertTrue(Event.same(sliced.at(0), EVENT_LIST[1]))

        # work stddev as well
        self.assertEqual(new_coll.stdev('in'), 2.23606797749979)
        self.assertEqual(new_coll.median('in'), 4)
Exemple #7
0
    def test_slices_and_permutations(self):
        """methods that slice/etc the underlying series."""

        # bisect
        search = dt_from_ms(1400425949000 + 30)
        bsect_idx = self._canned_wire_series.bisect(search)

        # bisect with bad arg
        bad_search = datetime.datetime.now()
        with self.assertRaises(CollectionException):
            self._canned_wire_series.bisect(bad_search)

        bsection = self._canned_wire_series.at(bsect_idx)
        self.assertEqual(bsection.data().get('status'), 'fail')

        # clean
        self.assertEqual(self._canned_event_series.clean('in').size(), 3)
        self.assertEqual(self._canned_event_series.clean('bogus_value').size(), 0)

        # slice
        sliced = self._canned_event_series.slice(1, 3)
        self.assertEqual(sliced.size(), 2)
        self.assertTrue(Event.same(sliced.at(0), EVENT_LIST[1]))
Exemple #8
0
    def test_accessor_methods(self):
        """test various access methods. Mostly for coverage."""

        col = self._canned_collection

        # basic accessors
        self.assertEqual(col.to_json(), EVENT_LIST)

        self.assertEqual(len(json.loads(col.to_string())), 3)

        # test at() - corollary to array index
        self.assertTrue(Event.same(col.at(2), EVENT_LIST[2]))

        # overshoot
        with self.assertRaises(CollectionException):
            col.at(5)

        # test at_time()
        # get timestamp of second event and add some time to it
        ref_dtime = EVENT_LIST[1].timestamp() + datetime.timedelta(seconds=3)
        self.assertTrue(Event.same(col.at_time(ref_dtime), EVENT_LIST[1]))

        # overshoot the end of the list for coverage
        ref_dtime = EVENT_LIST[2].timestamp() + datetime.timedelta(seconds=3)
        self.assertTrue(Event.same(col.at_time(ref_dtime), EVENT_LIST[2]))

        # make sure returning index 0 works
        ref_dtime = EVENT_LIST[0].timestamp() + datetime.timedelta(seconds=3)
        self.assertTrue(Event.same(col.at_time(ref_dtime), EVENT_LIST[0]))

        # hit dead on for coverage
        self.assertEqual(col.at_time(EVENT_LIST[1].timestamp()).get('in'), 3)

        # empty collection for coverage
        empty_coll = Collection(col, copy_events=False)
        self.assertIsNone(empty_coll.at_time(ref_dtime))

        # at_first() and at_last()
        self.assertTrue(Event.same(col.at_first(), EVENT_LIST[0]))
        self.assertTrue(Event.same(col.at_last(), EVENT_LIST[2]))

        # get the raw event list
        self.assertTrue(is_pvector(col.event_list()))
        self.assertTrue(isinstance(col.event_list_as_list(), list))
Exemple #9
0
    def test_accessor_methods(self):
        """test various access methods. Mostly for coverage."""

        col = self._canned_collection

        # basic accessors
        self.assertEqual(col.to_json(), EVENT_LIST)

        self.assertEqual(len(json.loads(col.to_string())), 3)

        # test at() - corollary to array index
        self.assertTrue(Event.same(col.at(2), EVENT_LIST[2]))

        # overshoot
        with self.assertRaises(CollectionException):
            col.at(5)

        # test at_time()
        # get timestamp of second event and add some time to it
        ref_dtime = EVENT_LIST[1].timestamp() + datetime.timedelta(seconds=3)
        self.assertTrue(Event.same(col.at_time(ref_dtime), EVENT_LIST[1]))

        # overshoot the end of the list for coverage
        ref_dtime = EVENT_LIST[2].timestamp() + datetime.timedelta(seconds=3)
        self.assertTrue(Event.same(col.at_time(ref_dtime), EVENT_LIST[2]))

        # make sure returning index 0 works
        ref_dtime = EVENT_LIST[0].timestamp() + datetime.timedelta(seconds=3)
        self.assertTrue(Event.same(col.at_time(ref_dtime), EVENT_LIST[0]))

        # hit dead on for coverage
        self.assertEqual(col.at_time(EVENT_LIST[1].timestamp()).get('in'), 3)

        # empty collection for coverage
        empty_coll = Collection(col, copy_events=False)
        self.assertIsNone(empty_coll.at_time(ref_dtime))

        # at_first() and at_last()
        self.assertTrue(Event.same(col.at_first(), EVENT_LIST[0]))
        self.assertTrue(Event.same(col.at_last(), EVENT_LIST[2]))

        # get the raw event list
        self.assertTrue(is_pvector(col.event_list()))
        self.assertTrue(isinstance(col.event_list_as_list(), list))
Exemple #10
0
    def test_slices_and_permutations(self):
        """methods that slice/etc the underlying series."""

        # bisect
        search = dt_from_ms(1400425949000 + 30)
        bsect_idx = self._canned_wire_series.bisect(search)

        # bisect with bad arg
        bad_search = datetime.datetime.now()
        with self.assertRaises(CollectionException):
            self._canned_wire_series.bisect(bad_search)

        bsection = self._canned_wire_series.at(bsect_idx)
        self.assertEqual(bsection.data().get('status'), 'fail')

        # clean
        self.assertEqual(self._canned_event_series.clean('in').size(), 3)
        self.assertEqual(
            self._canned_event_series.clean('bogus_value').size(), 0)

        # slice
        sliced = self._canned_event_series.slice(1, 3)
        self.assertEqual(sliced.size(), 2)
        self.assertTrue(Event.same(sliced.at(0), EVENT_LIST[1]))
Exemple #11
0
    def test_event_series(self):
        """test a series that contains basic event objects."""
        event_series = dict(
            name="traffic",
            columns=["time", "value", "status"],
            points=[
                [1400425947000, 52, "ok"],
                [1400425948000, 18, "ok"],
                [1400425949000, 26, "fail"],
                [1400425950000, 93, "offline"]
            ]
        )

        series = TimeSeries(event_series)

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)
        new_json = new_series.to_json()

        self._validate_wire_points(event_series, new_json)
        self.assertTrue(new_json.get('utc'))

        # try something a bit fancier with different types
        interface_series = dict(
            name="star-cr5:to_anl_ip-a_v4",
            description="star-cr5->anl(as683):100ge:site-ex:show:intercloud",
            device="star-cr5",
            id=169,
            interface="to_anl_ip-a_v4",
            is_ipv6=False,
            is_oscars=False,
            oscars_id=None,
            resource_uri="",
            site="anl",
            site_device="noni",
            site_interface="et-1/0/0",
            stats_type="Standard",
            title=None,
            columns=["time", "in", "out"],
            points=[
                [1400425947000, 52, 34],
                [1400425948000, 18, 13],
                [1400425949000, 26, 67],
                [1400425950000, 93, 91]
            ]
        )

        series = TimeSeries(interface_series)

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)
        new_json = new_series.to_json()

        self._validate_wire_points(interface_series, new_json)

        # Now with a list of events

        event_objects = [
            Event(1429673400000, {'in': 1, 'out': 2}),
            Event(1429673460000, {'in': 3, 'out': 4}),
            Event(1429673520000, {'in': 5, 'out': 6}),
        ]

        series = TimeSeries(dict(name='events', events=event_objects))

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)

        for i in enumerate(event_objects):
            self.assertTrue(Event.same(i[1], new_series.at(i[0])))
Exemple #12
0
    def test_event_series(self):
        """test a series that contains basic event objects."""
        event_series = dict(name="traffic",
                            columns=["time", "value", "status"],
                            points=[[1400425947000, 52, "ok"],
                                    [1400425948000, 18, "ok"],
                                    [1400425949000, 26, "fail"],
                                    [1400425950000, 93, "offline"]])

        series = TimeSeries(event_series)

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)
        new_json = new_series.to_json()

        self._validate_wire_points(event_series, new_json)
        self.assertTrue(new_json.get('utc'))

        # try something a bit fancier with different types
        interface_series = dict(
            name="star-cr5:to_anl_ip-a_v4",
            description="star-cr5->anl(as683):100ge:site-ex:show:intercloud",
            device="star-cr5",
            id=169,
            interface="to_anl_ip-a_v4",
            is_ipv6=False,
            is_oscars=False,
            oscars_id=None,
            resource_uri="",
            site="anl",
            site_device="noni",
            site_interface="et-1/0/0",
            stats_type="Standard",
            title=None,
            columns=["time", "in", "out"],
            points=[[1400425947000, 52, 34], [1400425948000, 18, 13],
                    [1400425949000, 26, 67], [1400425950000, 93, 91]])

        series = TimeSeries(interface_series)

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)
        new_json = new_series.to_json()

        self._validate_wire_points(interface_series, new_json)

        # Now with a list of events

        event_objects = [
            Event(1429673400000, {
                'in': 1,
                'out': 2
            }),
            Event(1429673460000, {
                'in': 3,
                'out': 4
            }),
            Event(1429673520000, {
                'in': 5,
                'out': 6
            }),
        ]

        series = TimeSeries(dict(name='events', events=event_objects))

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)

        for i in enumerate(event_objects):
            self.assertTrue(Event.same(i[1], new_series.at(i[0])))
Exemple #13
0
    def test_new_same(self):
        """trigger an error for coverage."""

        self.assertFalse(Event.same(EVENT_LIST[0], IDX_EVENT_DUP[0]))
Exemple #14
0
    def test_new_same(self):
        """trigger an error for coverage."""

        self.assertFalse(Event.same(EVENT_LIST[0], IDX_EVENT_DUP[0]))