示例#1
0
    def test_fire_failure_handler(self, reset_config):
        def go(fire):
            if fire.id == '2':
                raise RuntimeError("oops")

        # Skip
        fires_manager = fires.FiresManager()
        fires_manager.fires = [
            fires.Fire({'id': '1', 'name': 'n1'}),
            fires.Fire({'id': '2', 'name': 'n2'})
        ]
        assert fires_manager.num_fires == 2
        Config().set({"skip_failed_fires": True})
        assert fires_manager.skip_failed_fires
        for fire in fires_manager.fires:
            with fires_manager.fire_failure_handler(fire):
                go(fire)
        assert fires_manager.fires == [
            fires.Fire({'id': '1', 'name': 'n1'})
        ]
        assert fires_manager.num_fires == 1
        assert len(fires_manager.failed_fires) == 1
        assert fires_manager.failed_fires[0].id == '2'
        assert fires_manager.failed_fires[0].name == 'n2'
        assert fires_manager.failed_fires[0]['error']['message'] == 'oops'
        assert fires_manager.failed_fires[0]['error']['traceback']

        # Don't Skip
        fires_manager = fires.FiresManager()
        fires_manager.fires = [
            fires.Fire({'id': '1', 'name': 'n1'}),
            fires.Fire({'id': '2', 'name': 'n2'})
        ]
        Config().set({"skip_failed_fires": False})
        assert fires_manager.num_fires == 2
        assert not fires_manager.skip_failed_fires
        for fire in fires_manager.fires:
            if fire.id == '1':
                with fires_manager.fire_failure_handler(fire):
                    go(fire)
            else:
                with raises(RuntimeError) as e_info:
                    with fires_manager.fire_failure_handler(fire):
                        go(fire)
        assert fires_manager.num_fires == 2
        assert len(fires_manager.fires) == 2
        assert fires_manager.fires[0] == fires.Fire({'id': '1', 'name': 'n1'})
        assert fires_manager.fires[1].id == '2'
        assert fires_manager.fires[1].name == 'n2'
        assert fires_manager.fires[1]['error']['message'] == 'oops'
        assert fires_manager.fires[1]['error']['traceback']
        assert fires_manager.failed_fires is None
示例#2
0
 def test_no_fires(self, reset_config):
     fm = fires.FiresManager()
     assert fm.num_fires == 0
     assert fm.fires == []
     fm.merge_fires()
     assert fm.num_fires == 0
     assert fm.fires == []
示例#3
0
 def setup(self):
     self.fm = fires.FiresManager()
     self.init_fires = [
         fires.Fire({'id': '1', 'activity': [
             {'active_areas': [
                 # note this is midnight to midnight
                 {'start': '2019-01-01T17:00:00','end': "2019-01-02T17:00:00","utc_offset": "-07:00",
                  'specified_points':[{'lat': 40.0, 'lng': -80.0, "area": 90.0}]},
                 # note that this is midnight to noon
                 {'start': '2019-01-02T05:00:00','end': "2019-01-02T17:00:00","utc_offset": "-07:00",
                  'specified_points':[{'lat': 40.1, 'lng': -80.1, "area": 90.0}]}
             ]},
             {'active_areas': [
                 {'start': '2019-01-02T17:00:00','end': "2019-01-03T17:00:00","utc_offset": "-07:00",
                  'specified_points':[{'lat': 40.2, 'lng': -80.2, "area": 90.0}]}
             ]}
         ]}),
         fires.Fire({'id': '2', 'activity': [
             {'active_areas': [
                 {'start': '2019-01-02T20:00:00','end': "2019-01-03T20:00:00","utc_offset": "-04:00",
                  'specified_points':[{'lat': 30.0, 'lng': -90.0, "area": 90.0},{'lat': 30.5, 'lng': -90.5, "area": 90.0}]}
             ]},
             {'active_areas': [
                 {'start': '2019-01-03T20:00:00','end': "2019-01-04T20:00:00","utc_offset": "-04:00",
                  'specified_points':[{'lat': 30.1, 'lng': -90.1, "area": 90.0},{'lat': 30.6, 'lng': -90.6, "area": 90.0}]}
             ]}
         ]})
     ]
     self.fm.fires = self.init_fires
     assert self.fm.num_fires == 2
     assert self.fm.num_locations == 7
