Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 22, 2023
1 parent 2448a78 commit 1f6f2cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/sqlacodegen/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,9 +1002,13 @@ def generate_relationship_name(
RelationshipType.ONE_TO_MANY,
RelationshipType.MANY_TO_MANY,
):
singular_inflected_name = self.inflect_engine.singular_noun(preferred_name)
singular_inflected_name = self.inflect_engine.singular_noun(
preferred_name
)
if singular_inflected_name:
preferred_name = self.inflect_engine.plural_noun(singular_inflected_name)
preferred_name = self.inflect_engine.plural_noun(
singular_inflected_name
)
else:
inflected_name = self.inflect_engine.singular_noun(preferred_name)
if inflected_name:
Expand Down
33 changes: 21 additions & 12 deletions tests/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,9 @@ class SimpleItems(Base):
)

@pytest.mark.parametrize("generator", [["use_inflect"]], indirect=True)
def test_onetomany_inflect_singular_table_name(self, generator: CodeGenerator) -> None:
def test_onetomany_inflect_singular_table_name(
self, generator: CodeGenerator
) -> None:
Table(
# inflect_engine.singular_noun() should not make this name to 'False':
"simple_item",
Expand Down Expand Up @@ -1926,26 +1928,32 @@ class SimpleItem(Base):
)

@pytest.mark.parametrize("generator", [["use_inflect"]], indirect=True)
def test_use_inflect_plural_double_pluralize(self, generator: CodeGenerator) -> None:
def test_use_inflect_plural_double_pluralize(
self, generator: CodeGenerator
) -> None:
Table(
"users",
generator.metadata,
Column("users_id", INTEGER),
Column("groups_id", INTEGER),
ForeignKeyConstraint(['groups_id'], ['groups.groups_id'], name='fk_users_groups_id'),
PrimaryKeyConstraint('users_id', name='users_pkey'),
ForeignKeyConstraint(
["groups_id"], ["groups.groups_id"], name="fk_users_groups_id"
),
PrimaryKeyConstraint("users_id", name="users_pkey"),
)

Table("groups",
generator.metadata,
Column("groups_id", INTEGER),
Column("group_name", Text(50), nullable=False),
PrimaryKeyConstraint('groups_id', name='groups_pkey'),
)
Table(
"groups",
generator.metadata,
Column("groups_id", INTEGER),
Column("group_name", Text(50), nullable=False),
PrimaryKeyConstraint("groups_id", name="groups_pkey"),
)

validate_code(
generator.generate(),
("""\
(
"""\
from sqlalchemy import Column, ForeignKeyConstraint, Integer, PrimaryKeyConstraint, Text
from sqlalchemy.orm import declarative_base, relationship
Expand Down Expand Up @@ -1975,7 +1983,8 @@ class User(Base):
groups_id = Column(Integer)
group = relationship('Group', back_populates='users')
""")
"""
),
)

def test_table_kwargs(self, generator: CodeGenerator) -> None:
Expand Down

0 comments on commit 1f6f2cb

Please sign in to comment.