diff --git a/.github/workflows/build-for-os.yml b/.github/workflows/build-for-os.yml new file mode 100644 index 0000000..e360946 --- /dev/null +++ b/.github/workflows/build-for-os.yml @@ -0,0 +1,34 @@ +name: build-template + +on: + workflow_call: + inputs: + os: + required: true + type: string + +jobs: + build: + runs-on: ${{ inputs.os }} + timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + python_version: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + steps: + - uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python_version }} + - name: Install test requirements + run: pip install -r requirements.txt + - name: Install the package + run: python setup.py develop + - name: Run Tests + run: python -m pytest tests/ -v --cov --cov-report=xml --cov-report=term-missing diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 3388826..afd40cb 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -3,7 +3,9 @@ name: linux on: push: paths: - - .github/workflows/build.yml + - src/**/*.py + - tests/**/*.py + - .github/workflows/build-for-os.yml - .github/workflows/build-linux.yml workflow_dispatch: pull_request: @@ -14,6 +16,6 @@ on: jobs: build: - uses: christianhelle/autofaker/.github/workflows/build.yml@main + uses: ./.github/workflows/build-for-os.yml with: os: ubuntu-latest diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index 2319a14..5fd87fe 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -3,7 +3,9 @@ name: mac on: push: paths: - - .github/workflows/build.yml + - src/**/*.py + - tests/**/*.py + - .github/workflows/build-for-os.yml - .github/workflows/build-macos.yml workflow_dispatch: pull_request: @@ -14,6 +16,6 @@ on: jobs: build: - uses: christianhelle/autofaker/.github/workflows/build.yml@main + uses: ./.github/workflows/build-for-os.yml with: os: macos-latest diff --git a/.github/workflows/build-python-310-linux.yml b/.github/workflows/build-python-310-linux.yml new file mode 100644 index 0000000..ab54f14 --- /dev/null +++ b/.github/workflows/build-python-310-linux.yml @@ -0,0 +1,22 @@ +name: '3.10' + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-310-linux.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: '3.10' + os: ubuntu-latest diff --git a/.github/workflows/build-python-310-macos.yml b/.github/workflows/build-python-310-macos.yml new file mode 100644 index 0000000..ee97748 --- /dev/null +++ b/.github/workflows/build-python-310-macos.yml @@ -0,0 +1,22 @@ +name: '3.10' + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-310-macos.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: '3.10' + os: macos-latest diff --git a/.github/workflows/build-python-310-windows.yml b/.github/workflows/build-python-310-windows.yml new file mode 100644 index 0000000..247e8a2 --- /dev/null +++ b/.github/workflows/build-python-310-windows.yml @@ -0,0 +1,22 @@ +name: '3.10' + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-310-windows.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: '3.10' + os: windows-latest diff --git a/.github/workflows/build-python-311-linux.yml b/.github/workflows/build-python-311-linux.yml new file mode 100644 index 0000000..5b88bd7 --- /dev/null +++ b/.github/workflows/build-python-311-linux.yml @@ -0,0 +1,22 @@ +name: 3.11 + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-311-linux.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: 3.11 + os: ubuntu-latest diff --git a/.github/workflows/build-python-311-macos.yml b/.github/workflows/build-python-311-macos.yml new file mode 100644 index 0000000..a79351d --- /dev/null +++ b/.github/workflows/build-python-311-macos.yml @@ -0,0 +1,22 @@ +name: 3.11 + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-311-macos.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: 3.11 + os: macos-latest diff --git a/.github/workflows/build-python-311-windows.yml b/.github/workflows/build-python-311-windows.yml new file mode 100644 index 0000000..ec33b06 --- /dev/null +++ b/.github/workflows/build-python-311-windows.yml @@ -0,0 +1,22 @@ +name: 3.11 + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-311-windows.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: 3.11 + os: windows-latest diff --git a/.github/workflows/build-python-37-linux.yml b/.github/workflows/build-python-37-linux.yml new file mode 100644 index 0000000..287b46d --- /dev/null +++ b/.github/workflows/build-python-37-linux.yml @@ -0,0 +1,22 @@ +name: 3.7 + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-37-linux.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: 3.7 + os: ubuntu-latest diff --git a/.github/workflows/build-python-37-macos.yml b/.github/workflows/build-python-37-macos.yml new file mode 100644 index 0000000..b2a2671 --- /dev/null +++ b/.github/workflows/build-python-37-macos.yml @@ -0,0 +1,22 @@ +name: 3.7 + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-37-macos.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: 3.7 + os: macos-latest diff --git a/.github/workflows/build-python-37-windows.yml b/.github/workflows/build-python-37-windows.yml new file mode 100644 index 0000000..8555924 --- /dev/null +++ b/.github/workflows/build-python-37-windows.yml @@ -0,0 +1,22 @@ +name: 3.7 + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-37-windows.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: 3.7 + os: windows-latest diff --git a/.github/workflows/build-python-38-linux.yml b/.github/workflows/build-python-38-linux.yml new file mode 100644 index 0000000..4f8786c --- /dev/null +++ b/.github/workflows/build-python-38-linux.yml @@ -0,0 +1,22 @@ +name: 3.8 + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-38-linux.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: 3.8 + os: ubuntu-latest diff --git a/.github/workflows/build-python-38-macos.yml b/.github/workflows/build-python-38-macos.yml new file mode 100644 index 0000000..e9b014f --- /dev/null +++ b/.github/workflows/build-python-38-macos.yml @@ -0,0 +1,22 @@ +name: 3.8 + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-38-macos.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: 3.8 + os: macos-latest diff --git a/.github/workflows/build-python-38-windows.yml b/.github/workflows/build-python-38-windows.yml new file mode 100644 index 0000000..cfa5bf0 --- /dev/null +++ b/.github/workflows/build-python-38-windows.yml @@ -0,0 +1,22 @@ +name: 3.8 + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-38-windows.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: 3.8 + os: windows-latest diff --git a/.github/workflows/build-python-39-linux.yml b/.github/workflows/build-python-39-linux.yml new file mode 100644 index 0000000..4dff017 --- /dev/null +++ b/.github/workflows/build-python-39-linux.yml @@ -0,0 +1,22 @@ +name: 3.9 + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-39-linux.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: 3.9 + os: ubuntu-latest diff --git a/.github/workflows/build-python-39-macos.yml b/.github/workflows/build-python-39-macos.yml new file mode 100644 index 0000000..48aa14d --- /dev/null +++ b/.github/workflows/build-python-39-macos.yml @@ -0,0 +1,22 @@ +name: 3.9 + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-39-macos.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: 3.9 + os: macos-latest diff --git a/.github/workflows/build-python-39-windows.yml b/.github/workflows/build-python-39-windows.yml new file mode 100644 index 0000000..e510620 --- /dev/null +++ b/.github/workflows/build-python-39-windows.yml @@ -0,0 +1,22 @@ +name: 3.9 + +on: + push: + paths: + - src/**/*.py + - tests/**/*.py + - .github/workflows/build.yml + - .github/workflows/build-python-39-windows.yml + workflow_dispatch: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + python_version: 3.9 + os: windows-latest diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 2a86d00..7ddaeee 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -3,7 +3,9 @@ name: windows on: push: paths: - - .github/workflows/build.yml + - src/**/*.py + - tests/**/*.py + - .github/workflows/build-for-os.yml - .github/workflows/build-windows.yml workflow_dispatch: pull_request: @@ -14,6 +16,6 @@ on: jobs: build: - uses: christianhelle/autofaker/.github/workflows/build.yml@main + uses: ./.github/workflows/build-for-os.yml with: os: windows-latest diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07f00cd..dd6cfc3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,25 +6,20 @@ on: os: required: true type: string + python_version: + required: true + type: string jobs: build: runs-on: ${{ inputs.os }} - strategy: - fail-fast: false - matrix: - python_version: - - "3.7" - - "3.8" - - "3.9" - - "3.10" - - "3.11" + timeout-minutes: 10 steps: - uses: actions/checkout@v2 - name: Setup Python uses: actions/setup-python@v2 with: - python-version: ${{ matrix.python_version }} + python-version: ${{ inputs.python_version }} - name: Install test requirements run: pip install -r requirements.txt - name: Install the package diff --git a/.github/workflows/qodana.yml b/.github/workflows/qodana.yml new file mode 100644 index 0000000..39dba38 --- /dev/null +++ b/.github/workflows/qodana.yml @@ -0,0 +1,30 @@ +name: Qodana +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + +jobs: + qodana: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + checks: write + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit + fetch-depth: 0 # a full history is required for pull request analysis + - name: 'Qodana Scan' + uses: JetBrains/qodana-action@v2023.2 + continue-on-error: true + with: + args: --apply-fixes + push-fixes: pull-request + pr-mode: false + env: + QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/README.md b/README.md index e2ce995..9dea7a5 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,16 @@ name: Justin Wise job: Chief Operating Officer ``` +## Supported OS and Python versions + +|Windows|MacOS|Linux| +|---|---|---| +![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-37-windows.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-37-macos.yml/badge.svg)|![](https://github.com/christianhelle/autofaker/actions/workflows/build-python-37-linux.yml/badge.svg)| +![](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)| +![](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)| +![](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)| +![](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)| + ## Supported data types Currently autofaker supports creating anonymous variables for the following data types: diff --git a/qodana.yml b/qodana.yml new file mode 100644 index 0000000..ea37733 --- /dev/null +++ b/qodana.yml @@ -0,0 +1,3 @@ +version: "1.0" +linter: jetbrains/qodana-python:2023.2 +fixesStrategy: apply diff --git a/src/autofaker/generator.py b/src/autofaker/generator.py index 399d6ef..5ce4f97 100644 --- a/src/autofaker/generator.py +++ b/src/autofaker/generator.py @@ -22,7 +22,7 @@ def create( ) if is_date_type(type_name): return TypeDataGenerator.create_datetime( - type_name, field_name, use_fake_data + type_name ) if type_name == "list": return ListGenerator(t) @@ -35,7 +35,7 @@ def create( ) @staticmethod - def create_datetime(type_name, field_name: str = None, use_fake_data: bool = False): + def create_datetime(type_name): if type_name == "datetime": return DatetimeGenerator() if type_name == "date": @@ -69,15 +69,14 @@ def __init__(self, cls, use_fake_data: bool = False): self.cls = cls def generate(self): - args = [] fields = dataclasses.fields(self.cls) - for field in fields: + params = {} + for dataclass_field in fields: generator = TypeDataGenerator.create( - field.type, field.name, use_fake_data=self.use_fake_data + dataclass_field.type, dataclass_field.name, use_fake_data=self.use_fake_data ) - args.append((field.name, field.type, generator.generate())) - name = self.cls.__module__ + "." + self.cls.__qualname__ - instance = dataclasses.make_dataclass(name, args) + params[dataclass_field.name] = generator.generate() + instance = self.cls(**params) return instance diff --git a/tests/test_create_anonymous_data_classes.py b/tests/test_create_anonymous_data_classes.py index f6133e7..5421fae 100644 --- a/tests/test_create_anonymous_data_classes.py +++ b/tests/test_create_anonymous_data_classes.py @@ -1,6 +1,7 @@ import dataclasses import unittest from dataclasses import dataclass +from typing import List from autofaker import Autodata @@ -9,6 +10,8 @@ class DataClass: id: int text: str + list_of_str: List[str] + list_of_int: List[int] class AnonymousDataClassTestCase(unittest.TestCase): @@ -28,6 +31,8 @@ def test_create_many_data_class_returns_dataclass(self): data = Autodata.create(DataClass) self.assertNotEqual(0, data.id) self.assertNotEqual("", data.text) + self.assertNotEqual("", data.list_of_str[0]) + self.assertNotEqual(0, data.list_of_int[0]) @dataclass