示例#4
0
 def setup(self):
     self.fm = fires.FiresManager()
     self.init_fires = [
         fires.Fire({'id': '01', 'name': 'n1', 'dfd':'a1', 'baz':'baz1'}),
         fires.Fire({'id': '02', 'name': 'n2', 'bar':'a1', 'baz':'baz1'}),
         fires.Fire({'id': '03', 'name': 'n3', 'bar1':'a1', 'baz':'baz1',
             "activity": [{"active_areas": [{'country': "ZZ"}, {'country': "ZZ"}]}]}),
         fires.Fire({'id': '04', 'name': 'n4', 'bar1':'a1', 'baz':'baz1',
             "activity": [{"active_areas": [{'country': "UK"}]}]}),
         fires.Fire({'id': '05', 'name': 'n5', 'bar1':'a1', 'baz':'baz1',
             "activity": [{"active_areas": [{'country': "USA"}]}]}),
         fires.Fire({'id': '06', 'name': 'n6', 'bar1': 1 , 'baz':'baz1',
             "activity": [{"active_areas": [{'country': ''}]}]}),
         fires.Fire({'id': '07', 'name': 'n7', 'bar2':'a2', 'baz':'baz2',
             "activity": [{"active_areas": [{'country': "CA"}]}]}),
         fires.Fire({'id': '08', 'name': 'n8', 'bar2':'adfsdf', 'baz':'baz2',
             "activity": [{"active_areas": [{'country': "CA"}]}]}),
         fires.Fire({'id': '09', 'name': 'n9', 'bar2': 2 , 'baz':'baz2',
             "activity": [{"active_areas": [{'country': 'Unknown'}]}]}),
         fires.Fire({'id': '10', 'name': 'n10', "barj": "jj", "baz": 99,
             "activity": [{"active_areas": [{"country": "USA"}]}]}),
         fires.Fire({'id': '11', 'name': 'n11', "barj": "jj", "baz": 99,
             "activity": [{"active_areas": [{"country": "BZ"}]}]}),
         fires.Fire({'id': '12', 'name': 'n3', 'bar1':'a1', 'baz':'baz1',
             "activity": [{"active_areas": [{'country': "ZZ"}]}, {"active_areas": [{'country': "UK"}]}]}),
         fires.Fire({'id': '13', 'name': 'n3', 'bar1':'a1', 'baz':'baz1',
             "activity": [{"active_areas": [{'country': "ZZ"}]}, {"active_areas": [{'country': "ZZ"}]}]}),
         # 14 is same as 12 exept the two active area objects are with the same activity object
         fires.Fire({'id': '14', 'name': 'n3.5', 'bar1':'a1', 'baz':'baz1',
             "activity": [{"active_areas": [{'country': "ZZ"}, {'country': "UK"}]}]})
     ]
     self.fm.fires = self.init_fires
     assert self.fm.num_fires == 14
示例#5
0
    def test_is_mutable(self, reset_config):
        fires_manager = fires.FiresManager()

        # set to something other than UTC today (which is default)
        fires_manager.today = datetime.datetime(2017,10,1)
        assert fires_manager.today == datetime.datetime(2017,10,1)

        # set to same date (as datetime, date, and string objects)

        fires_manager.today = datetime.datetime(2017,10,1)
        assert fires_manager.today == datetime.datetime(2017,10,1)

        fires_manager.today = datetime.date(2017,10,1)
        assert fires_manager.today == datetime.datetime(2017,10,1)

        fires_manager.today = "2017-10-01T00:00:00"
        assert fires_manager.today == datetime.datetime(2017,10,1)

        fires_manager.today = "2017-10-01"
        assert fires_manager.today == datetime.datetime(2017,10,1)

        # set to different dates (as datetime, date, and string objects)

        fires_manager.today = datetime.datetime(2017,10,2)
        assert fires_manager.today == datetime.datetime(2017,10,2)

        fires_manager.today = datetime.date(2017,10,3)
        assert fires_manager.today == datetime.datetime(2017,10,3)

        fires_manager.today = "2017-10-04T00:00:00"
        assert fires_manager.today == datetime.datetime(2017,10,4)

        fires_manager.today = "2017-10-05"
        assert fires_manager.today == datetime.datetime(2017,10,5)
