def test_HasProps_set_from_json() -> None: c = Child() c.set_from_json('lst2', [1, 2]) assert c.int1 == 10 assert c.ds1 == field("x") assert c.lst1 == [] assert c.int2 == None assert c.str2 == "foo" assert c.ds2 == field("y") assert c.lst2 == [1, 2] c.set_from_json('ds1', "foo") assert c.int1 == 10 assert c.ds1 == "foo" assert c.lst1 == [] assert c.int2 == None assert c.str2 == "foo" assert c.ds2 == field("y") assert c.lst2 == [1, 2] c.set_from_json('int2', 100) assert c.int1 == 10 assert c.ds1 == "foo" assert c.lst1 == [] assert c.int2 == 100 assert c.str2 == "foo" assert c.ds2 == field("y") assert c.lst2 == [1, 2]
def test_ImageURL() -> None: glyph = ImageURL() assert glyph.url == field("url") assert glyph.x == field("x") assert glyph.y == field("y") assert glyph.w is None assert glyph.h is None assert glyph.angle == 0 assert glyph.dilate is False assert glyph.anchor == Anchor.top_left assert glyph.retry_attempts == 0 assert glyph.retry_timeout == 0 assert glyph.global_alpha == 1.0 check_properties_existence(glyph, [ "url", "x", "y", "w", "w_units", "h", "h_units", "angle", "angle_units", "dilate", "anchor", "retry_attempts", "retry_timeout", "global_alpha", ], GLYPH)
def test_field_function() -> None: transform = Dodge() assert bcpv.field("foo") == bcpv.Field(field="foo") assert bcpv.field("foo", transform) == bcpv.Field(field="foo", transform=transform) assert bcpv.field("foo", transform=transform) == bcpv.Field(field="foo", transform=transform)
def test_Segment() -> None: glyph = Segment() assert glyph.x0 == field("x0") assert glyph.y0 == field("y0") assert glyph.x1 == field("x1") assert glyph.y1 == field("y1") check_line_properties(glyph) check_properties_existence(glyph, ["x0", "y0", "x1", "y1"], LINE, GLYPH)
def test_Line() -> None: glyph = Line() assert glyph.x == field("x") assert glyph.y == field("y") check_line_properties(glyph) check_properties_existence(glyph, [ "x", "y", ], LINE, GLYPH)
def test_MultiLine() -> None: glyph = MultiLine() assert glyph.xs == field("xs") assert glyph.ys == field("ys") check_line_properties(glyph) check_properties_existence(glyph, [ "xs", "ys", ], LINE, GLYPH)
def test_Text() -> None: glyph = Text() assert glyph.x == field("x") assert glyph.y == field("y") assert glyph.text == "text" assert glyph.angle == 0 check_text_properties(glyph) check_properties_existence( glyph, ["x", "y", "text", "angle", "angle_units", "x_offset", "y_offset"], TEXT, GLYPH)
def test_Patches() -> None: glyph = Patches() assert glyph.xs == field("xs") assert glyph.ys == field("ys") check_line_properties(glyph) check_fill_properties(glyph) check_hatch_properties(glyph) check_properties_existence(glyph, [ "xs", "ys", ], FILL, HATCH, LINE, GLYPH)
def test_Step() -> None: glyph = Step() assert glyph.x == field("x") assert glyph.y == field("y") assert glyph.mode == "before" check_line_properties(glyph) check_properties_existence(glyph, [ "x", "y", "mode", ], LINE, GLYPH)
def test_HArea() -> None: glyph = HArea() assert glyph.y == field("y") assert glyph.x1 == field("x1") assert glyph.x2 == field("x2") check_fill_properties(glyph) check_hatch_properties(glyph) check_properties_existence(glyph, [ "y", "x1", "x2", ], FILL, HATCH, GLYPH)
def test_VArea() -> None: glyph = VArea() assert glyph.x == field("x") assert glyph.y1 == field("y1") assert glyph.y2 == field("y2") check_fill_properties(glyph) check_hatch_properties(glyph) check_properties_existence(glyph, [ "x", "y1", "y2", ], FILL, HATCH, GLYPH)
def test_HasProps_set() -> None: c = Child() c.update(**dict(lst2=[1, 2], str2="baz", int1=25, ds1=field("foo"))) assert c.int1 == 25 assert c.ds1 == field("foo") assert c.lst1 == [] assert c.int2 == None assert c.str2 == "baz" assert c.ds2 == field("y") assert c.lst2 == [1, 2] c.str2_proxy = "some" assert c.str2 == "somesome" assert c.str2_proxy == "somesome"
def test_HasProps_kw_init() -> None: p = Parent(int1=30, ds1=field("foo")) assert p.int1 == 30 assert p.ds1 == field("foo") assert p.lst1 == [] c = Child(str2="bar", lst2=[2, 3, 4], ds2=10) assert c.int1 == 10 assert c.ds1 == field("x") assert c.lst1 == [] assert c.int2 == None assert c.str2 == "bar" assert c.ds2 == 10 assert c.lst2 == [2, 3, 4]
def test_HasProps_default_init() -> None: p = Parent() assert p.int1 == 10 assert p.ds1 == field("x") assert p.lst1 == [] c = Child() assert c.int1 == 10 assert c.ds1 == field("x") assert c.lst1 == [] assert c.int2 == None assert c.str2 == "foo" assert c.ds2 == field("y") assert c.lst2 == [1, 2, 3]
def test_VBar() -> None: glyph = VBar() assert glyph.x == field("x") assert glyph.width == 1 assert glyph.top == field("top") assert glyph.bottom == 0 check_line_properties(glyph) check_fill_properties(glyph) check_hatch_properties(glyph) check_properties_existence(glyph, [ "x", "width", "top", "bottom", ], FILL, HATCH, LINE, GLYPH)
def test_HBar() -> None: glyph = HBar() assert glyph.y == field("y") assert glyph.height == 1 assert glyph.left == 0 assert glyph.right == field("right") check_line_properties(glyph) check_fill_properties(glyph) check_hatch_properties(glyph) check_properties_existence(glyph, [ "y", "height", "left", "right", ], FILL, HATCH, LINE, GLYPH)
def test_Quad() -> None: glyph = Quad() assert glyph.left == field("left") assert glyph.right == field("right") assert glyph.bottom == field("bottom") assert glyph.top == field("top") check_line_properties(glyph) check_fill_properties(glyph) check_hatch_properties(glyph) check_properties_existence(glyph, [ "left", "right", "bottom", "top", ], FILL, HATCH, LINE, GLYPH)
def test_Ray() -> None: glyph = Ray() assert glyph.x == field("x") assert glyph.y == field("y") assert glyph.angle == 0 assert glyph.length == 0 check_line_properties(glyph) check_properties_existence(glyph, [ "x", "y", "angle", "angle_units", "length", "length_units", ], LINE, GLYPH)
def test_set_from_json_keeps_mode(self) -> None: class Foo(HasProps): x = bcpd.NumberSpec(default=-1) a = Foo() assert a.x == -1 # set as a value a.x = 14 assert a.x == 14 # set_from_json keeps the previous dict-ness or lack thereof a.set_from_json('x', dict(value=16)) assert a.x == 16 # but regular assignment overwrites the previous dict-ness a.x = dict(value=17) assert a.x == value(17) # set as a field a.x = "bar" assert a.x == "bar" # set_from_json keeps the previous dict-ness or lack thereof a.set_from_json('x', dict(field="foo")) assert a.x == "foo" # but regular assignment overwrites the previous dict-ness a.x = dict(field="baz") assert a.x == field("baz")
def test_Annulus() -> None: glyph = Annulus() assert glyph.x == field("x") assert glyph.y == field("y") assert glyph.inner_radius == field("inner_radius") assert glyph.outer_radius == field("outer_radius") check_line_properties(glyph) check_fill_properties(glyph) check_hatch_properties(glyph) check_properties_existence(glyph, [ "x", "y", "inner_radius", "inner_radius_units", "outer_radius", "outer_radius_units", ], LINE, FILL, HATCH, GLYPH)
def test_fields(self) -> None: class Foo(HasProps): x = bcpd.FontSizeSpec(default="0px") a = Foo() a.x = "_120" assert a.x == "_120" a.x = dict(field="_120") assert a.x == field("_120") a.x = "foo" assert a.x == "foo" a.x = dict(field="foo") assert a.x == field("foo")
def test_Image_kwargs() -> None: glyph = Image(x=0, y=0, dw=10, dh=10) assert glyph.image == field("image") assert glyph.x == 0 assert glyph.y == 0 assert glyph.dw == 10 assert glyph.dh == 10 assert glyph.dilate is False
def test_ImageRGBA() -> None: glyph = ImageRGBA() assert glyph.image == field("image") assert glyph.x == field("x") assert glyph.y == field("y") assert glyph.dw == field("dw") assert glyph.dh == field("dh") assert glyph.dilate is False check_properties_existence(glyph, [ "image", "x", "y", "dw", "dw_units", "dh", "dh_units", "global_alpha", "dilate", ], GLYPH)
def test_HasProps_update() -> None: c = Child() c.update(**dict(lst2=[1, 2], str2="baz", int1=25, ds1=value(123))) assert c.int1 == 25 assert c.ds1 == value(123) assert c.lst1 == [] assert c.int2 == None assert c.str2 == "baz" assert c.ds2 == field("y") assert c.lst2 == [1, 2]
def test_Arc() -> None: glyph = Arc() assert glyph.x == field("x") assert glyph.y == field("y") assert glyph.radius == field("radius") assert glyph.start_angle == field("start_angle") assert glyph.end_angle == field("end_angle") assert glyph.direction == "anticlock" check_line_properties(glyph) check_properties_existence(glyph, [ "x", "y", "radius", "radius_units", "start_angle", "start_angle_units", "end_angle", "end_angle_units", "direction", ], LINE, GLYPH)
def test_HasProps_intrinsic() -> None: obj0 = Parent(int1=Intrinsic, ds1=Intrinsic, lst1=Intrinsic) assert obj0.int1 == 10 assert obj0.ds1 == field("x") assert obj0.lst1 == [] obj1 = Parent(int1=30, ds1=field("y"), lst1=["x", "y", "z"]) assert obj1.int1 == 30 assert obj1.ds1 == field("y") assert obj1.lst1 == ["x", "y", "z"] obj1.int1 = Intrinsic obj1.ds1 = Intrinsic obj1.lst1 = Intrinsic assert obj1.int1 == 10 assert obj1.ds1 == field("x") assert obj1.lst1 == []
def test_set_dict(self) -> None: class Foo(HasProps): col = bcpd.ColorSpec("colorfield") desc = Foo.__dict__["col"] f = Foo() f.col = {"field": "myfield"} assert f.col == field("myfield") f.col = "field2" assert f.col == "field2" assert desc.get_value(f) == Field("field2")
def test_AnnularWedge() -> None: glyph = AnnularWedge() assert glyph.x == field("x") assert glyph.y == field("y") assert glyph.inner_radius == field("inner_radius") assert glyph.outer_radius == field("outer_radius") assert glyph.start_angle == field("start_angle") assert glyph.end_angle == field("end_angle") assert glyph.direction == "anticlock" check_line_properties(glyph) check_fill_properties(glyph) check_hatch_properties(glyph) check_properties_existence(glyph, [ "x", "y", "inner_radius", "inner_radius_units", "outer_radius", "outer_radius_units", "start_angle", "start_angle_units", "end_angle", "end_angle_units", "direction", ], LINE, FILL, HATCH, GLYPH)
class Child(Parent): int2 = Nullable(Int()) str2 = String(default="foo") ds2 = NumberSpec(default=field("y")) lst2 = List(Int, default=[1, 2, 3]) @property def str2_proxy(self): return self.str2 @str2_proxy.setter def str2_proxy(self, value): self.str2 = value * 2
def test_Rect() -> None: glyph = Rect() assert glyph.x == field("x") assert glyph.y == field("y") assert glyph.width == field("width") assert glyph.height == field("height") assert glyph.angle == 0 assert glyph.dilate is False check_line_properties(glyph) check_fill_properties(glyph) check_hatch_properties(glyph) check_properties_existence(glyph, [ "x", "y", "width", "width_units", "height", "height_units", "angle", "angle_units", "dilate", ], LINE, FILL, HATCH, GLYPH)