async def test_parse_hard(self): topic = """ @foo(comma: ",", colon: ":", escape: '"') """ c = parse_directives(topic) props = parse_multi(next(c)[1]) assert props["comma"] == "," assert props["colon"] == ":" assert props["escape"] == '"'
async def test_parse_str(self): topic = """ @quote('foo') @doublequote("foo") @noquote(foo) """ c = parse_directives(topic) assert parse_single(next(c)[1]) == "foo" assert parse_single(next(c)[1]) == "foo" assert parse_single(next(c)[1]) == "foo"
async def test_parse_multi(self): topic = """ @foo(int: 123, float: 4.56, bool: true, string: "foo") """ c = parse_directives(topic) props = parse_multi(next(c)[1]) assert props["int"] == 123 assert props["float"] == 4.56 assert props["bool"] assert props["string"] == "foo"
def install(self, update: str): for installer, props in directives.parse_directives(update): if installer is None: self.issue(f"Unknown directive: {props}", area="General") continue try: self.issues.pop(f"@{installer.__name__}", None) installer(self, props) except Exception: self.issue(f"Failed installing: `@{installer}({props})`", "General")
async def test_parse_single(self): topic = """ @int(123) @float(4.56) @bool(true) @string("foo") """ c = parse_directives(topic) assert parse_single(next(c)[1]) == 123 assert parse_single(next(c)[1]) == 4.56 assert parse_single(next(c)[1]) assert parse_single(next(c)[1]) == "foo"
async def test_parse_bool(self): topic = """ @TRUE(TRUE) @True(True) @true(true) @FALSE(FALSE) @False(False) @false(false) """ c = parse_directives(topic) v = parse_single(next(c)[1]) assert type(v) is bool and v v = parse_single(next(c)[1]) assert type(v) is bool and v v = parse_single(next(c)[1]) assert type(v) is bool and v v = parse_single(next(c)[1]) assert type(v) is bool and not v v = parse_single(next(c)[1]) assert type(v) is bool and not v v = parse_single(next(c)[1]) assert type(v) is bool and not v