Ejemplo n.º 1
0
def test_BASESETTINGS_validation_lt_zero_ok():
    a = BaseSettings(
        {"test_float": {
            "type": "float",
            "validation": "lt_zero"
        }})
    v = -1.00
    a.set("test_float", v)
Ejemplo n.º 2
0
def test_BASESETTINGS_getset_defaultsdosomething():
    a = BaseSettings(
        {"test_default1": {
            "type": "string",
            "default": "value1"
        }})
    ov = "value1"
    nv = a.get("test_default1")
    assert nv == ov, "defaults are populating correctly in absence of a set"
Ejemplo n.º 3
0
def test_BASESETTINGS_validation_gt_zero_notok():
    a = BaseSettings(
        {"test_float": {
            "type": "float",
            "validation": "gt_zero"
        }})
    v = -1.00
    with pytest.raises(AssertionError, match="test_float") as excinfo:
        a.set("test_float", v)
Ejemplo n.º 4
0
def test_BASESETTINGS_validation_is_percent_ok():
    a = BaseSettings(
        {"test_float": {
            "type": "float",
            "validation": "is_percent"
        }})
    for i in range(100):
        v = i / 100.00
        a.set("test_float", v)
Ejemplo n.º 5
0
def test_BASESETTINGS_validation_is_percent_ok():
    a = BaseSettings({
        "test_string": {
            "type": "string",
            "validation": "in_list",
            "valid_list": ["a", "b"],
        }
    })
    a.set("test_string", "a")
Ejemplo n.º 6
0
def test_BASESETTINGS_validation_is_percent_notok():
    a = BaseSettings(
        {"test_float": {
            "type": "float",
            "validation": "is_percent"
        }})
    v = 1.01
    with pytest.raises(AssertionError, match="test_float") as excinfo:
        a.set("test_float", v)
Ejemplo n.º 7
0
def test_BASESETTINGS_getset_defaultsdontoverride():
    a = BaseSettings(
        {"test_default2": {
            "type": "string",
            "default": "value2"
        }})
    ov = "value1"
    a.set("test_default2", ov)
    nv = a.get("test_default2")
    assert nv == ov, "set is overriding default arguments when supplied"
Ejemplo n.º 8
0
def test_BASESETTINGS_validation_is_percent_notok():
    a = BaseSettings({
        "test_string": {
            "type": "string",
            "validation": "in_list",
            "valid_list": ["a", "b"],
        }
    })
    v = "c"
    with pytest.raises(AssertionError, match="test_string") as excinfo:
        a.set("test_string", v)
Ejemplo n.º 9
0
def test_BASESETTINGS_getset_dict():
    a = BaseSettings({"test_dict": {"type": "dict"}})
    v = {"a": "b", "c": "d"}
    a.set("test_dict", v)
    assert a.get("test_dict") == v, "set/get don't match for dict type"
Ejemplo n.º 10
0
def test_BASESETTINGS_getset_string_notdict():
    a = BaseSettings({"test_string": {"type": "string"}})
    v = {}
    with pytest.raises(AssertionError, match="test_string.*string") as excinfo:
        a.set("test_string", v)
Ejemplo n.º 11
0
def test_BASESETTINGS_getset_string():
    a = BaseSettings({"test_string": {"type": "string"}})
    v = "var"
    a.set("test_string", v)
    assert a.get("test_string") == v, "set/get don't match for string type"
Ejemplo n.º 12
0
def test_BASESETTINGS_getset_float_intok():
    a = BaseSettings({"test_float": {"type": "float"}})
    v = 3
    a.set("test_float", v)
    assert a.get("test_float") == v, "set/get doesn't cast int type"
Ejemplo n.º 13
0
def test_BASESETTINGS_getset_float():
    a = BaseSettings({"test_float": {"type": "float"}})
    v = 3.14159
    a.set("test_float", v)
    assert a.get("test_float") == v, "set/get don't match for float type"
Ejemplo n.º 14
0
def test_BASESETTINGS_getset_float_notdict():
    a = BaseSettings({"test_float": {"type": "float"}})
    v = {}
    with pytest.raises(AssertionError, match="test_float.*float") as excinfo:
        a.set("test_float", v)
