pyttings 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyttings-0.1.0/LICENSE +21 -0
- pyttings-0.1.0/PKG-INFO +85 -0
- pyttings-0.1.0/README.md +73 -0
- pyttings-0.1.0/pyproject.toml +14 -0
- pyttings-0.1.0/pyttings/__init__.py +5 -0
- pyttings-0.1.0/pyttings/core.py +60 -0
- pyttings-0.1.0/pyttings.egg-info/PKG-INFO +85 -0
- pyttings-0.1.0/pyttings.egg-info/SOURCES.txt +14 -0
- pyttings-0.1.0/pyttings.egg-info/dependency_links.txt +1 -0
- pyttings-0.1.0/pyttings.egg-info/top_level.txt +2 -0
- pyttings-0.1.0/setup.cfg +4 -0
- pyttings-0.1.0/setup.py +24 -0
- pyttings-0.1.0/tests/__init__.py +0 -0
- pyttings-0.1.0/tests/conftest.py +6 -0
- pyttings-0.1.0/tests/settings.py +6 -0
- pyttings-0.1.0/tests/test_core.py +60 -0
pyttings-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Rui Catarino
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pyttings-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: pyttings
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python settings management with namespacing and modular files. Inspired by Django.
|
|
5
|
+
Home-page: https://github.com/ruitcatarino/pyttings
|
|
6
|
+
Author: Rui Catarino
|
|
7
|
+
Requires-Python: >=3.12
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Dynamic: author
|
|
11
|
+
Dynamic: home-page
|
|
12
|
+
|
|
13
|
+
# Pyttings
|
|
14
|
+
Lightweight Python settings management with namespacing and modular files. Inspired by Django.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- **Namespaced Settings**: Use a prefix (e.g., `PYTTING_`) to avoid conflicts.
|
|
19
|
+
- **Custom Prefix**: Change the prefix using `PYTTING_ENV_PREFIX`.
|
|
20
|
+
- **Modular Settings**: Load settings from a module with `PYTTING_SETTINGS_MODULE`.
|
|
21
|
+
- **Environment Variables**: Override settings easily.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install pyttings
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
1. **Define Your Settings Module** (`myapp/settings.py`):
|
|
32
|
+
```python
|
|
33
|
+
DEBUG = True
|
|
34
|
+
DATABASE_URL = "sqlite:///db.sqlite3"
|
|
35
|
+
SECRET_KEY = "my-secret-key"
|
|
36
|
+
```
|
|
37
|
+
2. **Set the Settings Module**:
|
|
38
|
+
```bash
|
|
39
|
+
export PYTTING_SETTINGS_MODULE="myapp.settings"
|
|
40
|
+
```
|
|
41
|
+
3. **Use Pyttings**:
|
|
42
|
+
```python
|
|
43
|
+
from pyttings import settings
|
|
44
|
+
|
|
45
|
+
print(settings.DEBUG) # Output: True
|
|
46
|
+
print(settings.DATABASE_URL) # Output: sqlite:///db.sqlite3
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Configuration
|
|
50
|
+
|
|
51
|
+
### Required: `PYTTING_SETTINGS_MODULE`
|
|
52
|
+
|
|
53
|
+
Specify the settings module using the `PYTTING_SETTINGS_MODULE` environment variable. This is mandatory for Pyttings to know where to load your settings from.
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
export PYTTING_SETTINGS_MODULE="myapp.settings"
|
|
57
|
+
```
|
|
58
|
+
### Optional: `PYTTING_ENV_PREFIX`
|
|
59
|
+
By default, Pyttings uses `PYTTING_` as the prefix for environment variables. For example, to override the `DEBUG` setting, you would set:
|
|
60
|
+
```bash
|
|
61
|
+
export PYTTING_DEBUG="False"
|
|
62
|
+
```
|
|
63
|
+
If you want to use a custom prefix (e.g., `MYAPP_`), set the `PYTTING_ENV_PREFIX` environment variable:
|
|
64
|
+
```bash
|
|
65
|
+
export PYTTING_ENV_PREFIX="MYAPP_"
|
|
66
|
+
export MYAPP_DEBUG="False"
|
|
67
|
+
```
|
|
68
|
+
Now, Pyttings will look for `MYAPP_DEBUG` instead of `PYTTING_DEBUG`.
|
|
69
|
+
|
|
70
|
+
## Contributing
|
|
71
|
+
|
|
72
|
+
Contributions are welcome! If you'd like to contribute to Pyttings, please follow these steps:
|
|
73
|
+
|
|
74
|
+
1. Fork the repository on [GitHub](https://github.com/ruitcatarino/pyttings).
|
|
75
|
+
2. Create a new branch for your feature or bugfix.
|
|
76
|
+
3. Make your changes and ensure tests pass.
|
|
77
|
+
4. Submit a pull request with a clear description of your changes.
|
|
78
|
+
|
|
79
|
+
Please ensure your code follows the project's style and includes appropriate tests.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
Pyttings is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details.
|
pyttings-0.1.0/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Pyttings
|
|
2
|
+
Lightweight Python settings management with namespacing and modular files. Inspired by Django.
|
|
3
|
+
|
|
4
|
+
## Features
|
|
5
|
+
|
|
6
|
+
- **Namespaced Settings**: Use a prefix (e.g., `PYTTING_`) to avoid conflicts.
|
|
7
|
+
- **Custom Prefix**: Change the prefix using `PYTTING_ENV_PREFIX`.
|
|
8
|
+
- **Modular Settings**: Load settings from a module with `PYTTING_SETTINGS_MODULE`.
|
|
9
|
+
- **Environment Variables**: Override settings easily.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install pyttings
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
1. **Define Your Settings Module** (`myapp/settings.py`):
|
|
20
|
+
```python
|
|
21
|
+
DEBUG = True
|
|
22
|
+
DATABASE_URL = "sqlite:///db.sqlite3"
|
|
23
|
+
SECRET_KEY = "my-secret-key"
|
|
24
|
+
```
|
|
25
|
+
2. **Set the Settings Module**:
|
|
26
|
+
```bash
|
|
27
|
+
export PYTTING_SETTINGS_MODULE="myapp.settings"
|
|
28
|
+
```
|
|
29
|
+
3. **Use Pyttings**:
|
|
30
|
+
```python
|
|
31
|
+
from pyttings import settings
|
|
32
|
+
|
|
33
|
+
print(settings.DEBUG) # Output: True
|
|
34
|
+
print(settings.DATABASE_URL) # Output: sqlite:///db.sqlite3
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Configuration
|
|
38
|
+
|
|
39
|
+
### Required: `PYTTING_SETTINGS_MODULE`
|
|
40
|
+
|
|
41
|
+
Specify the settings module using the `PYTTING_SETTINGS_MODULE` environment variable. This is mandatory for Pyttings to know where to load your settings from.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
export PYTTING_SETTINGS_MODULE="myapp.settings"
|
|
45
|
+
```
|
|
46
|
+
### Optional: `PYTTING_ENV_PREFIX`
|
|
47
|
+
By default, Pyttings uses `PYTTING_` as the prefix for environment variables. For example, to override the `DEBUG` setting, you would set:
|
|
48
|
+
```bash
|
|
49
|
+
export PYTTING_DEBUG="False"
|
|
50
|
+
```
|
|
51
|
+
If you want to use a custom prefix (e.g., `MYAPP_`), set the `PYTTING_ENV_PREFIX` environment variable:
|
|
52
|
+
```bash
|
|
53
|
+
export PYTTING_ENV_PREFIX="MYAPP_"
|
|
54
|
+
export MYAPP_DEBUG="False"
|
|
55
|
+
```
|
|
56
|
+
Now, Pyttings will look for `MYAPP_DEBUG` instead of `PYTTING_DEBUG`.
|
|
57
|
+
|
|
58
|
+
## Contributing
|
|
59
|
+
|
|
60
|
+
Contributions are welcome! If you'd like to contribute to Pyttings, please follow these steps:
|
|
61
|
+
|
|
62
|
+
1. Fork the repository on [GitHub](https://github.com/ruitcatarino/pyttings).
|
|
63
|
+
2. Create a new branch for your feature or bugfix.
|
|
64
|
+
3. Make your changes and ensure tests pass.
|
|
65
|
+
4. Submit a pull request with a clear description of your changes.
|
|
66
|
+
|
|
67
|
+
Please ensure your code follows the project's style and includes appropriate tests.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
Pyttings is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pyttings"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Python settings management with namespacing and modular files. Inspired by Django."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
dependencies = []
|
|
8
|
+
|
|
9
|
+
[dependency-groups]
|
|
10
|
+
dev = [
|
|
11
|
+
"mypy>=1.14.1",
|
|
12
|
+
"pytest>=8.3.4",
|
|
13
|
+
"ruff>=0.9.4",
|
|
14
|
+
]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import importlib
|
|
2
|
+
import os
|
|
3
|
+
from functools import cached_property
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Settings:
|
|
8
|
+
def __init__(self) -> None:
|
|
9
|
+
self._settings_module: str = self._get_settings_module()
|
|
10
|
+
self._env_prefix: str = os.getenv("PYTTING_ENV_PREFIX", "PYTTING_")
|
|
11
|
+
self._cache: dict[str, Any] = {}
|
|
12
|
+
|
|
13
|
+
@cached_property
|
|
14
|
+
def defaults(self) -> dict[str, Any]:
|
|
15
|
+
module = importlib.import_module(self._settings_module)
|
|
16
|
+
return {
|
|
17
|
+
key: getattr(module, key)
|
|
18
|
+
for key in dir(module)
|
|
19
|
+
if not key.startswith("__") and not key.endswith("__") and key.isupper()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
def _get_settings_module(self) -> str:
|
|
23
|
+
settings_module: str | None = os.getenv("PYTTING_SETTINGS_MODULE")
|
|
24
|
+
if settings_module is None:
|
|
25
|
+
raise ValueError(
|
|
26
|
+
"PYTTING_SETTINGS_MODULE environment variable is not set. "
|
|
27
|
+
"Please specify a settings module."
|
|
28
|
+
)
|
|
29
|
+
return settings_module
|
|
30
|
+
|
|
31
|
+
def _get_env_var(self, name: str) -> Any | None:
|
|
32
|
+
value = os.getenv(f"{self._env_prefix}{name}")
|
|
33
|
+
if value is None:
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
if name not in self.defaults:
|
|
37
|
+
return value
|
|
38
|
+
|
|
39
|
+
value_type = type(self.defaults[name])
|
|
40
|
+
|
|
41
|
+
if value_type is bool:
|
|
42
|
+
return value.lower() == "true"
|
|
43
|
+
|
|
44
|
+
if value_type is type(None):
|
|
45
|
+
value_type = str
|
|
46
|
+
|
|
47
|
+
return value_type(value)
|
|
48
|
+
|
|
49
|
+
def __getattr__(self, name: str) -> Any:
|
|
50
|
+
if name not in self._cache:
|
|
51
|
+
value: Any | None = self._get_env_var(name)
|
|
52
|
+
if value is None:
|
|
53
|
+
if name in self.defaults:
|
|
54
|
+
value = self.defaults[name]
|
|
55
|
+
else:
|
|
56
|
+
raise AttributeError(
|
|
57
|
+
f"'{self.__class__.__name__}' object has no attribute '{name}'"
|
|
58
|
+
)
|
|
59
|
+
self._cache[name] = value
|
|
60
|
+
return self._cache[name]
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: pyttings
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python settings management with namespacing and modular files. Inspired by Django.
|
|
5
|
+
Home-page: https://github.com/ruitcatarino/pyttings
|
|
6
|
+
Author: Rui Catarino
|
|
7
|
+
Requires-Python: >=3.12
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Dynamic: author
|
|
11
|
+
Dynamic: home-page
|
|
12
|
+
|
|
13
|
+
# Pyttings
|
|
14
|
+
Lightweight Python settings management with namespacing and modular files. Inspired by Django.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- **Namespaced Settings**: Use a prefix (e.g., `PYTTING_`) to avoid conflicts.
|
|
19
|
+
- **Custom Prefix**: Change the prefix using `PYTTING_ENV_PREFIX`.
|
|
20
|
+
- **Modular Settings**: Load settings from a module with `PYTTING_SETTINGS_MODULE`.
|
|
21
|
+
- **Environment Variables**: Override settings easily.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install pyttings
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
1. **Define Your Settings Module** (`myapp/settings.py`):
|
|
32
|
+
```python
|
|
33
|
+
DEBUG = True
|
|
34
|
+
DATABASE_URL = "sqlite:///db.sqlite3"
|
|
35
|
+
SECRET_KEY = "my-secret-key"
|
|
36
|
+
```
|
|
37
|
+
2. **Set the Settings Module**:
|
|
38
|
+
```bash
|
|
39
|
+
export PYTTING_SETTINGS_MODULE="myapp.settings"
|
|
40
|
+
```
|
|
41
|
+
3. **Use Pyttings**:
|
|
42
|
+
```python
|
|
43
|
+
from pyttings import settings
|
|
44
|
+
|
|
45
|
+
print(settings.DEBUG) # Output: True
|
|
46
|
+
print(settings.DATABASE_URL) # Output: sqlite:///db.sqlite3
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Configuration
|
|
50
|
+
|
|
51
|
+
### Required: `PYTTING_SETTINGS_MODULE`
|
|
52
|
+
|
|
53
|
+
Specify the settings module using the `PYTTING_SETTINGS_MODULE` environment variable. This is mandatory for Pyttings to know where to load your settings from.
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
export PYTTING_SETTINGS_MODULE="myapp.settings"
|
|
57
|
+
```
|
|
58
|
+
### Optional: `PYTTING_ENV_PREFIX`
|
|
59
|
+
By default, Pyttings uses `PYTTING_` as the prefix for environment variables. For example, to override the `DEBUG` setting, you would set:
|
|
60
|
+
```bash
|
|
61
|
+
export PYTTING_DEBUG="False"
|
|
62
|
+
```
|
|
63
|
+
If you want to use a custom prefix (e.g., `MYAPP_`), set the `PYTTING_ENV_PREFIX` environment variable:
|
|
64
|
+
```bash
|
|
65
|
+
export PYTTING_ENV_PREFIX="MYAPP_"
|
|
66
|
+
export MYAPP_DEBUG="False"
|
|
67
|
+
```
|
|
68
|
+
Now, Pyttings will look for `MYAPP_DEBUG` instead of `PYTTING_DEBUG`.
|
|
69
|
+
|
|
70
|
+
## Contributing
|
|
71
|
+
|
|
72
|
+
Contributions are welcome! If you'd like to contribute to Pyttings, please follow these steps:
|
|
73
|
+
|
|
74
|
+
1. Fork the repository on [GitHub](https://github.com/ruitcatarino/pyttings).
|
|
75
|
+
2. Create a new branch for your feature or bugfix.
|
|
76
|
+
3. Make your changes and ensure tests pass.
|
|
77
|
+
4. Submit a pull request with a clear description of your changes.
|
|
78
|
+
|
|
79
|
+
Please ensure your code follows the project's style and includes appropriate tests.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
Pyttings is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
pyttings/__init__.py
|
|
6
|
+
pyttings/core.py
|
|
7
|
+
pyttings.egg-info/PKG-INFO
|
|
8
|
+
pyttings.egg-info/SOURCES.txt
|
|
9
|
+
pyttings.egg-info/dependency_links.txt
|
|
10
|
+
pyttings.egg-info/top_level.txt
|
|
11
|
+
tests/__init__.py
|
|
12
|
+
tests/conftest.py
|
|
13
|
+
tests/settings.py
|
|
14
|
+
tests/test_core.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
pyttings-0.1.0/setup.cfg
ADDED
pyttings-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from setuptools import find_packages, setup
|
|
4
|
+
|
|
5
|
+
version = os.getenv("PACKAGE_VERSION", "0.0.1")
|
|
6
|
+
|
|
7
|
+
setup(
|
|
8
|
+
name="pyttings",
|
|
9
|
+
version=version,
|
|
10
|
+
author="Rui Catarino",
|
|
11
|
+
description="Python settings management with namespacing and modular files. Inspired by Django.",
|
|
12
|
+
long_description=open("README.md", "r").read(),
|
|
13
|
+
long_description_content_type="text/markdown",
|
|
14
|
+
url="https://github.com/ruitcatarino/pyttings",
|
|
15
|
+
packages=find_packages(),
|
|
16
|
+
classifiers=[
|
|
17
|
+
"Development Status :: 5 - Production/Stable",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
],
|
|
23
|
+
install_requires=[],
|
|
24
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from pyttings import settings
|
|
6
|
+
from pyttings.core import Settings
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.fixture(autouse=True)
|
|
10
|
+
def clear_settings_cache():
|
|
11
|
+
settings._cache = {}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# Test settings initialization
|
|
15
|
+
def test_settings_initialization():
|
|
16
|
+
assert settings.DEBUG is True
|
|
17
|
+
assert settings.DATABASE_URL == "sqlite:///db.sqlite3"
|
|
18
|
+
assert settings.SECRET_KEY == "my-secret-key"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Test environment variable overrides
|
|
22
|
+
def test_env_var_overrides():
|
|
23
|
+
os.environ["PYTTING_DEBUG"] = "False"
|
|
24
|
+
os.environ["PYTTING_PORT"] = "8080"
|
|
25
|
+
print(os.environ["PYTTING_DEBUG"])
|
|
26
|
+
print(settings._cache)
|
|
27
|
+
assert settings.DEBUG is False # Overridden by environment variable
|
|
28
|
+
assert settings.PORT == 8080 # Overridden and converted to int
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# Test missing settings module
|
|
32
|
+
def test_missing_settings_module():
|
|
33
|
+
if "PYTTING_SETTINGS_MODULE" in os.environ:
|
|
34
|
+
del os.environ["PYTTING_SETTINGS_MODULE"]
|
|
35
|
+
with pytest.raises(
|
|
36
|
+
ValueError, match="PYTTING_SETTINGS_MODULE environment variable is not set"
|
|
37
|
+
):
|
|
38
|
+
Settings()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# Test missing attribute
|
|
42
|
+
def test_missing_attribute():
|
|
43
|
+
with pytest.raises(AttributeError, match="has no attribute 'MISSING_SETTING'"):
|
|
44
|
+
_ = settings.MISSING_SETTING
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# Test environment variable type conversion
|
|
48
|
+
def test_env_var_type_conversion():
|
|
49
|
+
os.environ["PYTTING_ENABLE_FEATURE"] = "True"
|
|
50
|
+
assert settings.ENABLE_FEATURE is True # Converted to bool
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# Test custom prefix
|
|
54
|
+
def test_custom_prefix():
|
|
55
|
+
os.environ["PYTTING_ENV_PREFIX"] = "TEST_"
|
|
56
|
+
os.environ["PYTTING_SETTINGS_MODULE"] = "tests.settings"
|
|
57
|
+
new_settings = Settings()
|
|
58
|
+
assert new_settings._env_prefix == "TEST_"
|
|
59
|
+
assert new_settings.DEBUG is True
|
|
60
|
+
assert new_settings.DATABASE_URL == "sqlite:///db.sqlite3"
|