示例#6
0
 def test_activity_for_only_one_fire(self, reset_config):
     # test in both skip and no-skip modes
     for s in (True, False):
         fm = fires.FiresManager()
         Config().set(s, 'merge', 'skip_failures')
         f = fires.Fire({'id': '1'})
         f2 = fires.Fire({
             'id':
             '1',
             "activity": [{
                 "active_areas": [{
                     "start":
                     "2014-05-27T17:00:00",
                     "end":
                     "2014-05-28T17:00:00",
                     'specified_points': [{
                         'area': 132,
                         'lat': 45.0,
                         'lng': -120.0
                     }]
                 }]
             }]
         })
         fm.fires = [f, f2]
         if not s:
             with raises(ValueError) as e_info:
                 fm.merge_fires()
             assert fm.num_fires == 2
             assert e_info.value.args[0].index(
                 fires.FiresMerger.ACTIVITY_FOR_BOTH_OR_NONE_MSG) > 0
         else:
             fm.merge_fires()
             assert fm.num_fires == 2
             assert [f, f2] == sorted(fm.fires,
                                      key=lambda e: int('activity' in e))
示例#7
0
    def test_dump_multiple_fires_with_meta(self, monkeypatch, reset_config):
        monkeypatch.setattr(fires.FiresManager, '_stream', self._stream())
        monkeypatch.setattr(uuid, "uuid4", lambda: "abcd1234")

        fires_manager = fires.FiresManager()
        fire_objects = [
            fires.Fire({'id':'a', 'bar':123, 'baz':12.32, 'bee': "12.12"}),
            fires.Fire({'id':'b', 'bar':2, 'baz': 1.1, 'bee': '24.34'})
        ]
        fires_manager.fires = fire_objects
        fires_manager.foo = {"bar": "baz"}

        fires_manager.dumps()
        expected = {
            "run_id": "abcd1234",
            "today": "2016-04-20",
            "run_config": DEFAULTS,
            "fires": fire_objects,
            "foo": {"bar": "baz"},
            "counts": {
                "fires": 2,
                "locations": 0
            },
            "bluesky_version": __version__
        }

        actual = json.loads(self._output.getvalue())
        assert expected == actual
示例#8
0
 def test_one_fire(self, reset_config):
     fm = fires.FiresManager()
     f = fires.Fire({'id': '1'})
     fm.fires = [f]
     assert fm.num_fires == 1
     assert fm.fires == [f]
     fm.merge_fires()
     assert fm.num_fires == 1
     assert fm.fires == [f]
示例#9
0
 def test_none_to_merge(self, reset_config):
     fm = fires.FiresManager()
     f = fires.Fire({'id': '1'})
     f2 = fires.Fire({'id': '2'})
     fm.fires = [f, f2]
     assert fm.num_fires == 2
     assert fm.fires == [f, f2]
     fm.merge_fires()
     assert fm.num_fires == 2
     assert fm.fires == [f, f2]
示例#10
0
    def test_earliest_and_latest_times(self, reset_config):
        fm = fires.FiresManager()
        f1 = fires.Fire({
            'id': '1',
            'activity': [
                {
                    'active_areas': [
                        {
                            "start": "2014-05-27T17:00:00",
                            "end": "2014-05-28T17:00:00",
                            'specified_points': [
                                {'area': 34, 'lat': 45.0, 'lng': -120.0},
                            ]
                        },
                        {
                            "start": "2014-05-25T17:00:00",
                            "end": "2014-05-26T17:00:00",
                            'specified_points': [
                                {'area': 34, 'lat': 45.0, 'lng': -120.0},
                            ]
                        }
                    ]
                }
            ]
        })
        f2 = fires.Fire({
            'id': '2',
            "activity":[
                {
                    'active_areas': [
                        {
                            "start": "2014-05-27T19:00:00",
                            "end": "2014-05-28T19:00:00",
                            'specified_points': [
                                {'area': 132, 'lat': 45.0, 'lng': -120.0},
                            ]
                        }
                    ]
                }
            ]
        })
        f3 = fires.Fire({
            'id': '2',
        })
        fm.fires = [f1, f2, f3]
        assert datetime.datetime(2014,5,25,17) == fm.earliest_start
        assert datetime.datetime(2014,5,28,19) == fm.latest_end

        # same thing, but with time zones specified for two of the fires
        f1.activity[0]['active_areas'][0]['utc_offset'] = '-07:00'
        f1.activity[0]['active_areas'][1]['utc_offset'] = '-07:00'
        f2.activity[0]['active_areas'][0]['utc_offset'] = '03:00' # no longer the latest time
        assert datetime.datetime(2014,5,26,0) == fm.earliest_start
        assert datetime.datetime(2014,5,29,0) == fm.latest_end