Ejemplo n.º 15
0
    def __init__(self, attributes=None):
        """init() with no parameters or init(dict) can specify a dictionary of attributes"""
        self.settings = BaseSettings({
            "id": {
                "type":
                "string",
                "validation":
                "",
                "default":
                "",
                "comment":
                "A unique string identifying the object. Generally not human friendly.",
            },
            "label": {
                "type": "string",
                "validation": "",
                "default": "",
                "comment": "A human friendly descriptor of the object.",
            },
            "height": {
                "type": "float",
                "validation": "",
                "default": 0.00,
                "comment": "The overall height of the building.",
            },
            "floors": {
                "type": "list",
                "validation": "",
                "default": [],
                "comment": "The floors contained in the building.",
            },
            "elevators": {
                "type": "list",
                "validation": "",
                "default": [],
                "comment": "The elevators contained in the building.",
            },
            "_elevation_of": {
                "type": "dict",
                "validation": "",
                "default": {},
                "comment": "A mapping of objects->elevations.",
            },
            "_at_elevation": {
                "type": "dict",
                "validation": "",
                "default": {},
                "comment": "A mapping of elevations->objects.",
            },
            "_ref_to": {
                "type": "dict",
                "validation": "",
                "default": {},
                "comment": "A mapping of ids->objects.",
            },
        })
        if attributes is not None:
            for key in attributes:
                self.set(key, attributes[key])
        self.set("id", SOLE.new_id("BaseBuilding"))

        running_height = 0
        floors = self.get("floors")
        if type(floors) == list:
            for f in floors:
                floor_id = f.get("id")
                f.set("elevation", running_height)
                running_height += f.get("height")
                f.set("elevation_top", running_height)
                f.set("building", self)
            self.set("height", running_height)

        elevators = self.get("elevators")
        if type(elevators) == list:
            for e in elevators:
                e.set("building", self)
Ejemplo n.º 16
0
 def __init__(self, attributes=None):
     """init() with no parameters or init(dict) can specify a dictionary of attributes"""
     self.settings = BaseSettings(
         {
             "height": {
                 "type": "float",
                 "validation": "gt_zero",
                 "default": 2.44,
                 "comment": "The height of the elevator itself.",
             },
             "elevation": {
                 "type": "float",
                 "validation": "",
                 "default": 0.00,
                 "comment": "The elevation of the top-most point of the elevator.",
             },
             "destination": {
                 "type": "floor",
                 "validation": "",
                 "default": None,
                 "comment": "The current destination floor that we are moving towards. Set to None when not in motion.",
             },
             "velocity": {
                 "type": "float",
                 "validation": "",
                 "default": 0.00,
                 "comment": "Positive velocity means upwards, negative means downward, 0 is at rest",
             },
             "label": {
                 "type": "string",
                 "validation": "",
                 "default": "",
                 "comment": "A friendly identifier for the elevator",
             },
             "maximum_up_speed": {
                 "type": "float",
                 "validation": "gt_zero",
                 "default": 1.00,
                 "comment": "A maximum upward velocity for the elevator, must be >0",
             },
             "maximum_down_speed": {
                 "type": "float",
                 "validation": "lt_zero",
                 "default": -1.00,
                 "comment": "A maximum downward velocity for the elevator, must be <0",
             },
             "carrying": {
                 "type": "list",
                 "validation": "",
                 "default": [],
                 "comment": "A list of Person objects presently within the elevator",
             },
             "building": {
                 "type": "building",
                 "validation": "",
                 "default": None,
                 "comment": "A reference to the current building object the elevator is contained within.",
             },
             "floor_requests": {
                 "type": "list",
                 "validation": "",
                 "default": [],
                 "comment": "A list of floor requests in sequential order.",
             },
             "status": {
                 "type": "string",
                 "validation": "",
                 "default": "idle",
                 "comment": "The current status of the elevator.",
             },
             "status_percent": {
                 "type": "float",
                 "validation": "is_percent",
                 "default": 1.00,
                 "comment": "A float inside [0,1] indicating percentage completion of status.",
             },
             "unloading_time_needed": {
                 "type": "float",
                 "validation": "gt_zero",
                 "default": 5.00,
                 "comment": "Real world seconds that it takes to unload the elevator.",
             },
             "loading_time_needed": {
                 "type": "float",
                 "validation": "gt_zero",
                 "default": 5.00,
                 "comment": "Real world seconds that it takes to load the elevator.",
             },
             "id": {
                 "type": "string",
                 "validation": "",
                 "default": "",
                 "comment": "A unique string identifying the object. Generally not human friendly.",
             },
         }
     )
     if attributes is not None:
         for key in attributes:
             self.set(key, attributes[key])
     self.set("id", SOLE.new_id("BaseElevator"))
