{"id":13771759,"url":"https://github.com/christianhelle/autofaker","last_synced_at":"2025-04-15T14:57:32.185Z","repository":{"id":57412753,"uuid":"416217548","full_name":"christianhelle/autofaker","owner":"christianhelle","description":"Python library designed to minimize the setup/arrange phase of your unit tests","archived":false,"fork":false,"pushed_at":"2025-04-14T23:48:09.000Z","size":540,"stargazers_count":7,"open_issues_count":4,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-15T14:57:19.993Z","etag":null,"topics":["python","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/christianhelle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"christianhelle","patreon":null,"open_collective":null,"ko_fi":"christianhelle","tidelift":null,"community_bridge":null,"liberapay":"christianhelle","issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":["https://paypal.me/christianhelle","https://buymeacoffee.com/christianhelle"]}},"created_at":"2021-10-12T06:49:34.000Z","updated_at":"2025-03-25T13:02:08.000Z","dependencies_parsed_at":"2023-01-23T03:01:05.051Z","dependency_job_id":"9344ccf3-f688-465f-88e9-0b20486d9e5d","html_url":"https://github.com/christianhelle/autofaker","commit_stats":{"total_commits":307,"total_committers":3,"mean_commits":"102.33333333333333","dds":0.07817589576547235,"last_synced_commit":"adebc231347b3de5c1c3cb5c3917a703fcffaa9e"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christianhelle%2Fautofaker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christianhelle%2Fautofaker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christianhelle%2Fautofaker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christianhelle%2Fautofaker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/christianhelle","download_url":"https://codeload.github.com/christianhelle/autofaker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249094937,"owners_count":21211836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","unit-testing"],"created_at":"2024-08-03T17:00:55.188Z","updated_at":"2025-04-15T14:57:32.166Z","avatar_url":"https://github.com/christianhelle.png","language":"Python","funding_links":["https://github.com/sponsors/christianhelle","https://ko-fi.com/christianhelle","https://liberapay.com/christianhelle","https://paypal.me/christianhelle","https://buymeacoffee.com/christianhelle","https://www.buymeacoffee.com/christianhelle"],"categories":["Fake Data"],"sub_categories":[],"readme":"[![build](https://github.com/christianhelle/autofaker/actions/workflows/build-linux.yml/badge.svg)](https://github.com/christianhelle/autofaker/actions/workflows/build-linux.yml)\n[![build](https://github.com/christianhelle/autofaker/actions/workflows/build-macos.yml/badge.svg)](https://github.com/christianhelle/autofaker/actions/workflows/build-macos.yml)\n[![build](https://github.com/christianhelle/autofaker/actions/workflows/build-windows.yml/badge.svg)](https://github.com/christianhelle/autofaker/actions/workflows/build-windows.yml)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=christianhelle_autofaker\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=christianhelle_autofaker)\n[![PyPI](https://img.shields.io/pypi/dm/autofaker)](https://pypi.org/project/autofaker)\n[![buymeacoffee](https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow.svg)](https://www.buymeacoffee.com/christianhelle)\n\n# AutoFaker\n\nAutoFaker is a Python library designed to minimize the setup/arrange phase of your unit tests by removing the need to manually \nwrite code to create anonymous variables as part of a test cases setup/arrange phase. \n\nThis library is heavily inspired by [AutoFixture](https://github.com/AutoFixture/AutoFixture) and was initially created \nfor simplifying how to write unit tests for ETL (Extract-Transform-Load) code running from a python library on an \nApache Spark cluster in Big Data solutions.\n\nWhen writing unit tests you normally start with creating objects that represent the initial state of the test.\nThis phase is called the **arrange** or setup phase of the test.\nIn most cases, the system you want to test will force you to specify much more information than you really care about, \nso you frequently end up creating objects with no influence on the test itself just simply to satisfy the compiler/interpreter\n\n[AutoFaker](https://pypi.org/project/autofaker/) is available from PyPI and should be installed using `pip`\n\n```\npip install autofaker\n```\n\nAutoFaker can help by creating such anonymous variables for you. Here's a simple example:\n\n```python\nimport unittest\nfrom autofaker import Autodata\n\nclass Calculator:\n  def add(self, number1: int, number2: int):\n    return number1 + number2\n\nclass CalculatorTests(unittest.TestCase):\n    def test_can_add_two_numbers(self):      \n        # arrange\n        numbers = Autodata.create_many(int, 2)\n        sut = Autodata.create(Calculator)        \n        # act\n        result = sut.add(numbers[0], numbers[1])        \n        # assert\n        self.assertEqual(numbers[0] + numbers[1], result)\n```\n\nSince the point of this library is to simplify the **arrange** step of writing unit tests, we can use the\n`@autodata` and `@fakedata` are available to explicitly state \nwhether to use anonymous variables or fake data and construct our system under test.\nTo use this you can either define the types or the arguments as function arguments to the decorator, or specify \nargument annotations\n\n```python\nimport unittest\nfrom autofaker import autodata\n\nclass Calculator:\n  def add(self, number1: int, number2: int):\n    return number1 + number2\n\nclass CalculatorTests(unittest.TestCase):\n    @autodata(Calculator, int, int)\n    def test_can_add_two_numbers_using_test_arguments(self, sut, number1, number2):\n        result = sut.add(number1, number2)\n        self.assertEqual(number1 + number2, result)\n\n    @autodata()\n    def test_can_add_two_numbers_using_annotated_arguments(self, \n                                                           sut: Calculator, \n                                                           number1: int, \n                                                           number2: int):\n        result = sut.add(number1, number2)\n        self.assertEqual(number1 + number2, result)\n```\n\nThere are times when completely anonymous variables don't make much sense, especially in data centric scenarios. \nFor these use cases this library uses [Faker](https://github.com/joke2k/faker) for generating fake data. This option \nis enabled by setting `use_fake_data` to `True` when calling the `Autodata.create()` function\n\n```python\nfrom dataclasses import dataclass\nfrom autofaker import Autodata\n\n@dataclass\nclass DataClass:\n    id: int\n    first_name: str\n    last_name: str\n    job: str\n\ndata = Autodata.create(DataClass, use_fake_data=True)\n\nprint(f'id:     {data.id}')\nprint(f'name:   {data.first_name} {data.last_name}')\nprint(f'job:    {data.job}\\n')\n```\n\nThe following code above might output something like:\n\n```\nid:     8952\nname:   Justin Wise\njob:    Chief Operating Officer\n```\n\n## Supported OS and Python versions\n\n|Windows|MacOS|Linux|\n|---|---|---|\n![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-38-windows.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-38-macos.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-38-linux.yml/badge.svg)|\n![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-39-windows.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-39-macos.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-39-linux.yml/badge.svg)|\n![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-310-windows.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-310-macos.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-310-linux.yml/badge.svg)|\n![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-311-windows.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-311-macos.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-311-linux.yml/badge.svg)|\n![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-312-windows.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-312-macos.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-312-linux.yml/badge.svg)|\n![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-313-windows.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-313-macos.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-313-linux.yml/badge.svg)|\n\n## Supported data types\n\nCurrently autofaker supports creating anonymous variables for the following data types:\n\nBuilt-in types:\n- int\n- float\n- str\n- complex\n- range\n- bytes\n- bytearray\n\nDatetime types:\n- datetime\n- date\n\nClasses:\n- Simple classes\n- @dataclass\n- Nested classes (and recursion)\n- Classes containing lists of other types\n- Enum classes\n\nDataframes:\n- Pandas dataframe\n\n\n## Example usages\n\nCreate anonymous built-in types like `int`, `float`, `str` and datetime types like `datetime` and `date`\n\n```python\nprint(f'anonymous string:    {Autodata.create(str)}')\nprint(f'anonymous int:       {Autodata.create(int)}')\nprint(f'anonymous float:     {Autodata.create(float)}')\nprint(f'anonymous complex:   {Autodata.create(complex)}')\nprint(f'anonymous range:     {Autodata.create(range)}')\nprint(f'anonymous bytes:     {Autodata.create(bytes)}')\nprint(f'anonymous bytearray: {Autodata.create(bytearray)}')\nprint(f'anonymous datetime:  {Autodata.create(datetime)}')\nprint(f'anonymous date:      {Autodata.create(datetime.date)}')\n```\n\nThe code above might output the following\n\n```\nanonymous string:    f91954f1-96df-463f-a427-665c99213395\nanonymous int:       2066712686\nanonymous float:     725758222.8712853\nanonymous datetime:  2017-06-19 02:40:41.000084\nanonymous date:      2019-11-10 00:00:00\n```\n\nCreates an anonymous class\n\n```python\n\nclass SimpleClass:\n    id = -1\n    text = 'test'\n\ncls = Autodata.create(SimpleClass)\nprint(f'id = {cls.id}')\nprint(f'text = {cls.text}')\n```\n\nThe code above might output the following\n\n```\nid = 2020177162\ntext = ac54a65d-b4a3-4eda-a840-eb948ad10d5f\n```\n\nCreate a collection of an anonymous class\n\n```python\nclass SimpleClass:\n    id = -1\n    text = 'test'\n\nclasses = Autodata.create_many(SimpleClass)\nfor cls in classes:\n  print(f'id = {cls.id}')\n  print(f'text = {cls.text}')\n  print()\n```\n\nThe code above might output the following\n\n```\nid = 242996515\ntext = 5bb60504-ccca-4104-9b7f-b978e52a6518\n\nid = 836984239\ntext = 079df61e-a87e-4f26-8196-3f44157aabd6\n\nid = 570703150\ntext = a3b86f08-c73a-4730-bde7-4bdff5360ef4\n```\n\nCreates an anonymous dataclass\n\n```python\nfrom dataclasses import dataclass\n\n@dataclass\nclass DataClass:\n    id: int\n    text: str\n\ncls = Autodata.create(DataClass)\nprint(f'id = {cls.id}')\nprint(f'text = {cls.text}')\n```\n\nThe code above might output the following\n\n```\nid = 314075507\ntext = 4a3b3cae-f4cf-4502-a7f3-61115a1e0d2a\n```\n\nCreates an anonymous dataclass using fake data\n\n```python\n@dataclass\nclass DataClass:\n    id: int\n\n    name: str\n    address: str\n    job: str\n\n    country: str\n    currency_name: str\n    currency_code: str\n\n    email: str\n    safe_email: str\n    company_email: str\n\n    hostname: str\n    ipv4: str\n    ipv6: str\n\n    text: str\n\n\ndata = Autodata.create(DataClass, use_fake_data=True)\n\nprint(f'id:               {data.id}')\nprint(f'name:             {data.name}')\nprint(f'job:              {data.job}\\n')\nprint(f'address:\\n{data.address}\\n')\n\nprint(f'country:          {data.country}')\nprint(f'currency name:    {data.currency_name}')\nprint(f'currency code:    {data.currency_code}\\n')\n\nprint(f'email:            {data.email}')\nprint(f'safe email:       {data.safe_email}')\nprint(f'work email:       {data.company_email}\\n')\n\nprint(f'hostname:         {data.hostname}')\nprint(f'IPv4:             {data.ipv4}')\nprint(f'IPv6:             {data.ipv6}\\n')\n\nprint(f'text:\\n{data.text}')\n```\n\nThe code above might output the following\n\n```\nid:               8952\nname:             Justin Wise\njob:              Chief Operating Officer\n\naddress:\n65939 Hernandez Parks\nRochaport, NC 41760\n\ncountry:          Equatorial Guinea\ncurrency name:    Burmese kyat\ncurrency code:    ERN\n\nemail:            smithjohn@example.com\nsafe email:       kent11@example.com\nwork email:       marissagreen@brown-cole.com\n\nhostname:         db-90.hendricks-west.org\nIPv4:             66.139.143.242\nIPv6:             895d:82f7:7c13:e7cb:f35d:c93:aeb2:8eeb\n\ntext:\nMovie author culture represent. Enjoy myself over physical green lead but home.\nShare wind factor far minute produce significant. Sense might fact leader.\n```\n\nCreate an anonymous class with nested types\n\n```python\n\nclass NestedClass:\n    id = -1\n    text = 'test'\n    inner = SimpleClass()\n\ncls = Autodata.create(NestedClass)\nprint(f'id = {cls.id}')\nprint(f'text = {cls.text}')\nprint(f'inner.id = {cls.inner.id}')\nprint(f'inner.text = {cls.inner.text}')\n```\n\nThe code above might output the following\n\n```\nid = 1565737216\ntext = e66ecd5c-c17a-4426-b755-36dfd2082672\ninner.id = 390282329\ninner.text = eef94b5c-aa95-427a-a9e6-d99e2cc1ffb2\n```\n\nCreate a collection of an anonymous class with nested types\n\n```python\nclass NestedClass:\n    id = -1\n    text = 'test'\n    inner = SimpleClass()\n\nclasses = Autodata.create_many(NestedClass)\nfor cls in classes:\n  print(f'id = {cls.id}')\n  print(f'text = {cls.text}')\n  print(f'inner.id = {cls.inner.id}')\n  print(f'inner.text = {cls.inner.text}')\n  print()\n```\n\nThe code above might output the following\n\n```\nid = 1116454042\ntext = ceeecf0c-7375-4f3a-8d4b-6d7a4f2b20fd\ninner.id = 1067027444\ninner.text = 079573ce-1ef4-408d-8984-1dbc7b0d0b80\n\nid = 730390288\ntext = ff3ca474-a69d-4ff6-95b4-fbdb1bea7cdb\ninner.id = 1632771208\ninner.text = 9423e824-dc8f-4145-ba47-7301351a91f8\n\nid = 187364960\ntext = b31ca191-5031-43a2-870a-7bc7c99e4110\ninner.id = 1705149100\ninner.text = e703a117-ba4f-4201-a31b-10ab8e54a673\n```\n\nCreate a Pandas DataFrame using anonymous data generated from a specified type\n\n```python\nclass DataClass:\n    id = -1\n    type = '' \n    value = 0\n\npdf = Autodata.create_pandas_dataframe(DataClass)\nprint(pdf)\n```\n\nThe code above might output the following\n\n```\n          id                                  type       value\n0  778090854  13537c5a-62e7-488b-836e-a4b17f2f3ae9  1049015695\n1  602015506  c043ca8d-e280-466a-8bba-ec1e0539fe28  1016359353\n2  387753717  986b3b1c-abf4-4bc1-95cf-0e979390e4f3   766159839\n```\n\nCreate a Pandas DataFrame using fake data generated from a specified type\n\n```python\nclass DataClass:\n    id = -1\n    first_name = '' \n    last_name = 0\n    phone_number = ''\n\npdf = Autodata.create_pandas_dataframe(DataClass, use_fake_data=True)\nprint(pdf)\n```\n\nThe code above might output the following\n\n```\n  first_name    id last_name          phone_number\n0   Lawrence  7670   Jimenez  001-172-307-0561x471\n1      Bryan  9084    Walker         (697)893-6767\n2       Paul  9824    Thomas    960.555.3577x65487\n```\n\n#\n\nFor tips and tricks on software development, check out [my blog](https://christianhelle.com)\n\nIf you find this useful and feel a bit generous then feel free to [buy me a coffee ☕](https://www.buymeacoffee.com/christianhelle)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristianhelle%2Fautofaker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristianhelle%2Fautofaker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristianhelle%2Fautofaker/lists"}