示例#11
0
 def test_simple(self, reset_config):
     fm = fires.FiresManager()
     f = fires.Fire({'id': '1'})
     f2 = fires.Fire({'id': '1'})
     fm.fires = [f, f2]
     fm.num_fires == 1
     assert dict(fm.fires[0]) == {
         'id': '1',
         'fuel_type': fires.Fire.DEFAULT_FUEL_TYPE,
         'type': fires.Fire.DEFAULT_TYPE
     }
示例#12
0
    def test_run_id_is_immutable(self, monkeypatch, reset_config):
        monkeypatch.setattr(uuid, 'uuid4', lambda: "sdf123")

        fm = fires.FiresManager()
        # if not already set, run_id is set when accessed.
        # This initial guid can be overwritten
        assert fm.run_id == "sdf123"
        fm.run_id = "sdfsdfsdf"
        assert fm.run_id == "sdfsdfsdf"

        # if FiresManager.load doesn't set run_id, then it can still be set after
        fm = fires.FiresManager()
        assert fm.run_id == "sdf123"
        fm.load({})
        assert fm.run_id == "sdf123"
        fm.run_id = "sdfsdfsdf"
        assert fm.run_id == "sdfsdfsdf"

        fm = fires.FiresManager()
        assert fm.run_id == "sdf123"
        fm.load({'run_id': "ggbgbg"})
        assert fm.run_id == "ggbgbg"
        with raises(TypeError) as e_info:
            fm.run_id = "sdfsdfsdf"
        assert e_info.value.args[0] == fires.FiresManager.RUN_ID_IS_IMMUTABLE_MSG

        fm = fires.FiresManager()
        assert fm.run_id == "sdf123"
        fm.run_id = "eee"
        assert fm.run_id == "eee"
        with raises(TypeError) as e_info:
            fm.run_id = "sdfsdfsdf"
        assert e_info.value.args[0] == fires.FiresManager.RUN_ID_IS_IMMUTABLE_MSG

        # when you load, fm starts from scratch
        fm = fires.FiresManager()
        assert fm.run_id == "sdf123"
        fm.load({'run_id': "ggbgbg"})
        assert fm.run_id == "ggbgbg"
示例#13
0
    def test_load_no_fires_with_meta(self, monkeypatch, reset_config):
        monkeypatch.setattr(fires.FiresManager, '_stream', self._stream(
            '{"fires":[], "foo": {"bar": "baz"}}'))
        monkeypatch.setattr(uuid, "uuid4", lambda: "abcd1234")

        fires_manager = fires.FiresManager()
        fires_manager.loads()
        assert fires_manager.num_fires == 0
        assert [] == fires_manager.fires
        assert fires_manager.today == freezegun.api.FakeDate(2016,4,20)
        expected_meta = {
            "foo": {"bar": "baz"}
        }
        assert expected_meta == fires_manager.meta
示例#14
0
    def test_getting_fires_and_meta(self, reset_config):
        fires_manager = fires.FiresManager()
        fire_objects = [
            fires.Fire({'id': '1', 'name': 'n1', 'dfd':'a1', 'baz':'baz1'}),
            fires.Fire({'id': '2', 'name': 'n2', 'bar':'a1', 'baz':'baz1'})
        ]
        fires_manager.fires = fire_objects
        fires_manager._meta = {'a':1, 'b':{'c':2}}

        assert fire_objects == fires_manager.fires
        assert 1 == fires_manager.a
        assert {'c':2} == fires_manager.b
        assert 2 == fires_manager.b['c']
        assert None == fires_manager.d