Ejemplo n.º 17
0
def test_BASESETTINGS_getset_list():
    a = BaseSettings({"test_list": {"type": "list"}})
    v = [1, 2, 3]
    a.set("test_list", v)
    assert a.get("test_list") == v, "set/get don't match for list type"
Ejemplo n.º 18
0
def test_BASESETTINGS_getset_list_notfloat():
    a = BaseSettings({"test_list": {"type": "list"}})
    v = 1.00
    with pytest.raises(AssertionError, match="test_list.*list") as excinfo:
        a.set("test_list", v)
Ejemplo n.º 19
0
def test_BASESETTINGS_getset_dict_notlist():
    a = BaseSettings({"test_dict": {"type": "dict"}})
    v = []
    with pytest.raises(AssertionError, match="test_dict.*dict") as excinfo:
        a.set("test_dict", v)
Ejemplo n.º 20
0
def test_BASESETTINGS_getset_iscopy():
    a = BaseSettings({"test_iscopy": {"type": "string"}})
    ov = "foo"
    a.set("test_iscopy", ov)
    nv = a.get("test_iscopy")
    assert nv is ov, "set/get are returning a copy rather than the original object"
Ejemplo n.º 21
0
 def __init__(self, attributes=None):
     """init() with no parameters or init(dict) can specify a dictionary of attributes"""
     self.settings = BaseSettings({
         "id": {
             "type":
             "string",
             "validation":
             "",
             "default":
             "",
             "comment":
             "A unique string identifying the object. Generally not human friendly.",
         },
         "height": {
             "type": "float",
             "validation": "gt_zero",
             "default": 3.00,
             "comment": "The height of the floor.",
         },
         "elevation": {
             "type":
             "float",
             "validation":
             "",
             "default":
             0.00,
             "comment":
             "The distance of the bottom-most point of the object from the ground.",
         },
         "elevation_top": {
             "type":
             "float",
             "validation":
             "",
             "default":
             0.00,
             "comment":
             "The distance of the top-most point of the object from the ground.",
         },
         "label": {
             "type": "string",
             "validation": "",
             "default": "",
             "comment": "A human friendly descriptor of the object.",
         },
         "carrying": {
             "type":
             "list",
             "validation":
             "",
             "default": [],
             "comment":
             "A list of the people contained within the floor object.",
         },
         "building": {
             "type": "building",
             "validation": "",
             "default": None,
             "comment": "A reference to the parent building object.",
         },
         "is_floor": {
             "type":
             "boolean",
             "validation":
             "",
             "default":
             True,
             "comment":
             "A boolean indicating whether we are a floor object or not.",
         },
     })
     if attributes is not None:
         for key in attributes:
             self.set(key, attributes[key])
     self.set("id", SOLE.new_id("BaseFloor"))
Ejemplo n.º 22
0
 def __init__(self, attributes=None):
     """init() with no parameters or init(dict) can specify a dictionary of attributes"""
     self.settings = BaseSettings(
         {
             "id": {
                 "type": "string",
                 "validation": "",
                 "default": "",
                 "comment": "A unique string identifying the object. Generally not human friendly.",
             },
             "height": {
                 "type": "float",
                 "validation": "gt_zero",
                 "default": 1.77,
                 "comment": "The height of the person.",
             },
             "location": {
                 "type": "reference",
                 "validation": "",
                 "default": None,
                 "comment": "A reference to the object the person is contained in, whether floor or elevator.",
             },
             "building": {
                 "type": "building",
                 "validation": "",
                 "default": None,
                 "comment": "A reference to the parent building.",
             },
             "destination": {
                 "type": "reference",
                 "validation": "",
                 "default": None,
                 "comment": "A reference to the floor/elevator that we are destined to.",
             },
             "label": {
                 "type": "string",
                 "validation": "",
                 "default": sole_baseperson_random_name(),
                 "comment": "A human friendly descriptor of the object.",
             },
             "status": {
                 "type": "string",
                 "validation": "in_list",
                 "default": "idle",
                 "valid_list": [
                     "idle",
                     "requesting",
                     "entering",
                     "aboard",
                     "leaving",
                 ],
                 "comment": "The current status of the person.",
             },
             "status_percent": {
                 "type": "float",
                 "validation": "is_percent",
                 "default": 1.00,
                 "comment": "A float inside [0,1] indicating percentage completion of the status.",
             },
         }
     )
     if attributes is not None:
         for key in attributes:
             self.set(key, attributes[key])
     self.set("id", SOLE.new_id("BasePerson"))