Skip to content

Commit

Permalink
Fix deep object row references
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Prescod committed Jun 5, 2022
1 parent 7763e3d commit 7844d2c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 31 deletions.
8 changes: 6 additions & 2 deletions snowfakery/row_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from random import randint

from snowfakery import data_gen_exceptions as exc
from snowfakery.object_rows import LazyLoadedObjectReference
from snowfakery.object_rows import LazyLoadedObjectReference, ObjectRow
from snowfakery.utils.pickle import RestrictedPickler
from snowfakery.object_rows import NicknameSlot, ObjectReference

Expand Down Expand Up @@ -167,7 +167,11 @@ def _make_history_table(conn, tablename):
NicknameSlot: lambda n: (
ObjectReference,
(n._tablename, n.allocated_id),
)
),
ObjectRow: lambda v: (
ObjectRow,
(v._tablename, v._values),
),
}

_SAFE_CLASSES = {
Expand Down
82 changes: 53 additions & 29 deletions tests/test_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,32 +913,56 @@ def test_random_reference_to_objects_with_diverse_types(self, generated_rows):
assert parse_date(generated_rows.table_values("B", 1, "datetime1ref"))
assert parse_date(generated_rows.table_values("B", 1, "datetime2ref"))

# TODO: Make this work
# def test_random_references__nested_1(self, generate_data_with_continuation, generated_rows):
# yaml = """
# - object: Parent
# count: 2
# fields:
# child1:
# - object: Child1
# fields:
# child2:
# - object: Child2
# fields:
# name: TheName
# - object: Child3
# fields:
# A_ref:
# random_reference:
# to: Parent
# nested_name:
# ${{A_ref.child1.child2.name}}
# """
# generate(StringIO(yaml))
# # generate_data_with_continuation(
# # yaml=yaml,
# # target_number=("Parent", 4),
# # times=1,
# # )
# assert generated_rows.table_values("Child3", 1, "nested_name") == "TheName"
# assert generated_rows.table_values("Child3", -1, "nested_name") == "TheName"
def test_random_references__nested(self, generated_rows):
yaml = """
- object: Parent
count: 2
fields:
child1:
- object: Child1
fields:
child2:
- object: Child2
fields:
name: TheName
- object: Child3
fields:
A_ref:
random_reference:
to: Parent
nested_name:
${{A_ref.child1.child2.name}}
"""
generate(StringIO(yaml))
assert generated_rows.table_values("Child3", 1, "nested_name") == "TheName"
assert generated_rows.table_values("Child3", -1, "nested_name") == "TheName"

def test_random_references__nested__with_continuation(
self, generate_data_with_continuation, generated_rows
):
yaml = """
- object: Parent
count: 2
fields:
child1:
- object: Child1
fields:
child2:
- object: Child2
fields:
name: TheName
- object: Child3
fields:
A_ref:
random_reference:
to: Parent
nested_name:
${{A_ref.child1.child2.name}}
"""
generate_data_with_continuation(
yaml=yaml,
target_number=("Parent", 4),
times=1,
)
assert generated_rows.table_values("Child3", 1, "nested_name") == "TheName"
assert generated_rows.table_values("Child3", -1, "nested_name") == "TheName"

0 comments on commit 7844d2c

Please sign in to comment.