示例#15
0
    def test_run_id_is_mutable(self, monkeypatch, reset_config):
        monkeypatch.setattr(uuid, 'uuid4', lambda: "sdf123")

        fm = fires.FiresManager()
        # if not already set, run_id is set when accessed.
        # This initial guid can be overwritten
        assert fm.run_id == "sdf123"
        fm.run_id = "sdfsdfsdf"
        assert fm.run_id == "sdfsdfsdf"

        # if FiresManager.load doesn't set run_id, then it can still be set after
        fm = fires.FiresManager()
        assert fm.run_id == "sdf123"
        fm.load({})
        assert fm.run_id == "sdf123"
        fm.run_id = "sdfsdfsdf"
        assert fm.run_id == "sdfsdfsdf"

        fm = fires.FiresManager()
        assert fm.run_id == "sdf123"
        fm.load({'run_id': "ggbgbg"})
        assert fm.run_id == "ggbgbg"
        fm.run_id = "sdfsdfsdf"
        assert fm.run_id == "sdfsdfsdf"

        fm = fires.FiresManager()
        assert fm.run_id == "sdf123"
        fm.run_id = "eee"
        assert fm.run_id == "eee"
        fm.run_id = "sdfsdfsdf"
        assert fm.run_id == "sdfsdfsdf"

        # when you load, fm starts from scratch
        fm = fires.FiresManager()
        assert fm.run_id == "sdf123"
        fm.load({'run_id': "ggbgbg"})
        assert fm.run_id == "ggbgbg"
示例#16
0
    def test_today_is_processed_for_wildcards(self, monkeypatch, reset_config):
        fm = fires.FiresManager()
        assert fm.today == datetime.date(2016,4,20)

        # test setting fm.today by load

        fm = fires.FiresManager()
        fm.load({'today': datetime.datetime(2012, 4,3,22,11)})
        assert fm.today == datetime.datetime(2012, 4,3,22,11)

        fm = fires.FiresManager()
        fm.load({'today': "2012-04-02T22:11:00Z"})
        assert fm.today == datetime.datetime(2012, 4,2,22,11)

        fm = fires.FiresManager()
        fm.load({'today': "{today}"})
        assert fm.today == datetime.datetime(2016, 4,20)

        fm = fires.FiresManager()
        fm.load({'today': "{yesterday}"})
        assert fm.today == datetime.datetime(2016, 4, 19)

        # TODO: any other possibilities ??

        # test setting fm.today by assignmentd

        fm = fires.FiresManager()
        fm.today = datetime.datetime(2016, 4, 1)
        assert fm.today == datetime.datetime(2016, 4, 1)

        fm = fires.FiresManager()
        fm.today = "2012-04-04T22:13:00Z"
        assert fm.today == datetime.datetime(2012, 4, 4, 22, 13)

        fm = fires.FiresManager()
        fm.today = "{today}"
        assert fm.today == datetime.datetime(2016, 4, 20)

        fm = fires.FiresManager()
        fm.today = "{yesterday}"
        assert fm.today == datetime.datetime(2016, 4, 19)
示例#17
0
 def test_different_event_ids(self, reset_config):
     # test in both skip and no-skip modes
     for s in (True, False):
         fm = fires.FiresManager()
         Config().set(s, 'merge', 'skip_failures')
         f = fires.Fire({
             'id':
             '1',
             "event_of": {
                 "id": "ABC"
             },
             # activity just used for assertion, below
             "activity": [{
                 "active_areas": [{
                     'specified_points': [{
                         'area': 123
                     }]
                 }]
             }]
         })
         f2 = fires.Fire({
             'id':
             '1',
             "event_of": {
                 "id": "SDF"
             },
             # activity just used for assertion, below
             "activity": [{
                 "active_areas": [{
                     'specified_points': [{
                         'area': 456
                     }]
                 }]
             }]
         })
         fm.fires = [f, f2]
         if not s:
             with raises(ValueError) as e_info:
                 fm.merge_fires()
             assert fm.num_fires == 2
             assert e_info.value.args[0].index(
                 fires.FiresMerger.EVENT_MISMATCH_MSG) > 0
         else:
             fm.merge_fires()
             assert fm.num_fires == 2
             assert [f2, f] == fm.fires
