Skip to content

Commit

Permalink
Merge pull request #49 from christianhelle/resolve-sonarcloud-warnings
Browse files Browse the repository at this point in the history
resolve sonarcloud warnings
  • Loading branch information
christianhelle authored Oct 19, 2024
2 parents a11a90b + abb1dd2 commit f2906bc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-python-313-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
uses: ./.github/workflows/build.yml
with:
python_version: 3.13
os: ubuntu-latest3
os: ubuntu-latest
2 changes: 1 addition & 1 deletion src/autofaker/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down
42 changes: 21 additions & 21 deletions tests/test_create_anonymous_builtins.py
Original file line number Diff line number Diff line change
@@ -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
40 changes: 20 additions & 20 deletions tests/test_create_anonymous_dataframe_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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)

0 comments on commit f2906bc

Please sign in to comment.