Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion snowfakery/data_generator_runtime_object_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
# objects that represent the hierarchy of a data generator.
# roughly similar to the YAML structure but with domain-specific objects
Definition = Union["ObjectTemplate", "SimpleValue", "StructuredValue"]
FieldValue = Union[None, Scalar, ObjectRow, tuple, PluginResult, ObjectReference]
FieldValue = Union[
None, bool, int, float, str, bytes, list, dict, tuple, set,
Scalar, ObjectRow, PluginResult, ObjectReference
]


class FieldDefinition(ABC):
Expand Down
5 changes: 5 additions & 0 deletions snowfakery/output_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class OutputStream(ABC):
type(None): noop,
bool: int,
Decimal: str,
list: lambda data: json.dumps(data),
dict: lambda data: json.dumps(data),
bytes: str,
tuple: lambda data: data,
set: lambda data: data,
}
uses_folder = False
uses_path = False
Expand Down
12 changes: 11 additions & 1 deletion tests/test_output_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ def do_output(self, yaml):

def test_csv_output(self):
yaml = """
- snowfakery_version: 3
- object: foo
fields:
a: 1
Expand All @@ -365,6 +366,13 @@ def test_csv_output(self):
fields:
barb: 2
bard: 4
- object: faz
fields:
list_t: ${{fake.json(data_columns={'Spec':'@1.0.1', 'ID':'pyint','Details':{'Name':'name', 'Address':'address'}}, num_rows=2)}}
dict_t: ${{fake.json(data_columns={'Spec':'@1.0.1', 'ID':'pyint','Details':{'Name':'name', 'Address':'address'}}, num_rows=1)}}
bool_t: ${{fake.pybool()}}
tuple_t: ${{(1, 2)}}
bytes_t: ${{fake.binary(length=64)}}
"""
with TemporaryDirectory() as t:
output_stream = CSVOutputStream(Path(t) / "csvoutput")
Expand All @@ -373,13 +381,15 @@ def test_csv_output(self):
assert messages
assert "foo.csv" in messages[0]
assert "bar.csv" in messages[1]
assert "csvw" in messages[2]
assert "faz.csv" in messages[2]
assert "csvw" in messages[3]
assert (Path(t) / "csvoutput" / "foo.csv").exists()
with open(Path(t) / "csvoutput" / "csvw_metadata.json") as f:
metadata = json.load(f)
assert {table["url"] for table in metadata["tables"]} == {
"foo.csv",
"bar.csv",
"faz.csv",
}

def test_null(self):
Expand Down
Loading