From 444aae75d007ba4744345a4ea67161f596269bbe Mon Sep 17 00:00:00 2001 From: Christian Helle Date: Sat, 19 Oct 2024 17:54:20 +0200 Subject: [PATCH 1/4] use isinstance() for direct type comparison --- src/autofaker/generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/autofaker/generator.py b/src/autofaker/generator.py index 5ce4f97..dbf5c8b 100644 --- a/src/autofaker/generator.py +++ b/src/autofaker/generator.py @@ -58,7 +58,7 @@ def _get_type_name(t) -> str: # because it will always be a string. This is because, annotations # transforms any type into a string object. Therefore, if the type # is a string, assess if it is the name of a known primitive type. - elif type(t) == str and t in PRIMITIVE_TYPES: + elif t.isinstance(str) and t in PRIMITIVE_TYPES: return t return type(t).__name__ From e1f6f90eaf0591ab8c05935303241877f793a4cf Mon Sep 17 00:00:00 2001 From: Christian Helle Date: Sat, 19 Oct 2024 21:58:54 +0200 Subject: [PATCH 2/4] Specify return types --- tests/test_create_anonymous_builtins.py | 42 ++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/test_create_anonymous_builtins.py b/tests/test_create_anonymous_builtins.py index aa2da68..da6ea22 100644 --- a/tests/test_create_anonymous_builtins.py +++ b/tests/test_create_anonymous_builtins.py @@ -1,80 +1,80 @@ import unittest from abc import abstractmethod +from typing import Type from autofaker import Autodata class CreateTestCase(unittest.TestCase): @abstractmethod - def getType(self): + def getType(self) -> Type: pass def test_create_returns_not_none(self): - if self.getType() is None: - return - self.assertIsNotNone(Autodata.create(self.getType())) + if self.getType() is not None: + self.assertIsNotNone(Autodata.create(self.getType())) def test_create_returns_not_type(self): - if self.getType() is None: - return - self.assertNotIsInstance(Autodata.create(self.getType()), type) + if self.getType() is not None: + self.assertNotIsInstance(Autodata.create(self.getType()), type) def test_create_returns_not_default(self): - if self.getType() is None or self.getType() is bool or range: - return - self.assertNotEqual(Autodata.create(self.getType()), self.getType()()) + if (self.getType() is not None + and not bool + and not range): + self.assertNotEqual(Autodata.create(self.getType()), self.getType()()) class AnonymousIntegerTestCase(CreateTestCase): - def getType(self): + def getType(self) -> Type[int]: return int class AnonymousStringTestCase(CreateTestCase): - def getType(self): + def getType(self) -> Type[str]: return str class AnonymousFloatTestCase(CreateTestCase): - def getType(self): + def getType(self) -> Type[float]: return float class AnonymousBooleanTestCase(CreateTestCase): - def getType(self): + def getType(self) -> Type[bool]: return bool class AnonymousComplexTestCase(CreateTestCase): - def getType(self): + def getType(self) -> Type[complex]: return complex class AnonymousRangeTestCase(CreateTestCase): - def getType(self): + def getType(self) -> Type[range]: return range class AnonymousBytesTestCase(CreateTestCase): - def getType(self): + def getType(self) -> Type[bytes]: return bytes class AnonymousByteArrayTestCase(CreateTestCase): - def getType(self): + def getType(self) -> Type[bytearray]: return bytearray class AnonymousMemoryViewTestCase(CreateTestCase): - def getType(self): + def getType(self) -> Type[memoryview]: return memoryview class AnonymousSetTestCase(CreateTestCase): - def getType(self): + def getType(self) -> Type[set]: return set class AnonymousFrozensetTestCase(CreateTestCase): - def getType(self): + def getType(self) -> Type[frozenset]: return frozenset From a989d7fcfff16587fc4c9190431d395658f39dbc Mon Sep 17 00:00:00 2001 From: Christian Helle Date: Sat, 19 Oct 2024 22:18:47 +0200 Subject: [PATCH 3/4] Use assertIn instead of assertTrue --- .../test_create_anonymous_dataframe_pandas.py | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/test_create_anonymous_dataframe_pandas.py b/tests/test_create_anonymous_dataframe_pandas.py index 0a7f831..83b57c9 100644 --- a/tests/test_create_anonymous_dataframe_pandas.py +++ b/tests/test_create_anonymous_dataframe_pandas.py @@ -40,16 +40,16 @@ def test_can_create_anonymous_pandas_dataframes_from_class_with_constructor_argu self, ): df = Autodata.create_pandas_dataframe(SimpleClassB) - self.assertTrue("id" in df.columns) - self.assertTrue("name" in df.columns) - self.assertTrue("text" in df.columns) + self.assertIn("id", df.columns) + self.assertIn("name", df.columns) + self.assertIn("text", df.columns) def test_can_create_anonymous_pandas_dataframes_from_class_with_constructor_class_arguments( self, ): df = Autodata.create_pandas_dataframe(SimpleClassC) - self.assertTrue("a" in df.columns) - self.assertTrue("b" in df.columns) + self.assertIn("a", df.columns) + self.assertIn("b", df.columns) class CreateFakePandasDataFrameTests(unittest.TestCase): @@ -69,16 +69,16 @@ def test_can_create_fake_pandas_dataframes_from_class_with_constructor_arguments self, ): df = Autodata.create_pandas_dataframe(SimpleClassB, use_fake_data=True) - self.assertTrue("id" in df.columns) - self.assertTrue("name" in df.columns) - self.assertTrue("text" in df.columns) + self.assertIn("id", df.columns) + self.assertIn("name", df.columns) + self.assertIn("text", df.columns) def test_can_create_fake_pandas_dataframes_from_class_with_constructor_class_arguments( self, ): df = Autodata.create_pandas_dataframe(SimpleClassC, use_fake_data=True) - self.assertTrue("a" in df.columns) - self.assertTrue("b" in df.columns) + self.assertIn("a", df.columns) + self.assertIn("b", df.columns) @dataclass @@ -118,16 +118,16 @@ def test_can_create_anonymous_pandas_dataframes_from_class_with_constructor_clas self, ): df = Autodata.create_pandas_dataframe(HybridClassA) - self.assertTrue("b" in df.columns) - self.assertTrue("a" in df.columns) + self.assertIn("b", df.columns) + self.assertIn("a", df.columns) def test_can_create_anonymous_pandas_dataframes_from_class_with_constructor_hybrid_class_arguments( self, ): df = Autodata.create_pandas_dataframe(HybridClassB) - self.assertTrue("c" in df.columns) - self.assertTrue("b" in df.columns) - self.assertTrue("a" in df.columns) + self.assertIn("c", df.columns) + self.assertIn("b", df.columns) + self.assertIn("a", df.columns) class CreateFakePandasDataFrameFromDataClassTests(unittest.TestCase): @@ -147,13 +147,13 @@ def test_can_create_fake_pandas_dataframes_from_class_with_constructor_class_arg self, ): df = Autodata.create_pandas_dataframe(HybridClassA, use_fake_data=True) - self.assertTrue("b" in df.columns) - self.assertTrue("a" in df.columns) + self.assertIn("b", df.columns) + self.assertIn("a", df.columns) def test_can_create_anonymous_pandas_dataframes_from_class_with_constructor_hybrid_class_arguments( self, ): df = Autodata.create_pandas_dataframe(HybridClassB, use_fake_data=True) - self.assertTrue("c" in df.columns) - self.assertTrue("b" in df.columns) - self.assertTrue("a" in df.columns) + self.assertIn("c", df.columns) + self.assertIn("b", df.columns) + self.assertIn("a", df.columns) From abb1dd2feda15c547327ba688ec1db7f51aba483 Mon Sep 17 00:00:00 2001 From: Christian Helle Date: Sat, 19 Oct 2024 22:33:35 +0200 Subject: [PATCH 4/4] Fix typo in build 3.13 linux workflow --- .github/workflows/build-python-313-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-python-313-linux.yml b/.github/workflows/build-python-313-linux.yml index 53c2b15..8d01ec5 100644 --- a/.github/workflows/build-python-313-linux.yml +++ b/.github/workflows/build-python-313-linux.yml @@ -19,4 +19,4 @@ jobs: uses: ./.github/workflows/build.yml with: python_version: 3.13 - os: ubuntu-latest3 \ No newline at end of file + os: ubuntu-latest