def test_CustomObject_config_schema_to_string(config_source, schema_source, string_io): with Schema.scope().registered(HOSTNAME=HOSTNAME, WORKDIR=WORKDIR), \ Config.scope().registered(HOSTNAME=HOSTNAME, WORKDIR=WORKDIR): schema = Schema.from_string(schema_source) config = Config.from_string(config_source, defaults=False, schema=schema) config.to_stream(string_io) s = string_io.getvalue() assert s == """\
def test_CustomObject_config_schema(config_source, schema_source): with Schema.scope().registered(HOSTNAME=HOSTNAME, WORKDIR=WORKDIR), \ Config.scope().registered(HOSTNAME=HOSTNAME, WORKDIR=WORKDIR): schema = Schema.from_string(schema_source) config = Config.from_string(config_source, schema=schema) assert config["x"] == HOSTNAME assert config["alpha"]["y"] == WORKDIR assert config["alpha"]["z"] == HOSTNAME + ":" + WORKDIR
def schema_minmax(minmax): return minmax, Schema.from_string("""\ dt = DateTimeOption(default=DateTime.{mm}, doc="datetime") dd = DateOption(default=Date.{mm}, doc="date") tt = TimeOption(default=Time.{mm}, doc="time") td = TimeDeltaOption(default=TimeDelta.{mm}, allow_none=True, doc="timedelta") """.format(mm=minmax))
def schema(dt, dd, tt, td): return Schema.from_string("""\ dt = DateTimeOption(default={dt!r}, allow_none=True, doc="datetime") dd = DateOption(default={dd!r}, allow_none=True, doc="date") tt = TimeOption(default={tt!r}, allow_none=True, doc="time") td = TimeDeltaOption(default={td!r}, allow_none=True, doc="timedelta") """.format(dt=dt, dd=dd, tt=tt, td=td))
def schema(): return Schema.from_string("""\ __default_option__ = Str() [a] __default_option__ = Int() [__default_section__] __default_option__ = Float() x = Int(default=10) [aa] x = Str(default="aaxxx") [ab] [__default_section__] x = Float() x = Str(default="abxxx") [ac] [__default_section__] x = Str(default="acxxx") [b] [bb] [c] __default_option__ = Complain() [d] [__default_section__] __default_option__ = Int() [e] [__default_section__] __default_option__ = Int() [__default_section__] __default_option__ = Complain() """)
def test_Schema_class_attributes_serialization(mmkey): source = """\ x = TimeDeltaOption(default=MTimeDelta.{}) """.format(mmkey) schema = Schema.from_string(source) assert schema.to_string() == """\ x = TimeDeltaOption(default=MTimeDelta.{}) """.format(mmkey)
def schema_complain(): return Schema.from_string("""\ arg0 = Complain(doc="argument 0") """)
def schema_remove(): return Schema.from_string("""\ arg0 = Remove(doc="argument 0") """)
def schema_ignore(): return Schema.from_string("""\ arg0 = Ignore(doc="argument 0") """)
def schema_any(): return Schema.from_string("""\ arg0 = Any(doc="argument 0") arg1 = Any(default=10, doc="argument 1") arg2 = Any(default=None, doc="argument 1") """)
def test_Schema_times_serialization(source): schema = Schema.from_string(source) assert source == schema.to_string().rstrip('\n')
def schema_now(): return Schema.from_string("""\ dtnow = DateTimeOption(default=DateTime.load_time(), doc="datetime now") dttoday = DateTimeOption(default=DateTime.today(), doc="datetime today") ddtoday = DateOption(default=Date.today(), doc="date today") """.format(mm=minmax))
def test_CustomObject_schema(schema_source, string_io): with Schema.scope().registered(HOSTNAME=HOSTNAME, WORKDIR=WORKDIR): schema = Schema.from_string(schema_source) schema.to_stream(string_io)
def test_CustomObject_schema_error(schema_source): with pytest.raises(ValueError): schema = Schema.from_string(schema_source)