Skip to content

Commit

Permalink
Merge pull request #48 from christianhelle/resolve-warnings
Browse files Browse the repository at this point in the history
Autodata docs
  • Loading branch information
christianhelle authored Oct 19, 2024
2 parents 000f7e7 + 1ae18dd commit a11a90b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 33 deletions.
45 changes: 25 additions & 20 deletions src/autofaker/autodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ def create(t, use_fake_data: bool = False):
"""
Creates an anonymous variable of the requested type
:param type t:
type - The type to generate data for
:param use_fake_data:
bool - Set this to True to use Faker to generate data
otherwise False to generate anonymous data
:param type t: type
The type to generate data for
:param use_fake_data: bool
Set this to True to use Faker to generate data
otherwise False to generate anonymous data
"""
return TypeDataGenerator.create(t, use_fake_data=use_fake_data).generate()

Expand All @@ -35,13 +36,15 @@ def create_many(t, size: int = 3, use_fake_data: bool = False) -> List[typing.An
Creates a list of anonymous variables of the requested
type using the specified length (default 3)
:param type t:
type - The type to generate data for
:type size:
int - The number of items to generate (default 3)
:param use_fake_data:
bool - Set this to True to use Faker to generate data,
otherwise False to generate anonymous data
:param type t: (type)
The type to generate data for
:param size: (int)
The number of items to generate (default 3)
:param use_fake_data: (bool)
Set this to True to use Faker to generate data,
otherwise False to generate anonymous data
"""
items = []
for _ in range(size):
Expand All @@ -54,13 +57,15 @@ def create_pandas_dataframe(t, rows: int = 3, use_fake_data: bool = False):
Create a Pandas DataFrame containing anonymous data
with the specified number of rows (default 3)
:param type t:
object - The class that represents the DataFrame.
This can be a plain old class or a @dataclass
:param type rows:
int - The number of rows to generate for the DataFrame (default 3)
:param use_fake_data:
bool - Set this to True to use Faker to generate data,
otherwise False to generate anonymous data
:param type t: object
The class that represents the DataFrame.
This can be a plain old class or a @dataclass
:param type rows: int
The number of rows to generate for the DataFrame (default 3)
:param use_fake_data: bool
Set this to True to use Faker to generate data,
otherwise False to generate anonymous data
"""
return PandasDataFrameGenerator(t, rows, use_fake_data=use_fake_data).generate()
51 changes: 38 additions & 13 deletions src/autofaker/decorators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Provides anonymous object creation functions to help minimize the setup/arrange phase when writing unit tests
Provides anonymous object creation functions to help minimize
the setup/arrange phase when writing unit tests
"""

import inspect
Expand All @@ -11,7 +12,8 @@

def autodata(*types: object, use_fake_data: bool = False):
"""
Creates anonymous variable of the requested types and pass them as arguments to a unit test function
Creates anonymous variable of the requested types
and pass them as arguments to a unit test function
Example:
Expand All @@ -26,8 +28,14 @@ def test_create_str_argument_using_decorator(self, text, number, decimal, boolea
self.assertIsNotNone(text)
:param use_fake_data: bool - Set this to True to use Faker to generate data, otherwise False to generate anonymous data
:param type types: tuple - The types to generate data. This is optional and will use the arguments from the function being decorated if not specified
:param use_fake_data: bool
Set this to True to use Faker to generate data,
otherwise False to generate anonymous data
:param type types: tuple
The types to generate data.
This is optional and will use the arguments
from the function being decorated if not specified
"""

def decorator(function):
Expand Down Expand Up @@ -56,7 +64,8 @@ def wrapper(*args):

def fakedata(*types: object):
"""
Creates fake values for the variables of the requested types and pass them as arguments to a unit test function
Creates fake values for the variables of the requested types
and pass them as arguments to a unit test function
Example:
Expand All @@ -71,7 +80,10 @@ def test_create_fake_arguments(self, text: str, number: int, decimal: float, boo
self.assertIsNotNone(text)
:param types: object - The types to generate data. This is optional and will use the arguments from the function being decorated if not specified
:param types: object
The types to generate data.
This is optional and will use the arguments from the function
being decorated if not specified
"""

def decorator(function):
Expand All @@ -98,11 +110,19 @@ def wrapper(*args):

def autopandas(t: object, rows: int = 3, use_fake_data: bool = False):
"""
Create a Pandas DataFrame containing anonymous data with the specified number of rows (default 3)
Create a Pandas DataFrame containing anonymous data
with the specified number of rows (default 3)
:param type t: object
The class that represents the DataFrame.
This can be a plain old class or a @dataclass
:param type t: object - The class that represents the DataFrame. This can be a plain old class or a @dataclass
:param type rows: int - The number of rows to generate for the DataFrame (default 3)
:param use_fake_data: bool - Set this to True to use Faker to generate data, otherwise False to generate anonymous data
:param type rows: int
The number of rows to generate for the DataFrame (default 3)
:param use_fake_data: bool
Set this to True to use Faker to generate data,
otherwise False to generate anonymous data
"""

def decorator(function):
Expand All @@ -121,10 +141,15 @@ def wrapper(*args):

def fakepandas(t, rows: int = 3):
"""
Create a Pandas DataFrame containing fake data with the specified number of rows (default 3)
Create a Pandas DataFrame containing fake data with
the specified number of rows (default 3)
:param type t: object
The class that represents the DataFrame.
This can be a plain old class or a @dataclass
:param type t: object - The class that represents the DataFrame. This can be a plain old class or a @dataclass
:param type rows: int - The number of rows to generate for the DataFrame (default 3)
:param type rows: int
The number of rows to generate for the DataFrame (default 3)
"""
return autopandas(t, rows, use_fake_data=True)

Expand Down

0 comments on commit a11a90b

Please sign in to comment.