示例#18
0
    def test_load_one_fire_with_meta(self, monkeypatch, reset_config):
        monkeypatch.setattr(fires.FiresManager, '_stream', self._stream(
            '{"fires":[{"id":"a","bar":123,"baz":12.32,"bee":"12.12"}],'
            '"foo": {"bar": "baz"}}'))
        monkeypatch.setattr(uuid, "uuid4", lambda: "abcd1234")

        fires_manager = fires.FiresManager()
        fires_manager.loads()
        expected_fires = [
            fires.Fire({'id':'a', 'bar':123, 'baz':12.32, 'bee': "12.12"})
        ]
        assert fires_manager.num_fires == 1
        assert expected_fires == fires_manager.fires
        assert fires_manager.today == freezegun.api.FakeDate(2016,4,20)
        expected_meta = {
            "foo": {"bar": "baz"}
        }
        assert expected_meta == fires_manager.meta
示例#19
0
    def test_load_invalid_data(self, monkeypatch, reset_config):
        fires_manager = fires.FiresManager()

        monkeypatch.setattr(fires.FiresManager, '_stream', self._stream(''))
        with raises(ValueError):
            fires_manager.loads()

        monkeypatch.setattr(fires.FiresManager, '_stream', self._stream('""'))
        with raises(ValueError):
            fires_manager.loads()

        monkeypatch.setattr(fires.FiresManager, '_stream', self._stream('"sdf"'))
        with raises(ValueError):
            fires_manager.loads()

        monkeypatch.setattr(fires.FiresManager, '_stream', self._stream('null'))
        with raises(ValueError):
            fires_manager.loads()
示例#20
0
    def test_is_immutable(self, reset_config):
        fires_manager = fires.FiresManager()
        fires_manager.today = datetime.datetime(2017,10,1)

        # ok to set to same val
        fires_manager.today = datetime.datetime(2017,10,1)
        fires_manager.today = datetime.date(2017,10,1)
        fires_manager.today = "2017-10-01"

        # not ok to change
        with raises(TypeError) as e_info:
            fires_manager.today = datetime.datetime(2017,10,2)
        assert e_info.value.args[0] == fires.FiresManager.TODAY_IS_IMMUTABLE_MSG
        with raises(TypeError) as e_info:
            fires_manager.today = datetime.date(2017,10,3)
        assert e_info.value.args[0] == fires.FiresManager.TODAY_IS_IMMUTABLE_MSG
        with raises(TypeError) as e_info:
            fires_manager.today = "2017-10-04"
        assert e_info.value.args[0] == fires.FiresManager.TODAY_IS_IMMUTABLE_MSG
示例#21
0
 def test_invalid_keys(self, reset_config):
     # test in both skip and no-skip modes
     for s in (True, False):
         # i.e. top-level location is old structure
         fm = fires.FiresManager()
         Config().set(s, 'merge', 'skip_failures')
         f = fires.Fire({'id': '1', 'location': {'area': 132}})
         f2 = fires.Fire({'id': '1', 'location': {'area': 132}})
         fm.fires = [f, f2]
         if not s:
             with raises(ValueError) as e_info:
                 fm.merge_fires()
             assert fm.num_fires == 2
             assert e_info.value.args[0].index(
                 fires.FiresMerger.INVALID_KEYS_MSG) > 0
         else:
             fm.merge_fires()
             assert fm.num_fires == 2
             assert [f, f2] == sorted(fm.fires, key=lambda e: int(e.id))
