diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-02-14 09:09:15 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-02-14 10:43:33 -0500 |
commit | 05eb969a778121ecab621652400904a8983749e9 (patch) | |
tree | 5128f5cb2d3427121bb911737c43818fcb1d2cef | |
parent | 1b726c48384931c813d254b6451cfb6ea4e5b882 (diff) | |
download | sqlalchemy-05eb969a778121ecab621652400904a8983749e9.tar.gz |
test dataclasses.KW_ONLY
had no test support for this, seems to work. gets
grabbed in annotations and applied correctly.
Change-Id: I2cd7ad7b376f38f945d2007b316a1316271f9a0f
-rw-r--r-- | test/orm/declarative/test_dc_transforms.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/test/orm/declarative/test_dc_transforms.py b/test/orm/declarative/test_dc_transforms.py index 0bf601455..9b7c72778 100644 --- a/test/orm/declarative/test_dc_transforms.py +++ b/test/orm/declarative/test_dc_transforms.py @@ -593,8 +593,8 @@ class DCTransformsTest(AssertsCompiledSQL, fixtures.TestBase): a2 = A(id=1, data="foo") eq_(a1, a2) - @testing.only_if(lambda: compat.py310, "python 3.10 is required") - def test_kw_only(self, dc_decl_base: Type[MappedAsDataclass]): + @testing.requires.python310 + def test_kw_only_attribute(self, dc_decl_base: Type[MappedAsDataclass]): class A(dc_decl_base): __tablename__ = "a" @@ -605,6 +605,24 @@ class DCTransformsTest(AssertsCompiledSQL, fixtures.TestBase): eq_(fas.args, ["self", "id"]) eq_(fas.kwonlyargs, ["data"]) + @testing.requires.python310 + def test_kw_only_dataclass_constant( + self, dc_decl_base: Type[MappedAsDataclass] + ): + class Mixin(MappedAsDataclass): + a: Mapped[int] = mapped_column(primary_key=True) + b: Mapped[int] = mapped_column(default=1) + + class Child(Mixin, dc_decl_base): + + __tablename__ = "child" + + _: dataclasses.KW_ONLY + c: Mapped[int] + + c1 = Child(1, c=5) + eq_(c1, Child(a=1, b=1, c=5)) + def test_mapped_column_overrides(self, dc_decl_base): """test #8688""" |