Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve sonarcloud warnings #49

Merged
merged 4 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
# 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:

Check warning on line 61 in src/autofaker/generator.py

View check run for this annotation

Codecov / codecov/patch

src/autofaker/generator.py#L61

Added line #L61 was not covered by tests
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()())

Check warning on line 25 in tests/test_create_anonymous_builtins.py

View check run for this annotation

Codecov / codecov/patch

tests/test_create_anonymous_builtins.py#L25

Added line #L25 was not covered by tests


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)
Loading