示例#22
0
    def test_setting_fires_and_meta(self, reset_config):
        fires_manager = fires.FiresManager()
        fire_objects = [
            fires.Fire({'id': '1', 'name': 'n1', 'dfd':'a1', 'baz':'baz1'}),
            fires.Fire({'id': '2', 'name': 'n2', 'bar':'a1', 'baz':'baz1'})
        ]
        fires_manager.fires = fire_objects
        fires_manager.a = 1
        fires_manager.b = {'c': 2}
        # you can also set meta data directly
        fires_manager.meta['d'] = 123

        assert fires_manager.num_fires == 2
        assert set(['1','2']) == set(list(fires_manager._fires.keys()))
        assert {'1': [fire_objects[0]],'2': [fire_objects[1]]} == fires_manager._fires
        assert fires_manager.today == freezegun.api.FakeDate(2016, 4, 20)
        expected_meta = {
            'a':1, 'b':{'c':2}, 'd': 123
        }
        assert expected_meta == fires_manager._meta == fires_manager.meta
示例#23
0
 def test_merge_mixed_success_no_activity(self, reset_config):
     fm = fires.FiresManager()
     #Config().set(True, 'merge', 'skip_failures')
     f = fires.Fire({'id': '1', "type": "rx", "fuel_type": "natural"})
     f2 = fires.Fire({'id': '1', "type": "rx", "fuel_type": "natural"})
     f3 = fires.Fire({'id': '2', "type": "rx", "fuel_type": "natural"})
     fm.fires = [f, f2, f3]
     assert fm.num_fires == 3
     fm.merge_fires()
     expected = [
         fires.Fire({
             'id': '1',
             "type": "rx",
             "fuel_type": "natural"
         }),
         fires.Fire({
             'id': '2',
             "type": "rx",
             "fuel_type": "natural"
         })
     ]
     assert fm.num_fires == 2
     assert expected == sorted(fm.fires, key=lambda e: int(e.id))
示例#24
0
 def setup(self):
     self.fm = fires.FiresManager()
     self.init_fires = [
         fires.Fire({'id': '1', 'activity': [{'active_areas': [{'specified_points':[{'lat': 40.0, 'lng': -80.0}]}]}]}),
         fires.Fire({'id': '2', 'activity': [{'active_areas': [{'specified_points':[{'lat': 45.0, 'lng': -81.0}, {'lat': 55.0, 'lng': -79.0}]}]}]}),
         fires.Fire({'id': '3', 'activity': [{'active_areas': [{'specified_points':[{'lat': 60.0, 'lng': -62.0}]}]}]}),
         fires.Fire({'id': '4', 'activity': [{'active_areas': [{'perimeter': {'polygon': [[-61, 71], [-61, 69], [-59, 69], [-59, 71], [-61, 71]]}}]}]}),
         fires.Fire({'id': '5', 'activity': [{'active_areas': [{'specified_points':[{'lat': 40.0, 'lng': -60.0}]}]}]}),
         fires.Fire({'id': '6', 'activity': [{'active_areas': [{'specified_points':[{'lat': 61.0, 'lng': -60.0}]}]}]}),
         fires.Fire({'id': '7', 'activity': [{'active_areas': [{'perimeter': {'polygon': [[-51,61], [-49, 61], [-49, 59], [-51, 59], [-51, 61]]}}]}]}),
         fires.Fire({'id': '8', 'activity': [{'active_areas': [{'specified_points':[{'lat': 70.0, 'lng': -120.0}]}]}]}),
         fires.Fire({'id': '9', 'activity': [{'active_areas': [{'specified_points':[{'lat': -10.0, 'lng': 10.0}]}]}]}),
         fires.Fire({'id': '10', 'activity': [
             {'active_areas': [{'specified_points': [{'lat': -10.0, 'lng': -10.0}]}]},
             {'active_areas': [{'specified_points': [{'lat': 40.0, 'lng': -80.0}]}]}
         ]}),
         fires.Fire({'id': '10', 'activity': [
             {'active_areas': [{'specified_points': [{'lat': -10.0, 'lng': 10.0}]}]},
             {'active_areas': [{'specified_points': [{'lat': -11.0, 'lng': 9.0}]}]},
         ]})
     ]
     self.fm.fires = self.init_fires
     assert self.fm.num_fires == 11
