-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from jordantshaw/develop
Develop to Main
- Loading branch information
Showing
10 changed files
with
228 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# This workflow will upload a Python Package using Twine when a release is created | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries | ||
|
||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
name: Publish | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.x' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install build | ||
- name: Build package | ||
run: python -m build | ||
- name: Publish package | ||
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | ||
|
||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [ "main", "develop" ] | ||
pull_request: | ||
branches: [ "main", "develop" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install flake8 pytest | ||
pip install -e .[test]; | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with pytest | ||
run: | | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from datetime import timedelta | ||
from typing import Generator, Any | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def config_toml_file(tmp_path_factory): | ||
config = ''' | ||
[app] | ||
description = "description from config.toml" | ||
''' | ||
file_path = tmp_path_factory.mktemp("data") / "config.toml" | ||
with open(file_path, 'w') as file: | ||
file.write(config) | ||
|
||
return file_path | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def config_yaml_file(tmp_path_factory): | ||
config = ''' | ||
app: | ||
description: description from config.yaml | ||
''' | ||
file_path = tmp_path_factory.mktemp("data") / "config.yaml" | ||
with open(file_path, 'w') as file: | ||
file.write(config) | ||
|
||
return file_path | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def config_ini_file(tmp_path_factory): | ||
config = ''' | ||
[APP] | ||
DESCRIPTION = description from config.ini | ||
''' | ||
file_path = tmp_path_factory.mktemp("data") / "config.ini" | ||
with open(file_path, 'w') as file: | ||
file.write(config) | ||
|
||
return file_path | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def config_json_file(tmp_path_factory): | ||
config = ''' | ||
{ | ||
"app": { | ||
"description": "description from config.json" | ||
} | ||
} | ||
''' | ||
file_path = tmp_path_factory.mktemp("data") / "config.json" | ||
with open(file_path, 'w') as file: | ||
file.write(config) | ||
|
||
return file_path | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from pydantic_config.loaders import toml_file_loader, ini_file_loader, yaml_file_loader, json_file_loader | ||
|
||
|
||
def test_toml_load(config_toml_file): | ||
data = toml_file_loader(config_toml_file) | ||
assert data == {'app': {'description': 'description from config.toml'}} | ||
|
||
|
||
def test_ini_load(config_ini_file): | ||
data = ini_file_loader(config_ini_file) | ||
assert data == {'DEFAULT': {}, 'APP': {'description': 'description from config.ini'}} | ||
|
||
|
||
def test_yaml_load(config_yaml_file): | ||
data = yaml_file_loader(config_yaml_file) | ||
assert data == {'app': {'description': 'description from config.yaml'}} | ||
|
||
|
||
def test_json_load(config_json_file): | ||
data = json_file_loader(config_json_file) | ||
assert data == {'app': {'description': 'description from config.json'}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import pytest | ||
from pydantic import BaseModel | ||
|
||
from pydantic_config import SettingsModel | ||
|
||
|
||
def test_config_file(config_toml_file): | ||
class App(BaseModel): | ||
name: str = 'AppName' | ||
description: str = None | ||
|
||
class Settings(SettingsModel): | ||
app: App | ||
|
||
class Config: | ||
config_file = [config_toml_file] | ||
|
||
settings = Settings() | ||
assert settings.dict() == {'app': {'name': 'AppName', 'description': 'description from config.toml'}} | ||
|
||
|
||
def test_invalid_config_file(): | ||
file = 'invalid/file/path/file.toml' | ||
|
||
class Settings(SettingsModel): | ||
foo: str = 'bar' | ||
|
||
class Config: | ||
config_file = [file] | ||
|
||
with pytest.raises(OSError) as exc: | ||
Settings() | ||
|
||
|
||
def test_multiple_config_files(config_toml_file, config_yaml_file): | ||
class App(BaseModel): | ||
name: str = 'AppName' | ||
description: str = None | ||
|
||
class Settings(SettingsModel): | ||
app: App | ||
|
||
class Config: | ||
config_file = [config_toml_file, config_yaml_file] | ||
|
||
settings = Settings() | ||
assert settings.dict() == {'app': {'name': 'AppName', 'description': 'description from config.yaml'}} | ||
|