Skip to content

Commit 89bb36a

Browse files
committed
moves test out of class to accommodate pytest params
1 parent f0cfa32 commit 89bb36a

File tree

1 file changed

+68
-66
lines changed

1 file changed

+68
-66
lines changed

tests/unit/test_table.py

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6322,72 +6322,6 @@ def test_constructor_explicit_with_none(self):
63226322
self.assertIsNone(table_constraint.primary_key)
63236323
self.assertIsNone(table_constraint.foreign_keys)
63246324

6325-
@pytest.mark.parametrize(
6326-
"self_pk_name,self_fk_name,other_pk_name,other_fk_name,expected_equal",
6327-
[
6328-
(None, None, None, None, True),
6329-
('pkey', None, 'pkey', None, True),
6330-
('pkey', 'fkey', 'pkey', 'fkey', True),
6331-
(None, 'fkey', None, 'fkey', True),
6332-
('pkey', None, 'pkey_no_match', None, False),
6333-
('pkey', 'fkey', 'pkey_no_match', 'fkey_no_match', False),
6334-
(None, 'fkey', None, 'fkey_no_match', False),
6335-
('pkey', 'fkey', 'pkey_no_match', 'fkey', False),
6336-
('pkey', 'fkey', 'pkey', 'fkey_no_match', False),
6337-
]
6338-
)
6339-
def test_eq_parametrized(self, self_pk_name, self_fk_name, other_pk_name, other_fk_name, expected_equal):
6340-
# Imports are placed here to ensure they are self-contained for this example.
6341-
# In a real test file, they would likely be at the top of the file.
6342-
from google.cloud.bigquery.table import (
6343-
ColumnReference,
6344-
ForeignKey,
6345-
PrimaryKey,
6346-
TableReference,
6347-
TableConstraints,
6348-
)
6349-
6350-
# Helper function to create a PrimaryKey object or None
6351-
def _create_primary_key(name):
6352-
if name is None:
6353-
return None
6354-
return PrimaryKey(columns=[name])
6355-
6356-
# Helper function to create a list of ForeignKey objects or None
6357-
def _create_foreign_keys(name):
6358-
if name is None:
6359-
return None
6360-
# Using a generic referenced_table and column_references for simplicity
6361-
# The 'name' parameter ensures different ForeignKey objects for different names
6362-
return [
6363-
ForeignKey(
6364-
name=name,
6365-
referenced_table=TableReference.from_string(
6366-
f"my-project.my-dataset.{name}_referenced_table"
6367-
),
6368-
column_references=[
6369-
ColumnReference(
6370-
referencing_column=f"{name}_ref_col",
6371-
referenced_column=f"{name}_pk_col",
6372-
)
6373-
],
6374-
)
6375-
]
6376-
6377-
# Create the two TableConstraints instances for comparison
6378-
tc1 = TableConstraints(
6379-
primary_key=_create_primary_key(self_pk_name),
6380-
foreign_keys=_create_foreign_keys(self_fk_name),
6381-
)
6382-
tc2 = TableConstraints(
6383-
primary_key=_create_primary_key(other_pk_name),
6384-
foreign_keys=_create_foreign_keys(other_fk_name),
6385-
)
6386-
6387-
# Assert the equality based on the expected outcome
6388-
assert (tc1 == tc2) == expected_equal
6389-
6390-
63916325
def test__eq__other_type(self):
63926326
from google.cloud.bigquery.table import (
63936327
PrimaryKey,
@@ -6605,6 +6539,74 @@ def test_to_api_repr_empty_constraints(self):
66056539
self.assertEqual(instance.to_api_repr(), expected)
66066540

66076541

6542+
@pytest.mark.parametrize(
6543+
"self_pk_name,self_fk_name,other_pk_name,other_fk_name,expected_equal",
6544+
[
6545+
(None, None, None, None, True),
6546+
("pkey", None, "pkey", None, True),
6547+
("pkey", "fkey", "pkey", "fkey", True),
6548+
(None, "fkey", None, "fkey", True),
6549+
("pkey", None, "pkey_no_match", None, False),
6550+
("pkey", "fkey", "pkey_no_match", "fkey_no_match", False),
6551+
(None, "fkey", None, "fkey_no_match", False),
6552+
("pkey", "fkey", "pkey_no_match", "fkey", False),
6553+
("pkey", "fkey", "pkey", "fkey_no_match", False),
6554+
],
6555+
)
6556+
def test_table_constraint_eq_parametrized(
6557+
self_pk_name, self_fk_name, other_pk_name, other_fk_name, expected_equal
6558+
):
6559+
# Imports are placed here to ensure they are self-contained for this example.
6560+
# In a real test file, they would likely be at the top of the file.
6561+
from google.cloud.bigquery.table import (
6562+
ColumnReference,
6563+
ForeignKey,
6564+
PrimaryKey,
6565+
TableReference,
6566+
TableConstraints,
6567+
)
6568+
6569+
# Helper function to create a PrimaryKey object or None
6570+
def _create_primary_key(name):
6571+
if name is None:
6572+
return None
6573+
return PrimaryKey(columns=[name])
6574+
6575+
# Helper function to create a list of ForeignKey objects or None
6576+
def _create_foreign_keys(name):
6577+
if name is None:
6578+
return None
6579+
# Using a generic referenced_table and column_references for simplicity
6580+
# The 'name' parameter ensures different ForeignKey objects for different names
6581+
return [
6582+
ForeignKey(
6583+
name=name,
6584+
referenced_table=TableReference.from_string(
6585+
f"my-project.my-dataset.{name}_referenced_table"
6586+
),
6587+
column_references=[
6588+
ColumnReference(
6589+
referencing_column=f"{name}_ref_col",
6590+
referenced_column=f"{name}_pk_col",
6591+
)
6592+
],
6593+
)
6594+
]
6595+
6596+
# Create the two TableConstraints instances for comparison
6597+
tc1 = TableConstraints(
6598+
primary_key=_create_primary_key(self_pk_name),
6599+
foreign_keys=_create_foreign_keys(self_fk_name),
6600+
)
6601+
tc2 = TableConstraints(
6602+
primary_key=_create_primary_key(other_pk_name),
6603+
foreign_keys=_create_foreign_keys(other_fk_name),
6604+
)
6605+
6606+
# Assert the equality based on the expected outcome
6607+
assert (tc1 == tc2) == expected_equal
6608+
6609+
66086610
class TestExternalCatalogTableOptions:
66096611
PROJECT = "test-project"
66106612
DATASET_ID = "test_dataset"

0 commit comments

Comments
 (0)