示例#25
0
 def setup(self):
     self.fm = fires.FiresManager()
     self.init_fires = [
         fires.Fire({'id': '1', 'activity': [{'active_areas':[{'specified_points': [{'area': 45}]}]} ]}),
         fires.Fire({'id': '2', 'activity': [{'active_areas':[{'specified_points': [{'area': 55}, {'area': 40}]}]} ]}),
         fires.Fire({'id': '3', 'activity': [{'active_areas':[{'specified_points': [{'area': 55}]}]} ]}),
         fires.Fire({'id': '4', 'activity': [{'active_areas':[{'perimeter': {'area': 65}}]} ]}),
         fires.Fire({'id': '5', 'activity': [{'active_areas':[{'specified_points': [{'area': 85}]}]} ]}),
         fires.Fire({'id': '6', 'activity': [{'active_areas':[{'specified_points': [{'area': 75}], 'perimeter': {'area': 90}}]}]}),
         fires.Fire({'id': '7', 'activity': [{'active_areas':[{'specified_points': [{'area': 50}]}]} ]}),
         fires.Fire({'id': '8', 'activity': [{'active_areas':[{'specified_points': [{'area': 30}]}]} ]}),
         fires.Fire({'id': '9', 'activity': [
             {'active_areas':[{'specified_points': [{'area': 45}]}]},
             {'active_areas':[{'specified_points': [{'area': 40}]}]}
         ]}),
         fires.Fire({'id': '10', 'activity': [
             {'active_areas':[{'specified_points': [{'area': 45}]}]},
             {'active_areas':[{'perimeter': {'area': 65}}]}
         ]}),
         fires.Fire({'id': '11', 'activity': [{'active_areas':[{'specified_points': [{'area': 15}, {'area': 20}]}]} ]})
     ]
     self.fm.fires = self.init_fires
     assert self.fm.num_fires == 11
示例#26
0
    def test_load_multiple_streams(self, monkeypatch, reset_config):
        input_1 = io.StringIO('{"fires":[{"id":"a","bar":123,"baz":12.32,"bee":"12.12"},'
            '{"id":"b","bar":2, "baz": 1.1, "bee":"24.34"}],'
            '"foo": {"bar": "baz"}}')
        input_2 = io.StringIO('{"das": 1, "fires":[{"id":"c","bar":1223,"baz":1,"bee":"12"}]}')

        monkeypatch.setattr(uuid, "uuid4", lambda: "abcd1234")

        fires_manager = fires.FiresManager()
        fires_manager.loads(input_stream=input_1, append_fires=True)
        fires_manager.loads(input_stream=input_2, append_fires=True)
        expected_fires = [
            fires.Fire({'id':'a', 'bar':123, 'baz':12.32, 'bee': "12.12"}),
            fires.Fire({'id':'b', 'bar':2, 'baz': 1.1, 'bee': '24.34'}),
            fires.Fire({"id":"c", "bar":1223,"baz":1,"bee":"12"})
        ]
        assert fires_manager.num_fires == 3
        assert expected_fires == fires_manager.fires
        assert fires_manager.today == freezegun.api.FakeDatetime(2016,4,20)
        expected_meta = {
            "foo": {"bar": "baz"},
            "das": 1
        }
        assert expected_meta == fires_manager.meta
示例#27
0
 def test_manually_set_to_date_obj(self, reset_config):
     fires_manager = fires.FiresManager()
     fires_manager.today = datetime.date(2017,10,1)
     assert fires_manager.today == datetime.datetime(2017,10,1)
示例#28
0
 def test_manually_set_to_string(self, reset_config):
     fires_manager = fires.FiresManager()
     fires_manager.today = "2017-10-01"
     assert fires_manager.today == datetime.datetime(2017,10,1)
示例#29
0
 def test_set_to_date_obj_in_loaded_input_data(self, reset_config):
     fires_manager = fires.FiresManager()
     fires_manager.load({"today": datetime.date(2017,10,1)})
     assert fires_manager.today == datetime.datetime(2017,10,1)
示例#30
0
 def test_set_to_string_in_loaded_input_data(self, reset_config):
     fires_manager = fires.FiresManager()
     fires_manager.load({"today": "2017-10-01"})
     assert fires_manager.today == datetime.datetime(2017,10,1)