aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.coveragerc4
-rw-r--r--.github/workflows/python-package-ci.yml71
-rw-r--r--.github/workflows/python-security.yml11
-rw-r--r--.gitignore7
-rw-r--r--.pre-commit-config.yaml42
-rw-r--r--.travis.yml13
-rw-r--r--CHANGELOG.md221
-rw-r--r--CONTRIBUTING.md34
-rw-r--r--README.md323
-rw-r--r--config_file/__init__.py10
-rw-r--r--config_file/abstract_parser.py118
-rw-r--r--config_file/base_parser.py139
-rw-r--r--config_file/config_file.py269
-rw-r--r--config_file/config_file_path.py116
-rw-r--r--config_file/exceptions.py9
-rw-r--r--config_file/ini_parser.py13
-rw-r--r--config_file/ini_parser_compat.py42
-rw-r--r--config_file/json_parser.py15
-rw-r--r--config_file/nested_lookup.py402
-rw-r--r--config_file/parse_value.py218
-rw-r--r--config_file/parsers/__init__.py0
-rw-r--r--config_file/parsers/base_parser.py79
-rw-r--r--config_file/parsers/ini_parser.py123
-rw-r--r--config_file/parsers/json_parser.py129
-rw-r--r--config_file/parsers/parse_value.py87
-rw-r--r--config_file/toml_parser.py18
-rw-r--r--config_file/utils.py43
-rw-r--r--config_file/yaml_parser.py21
-rw-r--r--docs/Makefile20
-rw-r--r--docs/make.bat35
-rw-r--r--docs/source/api-reference.rst2
-rw-r--r--docs/source/conf.py58
-rw-r--r--docs/source/getting-started.rst141
-rw-r--r--docs/source/index.rst22
-rw-r--r--docs/source/license.rst4
-rw-r--r--poetry.lock593
-rw-r--r--pyproject.toml44
-rw-r--r--tests/conftest.py68
-rw-r--r--tests/templates/ini/all_strings.ini7
-rw-r--r--tests/templates/ini/default.ini7
-rw-r--r--tests/templates/ini/invalid.ini2
-rw-r--r--tests/templates/json/all_strings.json9
-rw-r--r--tests/templates/json/default.json13
-rw-r--r--tests/templates/json/invalid.json1
-rw-r--r--tests/templates/toml/all_strings.toml6
-rw-r--r--tests/templates/toml/default.toml7
-rw-r--r--tests/templates/toml/invalid.toml1
-rw-r--r--tests/templates/yaml/all_strings.yaml6
-rw-r--r--tests/templates/yaml/default.yaml7
-rw-r--r--tests/templates/yaml/invalid.yaml6
-rw-r--r--tests/test_abstract_parser.py68
-rw-r--r--tests/test_base_parser.py57
-rw-r--r--tests/test_config_file.py504
-rw-r--r--tests/test_config_file_path.py112
-rw-r--r--tests/test_ini_parser.py106
-rw-r--r--tests/test_json_parser.py198
-rw-r--r--tests/test_nested_lookup.py1064
-rw-r--r--tests/test_parse_value.py191
-rw-r--r--tests/test_toml_parser.py24
-rw-r--r--tests/test_utils.py78
-rw-r--r--tests/test_yaml_parser.py24
-rw-r--r--tox.ini14
62 files changed, 4173 insertions, 1903 deletions
diff --git a/.coveragerc b/.coveragerc
index e272605..11aaf17 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -1,2 +1,4 @@
[run]
-source=config_file \ No newline at end of file
+source=config_file/
+branch = True
+omit = config_file/parsers/abstract_parser.py \ No newline at end of file
diff --git a/.github/workflows/python-package-ci.yml b/.github/workflows/python-package-ci.yml
index d9f8836..0b82937 100644
--- a/.github/workflows/python-package-ci.yml
+++ b/.github/workflows/python-package-ci.yml
@@ -1,52 +1,39 @@
-name: Python package CI
+name: python package CI
-on:
- push:
- branches: [ master, dev ]
- pull_request:
- branches: [ master, dev ]
+on: [push, pull_request]
jobs:
build:
-
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
steps:
- - uses: actions/checkout@v2
-
- - name: Set up Python ${{ matrix.python-version }}
- uses: actions/setup-python@v2
- with:
- python-version: ${{ matrix.python-version }}
-
- - name: Install dependencies
- run: |
- python -m pip install --upgrade pip
- pip install poetry codecov requests
- poetry install -v -E toml -E yaml
-
- - name: Run linters
- run: |
- poetry run pre-commit run --all
-
- - name: Run tests
- run: |
- poetry run task test
-
- - name: Upload coverage to Codecov
- uses: codecov/codecov-action@v1
- with:
- token: ${{ secrets.CODECOV_TOKEN }}
- file: ./coverage.xml
- flags: unittests
- env_vars: OS,PYTHON
- name: codecov-umbrella
- fail_ci_if_error: true
-
- - name: Build Package
- run: |
- poetry build
-
+ - uses: actions/checkout@v2
+
+ - name: Set up Python ${{ matrix.python-version }}
+ uses: actions/setup-python@v2
+ with:
+ python-version: ${{ matrix.python-version }}
+
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install poetry
+ poetry install -E toml -E yaml
+
+ - name: Run tests
+ run: poetry run task test_ci
+
+ - name: Upload coverage to Codecov
+ uses: codecov/codecov-action@v1
+ with:
+ token: ${{ secrets.CODECOV_TOKEN }}
+ file: ./coverage.xml
+ flags: unittests
+ name: codecov-umbrella
+ fail_ci_if_error: true
+
+ - name: Build Package
+ run: poetry build
diff --git a/.github/workflows/python-security.yml b/.github/workflows/python-security.yml
new file mode 100644
index 0000000..5597151
--- /dev/null
+++ b/.github/workflows/python-security.yml
@@ -0,0 +1,11 @@
+name: Python Security Checks
+on: [push, pull_request]
+
+jobs:
+ security_checks:
+ runs-on: ubuntu-latest
+ name: Execute the pycharm-security action
+ steps:
+ - uses: actions/checkout@v1
+ - name: Run PyCharm Security
+ uses: tonybaloney/pycharm-security@master \ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 31ebf72..9b8c400 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,12 +8,13 @@
# Python
*.egg-info/
__pycache__/
-venv/
+.venv/
-# Pytest
+# Testing / Linting
.pytest_cache/
.coverage
.benchmarks/
+.mypy_cache/
# Package Publishing
dist/
@@ -22,4 +23,4 @@ dist/
.python-version
# Sphinx
-build/ \ No newline at end of file
+build/
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 9975877..879742c 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,30 +1,42 @@
repos:
+ - repo: git@github.com:humitos/mirrors-autoflake.git
+ rev: v1.3
+ hooks:
+ - id: autoflake
+ args:
+ [
+ "--in-place",
+ "--remove-all-unused-imports",
+ "--remove-unused-variable",
+ ]
-- repo: git@github.com:humitos/mirrors-autoflake.git
- rev: v1.3
- hooks:
- - id: autoflake
- args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']
-
-- repo: https://github.com/asottile/seed-isort-config
+ - repo: https://github.com/asottile/seed-isort-config
rev: v1.9.4
hooks:
- - id: seed-isort-config
+ - id: seed-isort-config
-- repo: https://github.com/pre-commit/mirrors-isort
+ - repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
hooks:
- - id: isort
+ - id: isort
additional_dependencies:
- toml
-- repo: https://github.com/ambv/black
+ - repo: https://github.com/ambv/black
rev: stable
hooks:
- - id: black
- language_version: python3.8
+ - id: black
+
+ - repo: https://github.com/pre-commit/pre-commit-hooks
+ rev: v2.5.0
+ hooks:
+ - id: trailing-whitespace
+ - id: check-docstring-first
+ - id: check-case-conflict
+ - id: check-yaml
+ - id: check-toml
-- repo: https://github.com/pre-commit/pre-commit-hooks
+ - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
hooks:
- - id: flake8
+ - id: flake8
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 507c5e1..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-language: python
-os: linux
-
-python:
- - "3.6"
- - "3.7"
- - "3.8"
-
-install:
- - curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
- - source $HOME/.poetry/env
- - pip install --upgrade pip tox-travis codecov
-script: tox \ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e0a3ce8..0b288a1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,167 +5,174 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## Unreleased
+
+### Added
+
+- `ConfigFile` can now accept yaml and toml files as optional extra file types.
+ As long as the extras (`yaml` and `toml`) are installed, those file types can also
+ be used.
+
+### Changed
+
+- `path` on the `ConfigFile` is now a property that can only be retrieved. `contents` is now private
+ but you can use `.stringify()` instead to get the contents. `parser` is now also private.
+
+- `restore_original` in `ConfigFile` now raises a `FileNotFoundError` instead of an `OSError` if the original
+ file path does not exist.
+
+### Fixed
+
+- `default` in `ConfigFile`'s `get` method can now be `None`. Previously, it was defaulted to the
+ value `None` so there was no way of distinguishing between the default value and a user inputted
+ value of `None`.
+
## 0.10.0 - 2020-05-10
-Changed
+### Changed
- - `toml` and `pyyaml` are now optional extra dependencies. This allows you to
- not have to install them if you aren't using them.
-
- - `retrieve_all` in `JsonParser`'s `get` method is now called `get_all` for
- consistency. It isn't publicly available yet. The thought is to write a custom
- ini parser first that supports multiple of the same keys and subsections.
- This way you can have the `get_all`, `set_all`, `delete_all`, etc. methods
- for all file type parsers. I would have to weight if that added complexity
- of not using the built-in configparser and roll our own for some added
- features is worth it or see if there are ways to work around it with
- configparser that are ideal.
+- `toml` and `pyyaml` are now optional extra dependencies. This allows you to
+ not have to install them if you aren't using them.
-Fixed
+- `retrieve_all` in `JsonParser`'s `get` method is now called `get_all` for
+ consistency. It isn't publicly available yet. The thought is to write a custom
+ ini parser first that supports multiple of the same keys and subsections.
+ This way you can have the `get_all`, `set_all`, `delete_all`, etc. methods
+ for all file type parsers. I would have to weight if that added complexity
+ of not using the built-in configparser and roll our own for some added
+ features is worth it or see if there are ways to work around it with
+ configparser that are ideal.
- - You can now specify a default and still coerce your return type. Previously,
- if you specified a default, there was no logic in that branch to coerce your
- return type as well.
+### Fixed
+- You can now specify a default and still coerce your return type. Previously,
+ if you specified a default, there was no logic in that branch to coerce your
+ return type as well.
## 0.9.0 - 2020-02-09
-Added
+### Added
+
+- `default` optional parameter to the `get()` method of `ConfigFile`.
+ The allows a default value to be fallen back to if the given key is missing.
- - `default` optional parameter to the `get()` method of `ConfigFile`.
- The allows a default value to be fallen back to if the given key is missing.
-
- - `return_type` optional parameter to `get()` method of `ConfigFile`. This
- allows you to coerce the return type to one of your choosing by feeding it
- the return value.
+- `return_type` optional parameter to `get()` method of `ConfigFile`. This
+ allows you to coerce the return type to one of your choosing by feeding it
+ the return value.
-Changed
+### Changed
- - Automatic type parsing is now off by default. This is because of the addition of
- the `return_type` optional parameter. After using the package more, I think
- the explicitness of specifying the type you're after or that you'd like to
- automatically parse the type to one of the basic types is more maintainable.
- However, I think the option to automatically parse or parse a whole section of
- values is still a useful one.
-
- - The `parse_type` parameter to `ConfigFile`'s `get()` method is now called
- `parse_types`.
+- Automatic type parsing is now off by default. This is because of the addition of
+ the `return_type` optional parameter. After using the package more, I think
+ the explicitness of specifying the type you're after or that you'd like to
+ automatically parse the type to one of the basic types is more maintainable.
+ However, I think the option to automatically parse or parse a whole section of
+ values is still a useful one.
+
+- The `parse_type` parameter to `ConfigFile`'s `get()` method is now called
+ `parse_types`.
## 0.8.0 - 2020-02-02
-Added
+### Added
+
+- More type hints to `ConfigFile` and `IniParser`.
+- `nested_lookup` dependency to help with modifying deeply nested structures
+ (JSON + YAML)
+- `JsonParser` so you can now specify `.json` files to be parsed.
- - More type hints to `ConfigFile` and `IniParser`.
- - `nested_lookup` dependency to help with modifying deeply nested structures
- (JSON + YAML)
- - `JsonParser` so you can now specify `.json` files to be parsed.
-
-Changed
+### Changed
- - The original content of the passed in file is now called `content`
- instead of `contents`. This is for consistency since the parsed version is
- called `parsed_content`.
+- The original content of the passed in file is now called `content`
+ instead of `contents`. This is for consistency since the parsed version is
+ called `parsed_content`.
## 0.7.0 - 2020-01-27
-Fixed
+### Fixed
- - Support for using custom parsers with `ConfigFile` with the `parser` optional
- argument. This was technically supported before, but it was not tested and found
- to not actually use the passed in parser once tested.
+- Support for using custom parsers with `ConfigFile` with the `parser` optional
+ argument. This was technically supported before, but it was not tested and found
+ to not actually use the passed in parser once tested.
-Changed
+### Changed
- - The `reset()` method on `ConfigFile` is now called `restore_original()`.
- The behavior is the same. This was done to better describe what exactly that method
- is doing. Since the file is not written back out with every `set()` or `delete()`
- and calling `save()` explicitly is required, `reset()` may have been confused with
- resetting the changes you've made rather than deleting and restoring the original
- configuration file.
+- The `reset()` method on `ConfigFile` is now called `restore_original()`.
+ The behavior is the same. This was done to better describe what exactly that method
+ is doing. Since the file is not written back out with every `set()` or `delete()`
+ and calling `save()` explicitly is required, `reset()` may have been confused with
+ resetting the changes you've made rather than deleting and restoring the original
+ configuration file.
## 0.6.0 - 2020-01-24
-Changed
+### Changed
- - Bumped down python version requirement to 3.6 and now test 3.6, 3.7, and 3.8 on CI.
+- Bumped down python version requirement to 3.6 and now test 3.6, 3.7, and 3.8 on CI.
## 0.5.0 - 2020-01-19
-Added
+### Added
- - Support for retrieving entire sections as a `dict` with `get()`.
+- Support for retrieving entire sections as a `dict` with `get()`.
## 0.4.0 - 2020-01-19
-Added
+### Added
- - `reset()` and `save()` methods to `ConfigFile`. This allows you to reset your
- configuration file to an "original state," given the original config file path.
- However, say you have a `config/config.json` file. Then it will automatically try
- to look for `config/config.original.json` if no file path is specified. The `save()`
- method should be called after your changes to the config file. It will write them
- back out.
-
- - Raise test coverage to 93%.
+- `reset()` and `save()` methods to `ConfigFile`. This allows you to reset your
+ configuration file to an "original state," given the original config file path.
+ However, say you have a `config/config.json` file. Then it will automatically try
+ to look for `config/config.original.json` if no file path is specified. The `save()`
+ method should be called after your changes to the config file. It will write them
+ back out.
+
+- Raise test coverage to 93%.
## 0.3.3 - 2020-01-18
-Changed
+### Changed
- - `_split_on_dot` is no longer in base parser (now in a utils file). Also, the default
+- `_split_on_dot` is no longer in base parser (now in a utils file). Also, the default
behavior is now to split on every dot and split on only the last dot if specified
-
-Fixed
- - `ConfigFile` was trying to use `_split_on_dot`, but it no longer inherited from base parser.
-
- - `TypeError` when setting the key/value pairs since configparser requires the option
- to be a string. The parser now just converts the value to a string if it is not one
- and then adds the key/value pair. It would still be parsed correctly when retrieving
- it.
+### Fixed
+
+- `ConfigFile` was trying to use `_split_on_dot`, but it no longer inherited from base parser.
+
+- `TypeError` when setting the key/value pairs since configparser requires the option
+ to be a string. The parser now just converts the value to a string if it is not one
+ and then adds the key/value pair. It would still be parsed correctly when retrieving
+ it.
## 0.3.1 - 2020-01-17
-Fixed
+### Fixed
- - `isinstance` call for `BaseParser` to be correctly used.
+- `isinstance` call for `BaseParser` to be correctly used.
## 0.3.0 - 2020-01-17
-Added
+### Added
+
+- Abstract base parser as a contract for concrete file format parser implementations.
- - Abstract base parser as a contract for concrete file format parser implementations.
-
- - Exposed `ConfigFile`, `BaseParser`, and `ParsingError` to the Public API. The base
- parser is exposed to allow future custom extensions of the config file and what it
+- Exposed `ConfigFile`, `BaseParser`, and `ParsingError` to the Public API. The base
+ parser is exposed to allow future custom extensions of the config file and what it
can parse by its users.
-
- - `has_section` and `has_key` is now changed to a single `has` method which determines
- whether you're checking a section or key by the presence of a dot.
-
- - `IniParser` to support the ini format. It uses configparser internally, but it is
- only exposed through the `ConfigFile` object.
+
+- `has_section` and `has_key` is now changed to a single `has` method which determines
+ whether you're checking a section or key by the presence of a dot.
+
+- `IniParser` to support the ini format. It uses configparser internally, but it is
+ only exposed through the `ConfigFile` object.
## 0.2.0 - 2020-01-04
-Added
+### Added
- - Parsing of strings to their native values
+- Parsing of strings to their native values
## 0.1.0 - 2020-01-04
-Added
-
- - Created the config_file package with only the version inside it
-
- - toml and pyyaml to dependencies
-
- - Pre-commit pipeline with autoflake, isort, black, and flake8
-
- - MIT license
-
- - Contributing guidelines
-
- - bump2version for easily upgrading versions of config file
-
- - pytest to dev dependencies for testing later on
+ - Initial Release \ No newline at end of file
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 8669fd0..b4e1b26 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -14,33 +14,34 @@ Here are some guidelines to keep in mind when submitting a pull request:
paragraphs of explanation as you need. This is the place to clarify any subtleties
you have in your implemeƒntation, document other approaches you tried that didn't
end up working, any limitations on your implementation, etc. The most important
- part here is to describe *why* you made the change you did, not simply *what* the
+ part here is to describe _why_ you made the change you did, not simply _what_ the
change you made is.
- Changelog: Please ensure to update the changelog by adding a new bullet under
- an ``Added``, ``Changed``, ``Deprecated``, ``Removed``, ``Fixed``, or ``Security`` section
- headers under the ``Unreleased`` version. If any of those sections are not present,
+ an `Added`, `Changed`, `Deprecated`, `Removed`, `Fixed`, or `Security` section
+ headers under the `Unreleased` version. If any of those sections are not present,
feel free to add the one you need. See
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/) if you need guidance
on what makes a good entry since this project follows those principles. If you're
not comfortable with your English, we'd be happy to write it for you.
-- Ensure the tests pass: ``poetry run task test`` to run all tests.
+- Ensure the tests pass: `poetry run task test` to run all tests.
- New features should be accompanied with tests for them:
+
- Unit tests are written using [pytest](https://docs.pytest.org/en/latest/).
- Pre-commit pipeline: We use a pre-commit pipeline to ensure standard code format.
- - Unused imports are automatically removed using `autoflake <https://github.com/myint/autoflake>`_
-
- - The remaining imports are sorted using `isort <https://github.com/timothycrosley/isort>`_.
-
- - All code is automatically formatted with `black <https://github.com/psf/black>`_
-
- - Lastly, everything is checked by `flake8 <https://gitlab.com/pycqa/flake8>`_.
-
- Make sure to install pre-commit before making commits.
+ - Unused imports are automatically removed using `autoflake <https://github.com/myint/autoflake>`\_
+
+ - The remaining imports are sorted using `isort <https://github.com/timothycrosley/isort>`\_.
+
+ - All code is automatically formatted with `black <https://github.com/psf/black>`\_
+
+ - Lastly, everything is checked by `flake8 <https://gitlab.com/pycqa/flake8>`\_.
+
+ Make sure to install pre-commit before making commits.
Note: if any of the items had to do any reformatting, sorting, etc., the commit will
fail. You'll have to re-add the items it fixed and try again.
@@ -48,11 +49,10 @@ Here are some guidelines to keep in mind when submitting a pull request:
```bash
pre-commit install
```
-
+
- CI Pipeline: There is a CI pipeline that is run by Travis CI on commits to master and
on pull requests.
-
+
- All it does is ensure that all the tests pass.
-To get started, make sure you have poetry installed and run ``poetry install`` and
-``poetry shell`` to enter the virtual environment. \ No newline at end of file
+To get started, make sure you have poetry installed and run `poetry install -E yaml -E toml` and `poetry shell` to enter the virtual environment.
diff --git a/README.md b/README.md
index b7ef6ef..8cbf360 100644
--- a/README.md
+++ b/README.md
@@ -6,105 +6,322 @@
[![Version](https://img.shields.io/pypi/v/config-file)](https://pypi.org/project/config-file/)
[![Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/)
[![Documentation Status](https://readthedocs.org/projects/config-file/badge/?version=latest)](https://config-file.readthedocs.io/en/latest/?badge=latest)
-[![Build Status](https://travis-ci.com/eugenetriguba/config-file.svg?branch=master)](https://travis-ci.com/eugenetriguba/config-file)
+[![Build Status](https://github.com/eugenetriguba/config-file/workflows/python%20package%20CI/badge.svg?branch=master)](https://github.com/eugenetriguba/config-file/actions/)
[![Codecov](https://codecov.io/gh/eugenetriguba/config-file/graph/badge.svg)](https://codecov.io/gh/eugenetriguba/config-file)
## About Config File
-The Config File project is designed to allow you to easily manipulate your
-configuration files with the same simple API whether they are in INI,
-JSON, YAML, or TOML. For the time being, it only supports INI and JSON.
+The Config File project is designed to allow you to easily manipulate your
+configuration files with the same simple API whether they are in INI, JSON,
+YAML, or TOML.
## Installation
-Config File is available to download through PyPI using pip.
+Config File is available to download through PyPI.
```bash
$ pip install config-file
```
+### Installing Extras
+
If you want to manipulate YAML and TOML, you'll want to download the extras as well.
```bash
$ pip install config-file[yaml, toml]
```
+You can also use [Poetry](https://python-poetry.org).
+
+```bash
+$ poetry install config-file -E yaml -E toml
+```
+
## Usage
-Say you have an INI file you want to manipulate. It must have an .ini
-extension in order for the package to recognize it.
+For this overview, let's say you have the following `ini` file
+you want to manipulate.
+
+Do note, however, that the `ini` format is the oddest format that
+`ConfigFile` supports in that it has no formal specification and is
+not type aware. When retrieving items from the file, it will return
+them as strings by default. Others are more type aware and do not
+require as much type coercion.
```ini
[section]
-first_key = 5
-second_key = blah
-third_key = true
+num_key = 5
+str_key = blah
+bool_key = true
+list_key = [1, 2]
+
+[second_section]
+dict_key = { "another_num": 5 }
```
-Then we can manipulate it as follows.
+It must have a `.ini` extension in order
+for the package to recognize it and use the correct parser for it.
+
+### Setting up ConfigFile
+
+To use the package, we import in the `ConfigFile` object. This object
+is the only thing considered to be part of the public API.
+
+We can set it up by giving it a string or `pathlib.Path` as the argument.
+Any home tildes `~` in the string or `Path` are recognized and converted
+to the full path for us.
```python
from config_file import ConfigFile
-ORIGINAL_CONFIG_PATH = Path("~/some-project/some-other-config-file.ini")
-CONFIG_PATH = Path("~/some-project/config.ini")
+config = ConfigFile("~/some-project/config.ini")
+```
+
+### Using `get()`
-# Our path can be a string or a Path object.
-# The "~" will be automatically expanded to the full path for us.
-config = ConfigFile(CONFIG_PATH)
+A recurring pattern you'll see here is that all methods that
+need to specify something inside your configuration file will
+do so using a dot syntax.
-# All the types will be retrieved as strings unless specified otherwise.
-print(config.get("section.first_key"))
->>> "5"
-print(config.get("section.first_key", return_type=int))
+#### Retrieving keys and sections
+
+So to retrieve our `num_key`, we'd specify the heading and the
+key separated by a dot. All values will then be retrieved as
+strings.
+
+```python
+config.get('section.num_key')
+>>> '5'
+```
+
+While we can retrieves keys, we can also retrieve the entire
+section, which will be returned back to us as a dictionary.
+
+```python
+config.get('section')
+>>> {'num_key': '5', 'str_key': 'blah', 'bool_key': 'true', 'list_key': '[1, 2]'}
+```
+
+Furthermore, you can also index into the `ConfigFile` object
+to retrieve keys if that is preferred.
+
+```python
+config['section']['num_key']
+>>> '5'
+```
+
+#### Coercing the return types
+
+However, some of these keys are obviously not strings natively.
+If we are retrieving a particular value of a key, we may want to
+coerce it right away without doing clunky type conversions after
+each time we retrieve a value. To do this, we can utilize the
+`return_type` keyword argument.
+
+```python
+config.get('section.num_key', return_type=int)
>>> 5
+```
-# This holds true when we retrieve entire sections as well. However, we can
-# also recursively parse the entire section is desired.
-print(config.get("section"))
->>> {'first_key': '5', 'second_key': 'blah', 'third_key': 'true'}
-print(config.get("section", parse_types=True))
->>> {'first_key': 5, 'second_key': 'blah', 'third_key': True}
+Sometimes we don't have structures quite that simple though. What
+if we wanted all the values in `section` coerced? For that, we can
+utilize a `parse_types` keyword argument.
-# Sometimes we want to retrieve a key but don't know whether or not
-# it will be set. In that case, we can set a default.
-print(config.get("section.unknown", default=False))
->>> False
+```python
+config.get('section', parse_types=True)
+>>> {'num_key': 5, 'str_key': 'blah', 'bool_key': True, 'list_key': [1, 2]}
+```
-# Setting, deleting, and checking if a key exists is just as easy.
-print(config.set("section.first_key", 10))
->>> True
+It also works for regular keys.
-print(config.delete("section.third_key"))
->>> True
+```python
+config.get('section.num_key', parse_types=True)
+>>> 5
+```
-print(config.has("section.third_key"))
->>> False
+#### Handling non-existent keys
-# We can also convert the entire configuration file to a string.
-print(config.stringify())
->>> '[section]\nfirst_key = 5\nsecond_key = blah\nthird_key = true\n\n'
+Sometimes we want to retrieve a key but are unsure of if it will exist.
+There are two ways we could handle that.
-# Lastly, we need to make sure we save our changes. Nothing is written
-# out until we do so.
-print(config.save())
->>> True
+The first is the one we're used to seeing: catch the error.
+
+```python
+try:
+ important_value = config.get('section.i_do_not_exist')
+except KeyError:
+ important_value = 42
+```
+
+However, the `get` method comes with a `default` keyword argument that we
+can utilze for this purpose.
+
+```python
+config.get('section.i_do_not_exist', default=42)
+>>> 42
+```
+
+This can be handy if you have a default for a particular configuration value.
+
+### Using `set()`
+
+We can use `set()` to set a existing key's value.
+
+```python
+config.set('section.num_key', 6)
+```
+
+The method does not return anything, since there is nothing
+useful to return. If something goes wrong where it is unable to set
+the value, an exception will be raised instead. This is the case
+for most methods on `ConfigFile`, such as `delete()` or `save()`,
+where there would be no useful return value to utilize.
+
+With `set()`, we can also create and set keys that don't exist yet.
+
+```python
+config.set('new_section.new_key', 'New key value!')
+```
+
+Would then result in the following section being added to our original file:
+
+```ini
+[new_section]
+new_key = New key value!
+```
-# If we have, say, a default config file and a user config file, we can easily
-# restore default one. We can specify the file path to it.
-print(config.restore_original(original_file_path=ORIGINAL_CONFIG_PATH))
+The exact behavior of how these new keys or sections are added are a bit
+dependent on the file format we're using, since every format is a little
+different in it's structure and in what it supports. Mostly though, `ini`
+is just the odd one.
+
+If we try the following in `ini`, which does not support subsections or
+nested keys, we simply get a single section.
+
+```python
+config.set("section.sub_section.sub_sub_section.key", 5)
+```
+
+```ini
+[section.sub_section.sub_sub_section]
+key = 5
+```
+
+Lastly, we can set values using an array notation as well. The underlying
+content is all manipulated as a dictionary for every file type. If we wanted
+to create a new section, we'd simply set it to be an empty dictionary.
+
+```python
+config['new_section'] = {}
+```
+
+Which would result to be an empty section:
+
+```ini
+[new_section]
+```
+
+### Using `delete()`
+
+`delete()` allows us to delete entire sections or specific keys.
+
+```python
+config.delete('section')
+```
+
+Would result in the entire section being removed from our configuration file.
+However, we can also just delete a single key.
+
+```python
+config.delete('section.num_key')
+```
+
+We can also use the array notation here as well.
+
+```python
+del config['section']['num_key']
+```
+
+### Using `has()`
+
+`has()` allows us to check whether a given key exists in our file. There
+are two ways to use `has()`.
+
+The first is using the dot syntax.
+
+```python
+config.has('section.str_key')
>>> True
+config.has('does_not_exist')
+>>> False
+```
+
+This will check if our specific key or section exists. However, we can
+also check in general if a given key or sections exists anywhere in our
+file with the `wild` keyword argument.
-# Otherwise, a config.original.ini file will automatically be looked for in the
-# current directory (because our configuration file we passed in was
-# named config.ini).
-print(config.restore_original())
+```python
+config.has('str_key', wild=True)
>>> True
```
-## Documentation
+### Using `save()`
+
+For any changes we make to our configuration file, they are not written out
+to the filesystem until we call `save()`. This is to avoid unnecessary write
+calls after each operation until we actually need to save.
+
+```python
+config.delete('section.list_key')
+config.save()
+```
+
+### Using `stringify()`
+
+`stringify()` shows us our configuration file, with any changes we've made,
+as a string. `stringify()` will always show us our latest changes since it
+is stringify-ing our internal representation of the configuration file, not
+just the file we've read in.
+
+```python
+config.stringify()
+>>> '[section]\nnum_key = 5\nstr_key = blah\nbool_key = true\nlist_key = [1, 2]\n\n[second_section]\ndict_key = { "another_num": 5 }\n\n'
+```
+
+
+### Using `restore_original()`
+
+If we have a initial configuration file state, we could keep a copy of that
+initial file and restore back to it whenever needed using `restore_original()`.
+
+By default, if we created our `ConfigFile` object with the path of `~/some-project/config.ini`,
+`restore_original()` will look for our original file at `~/some-project/config.original.ini`.
+
+```python
+config.restore_original()
+```
+
+However, if we have a specific path elsewhere that this original configuration file is or it
+is named differently than what the default expects, we can utilize the `original_path`
+keyword argument.
+
+```python
+config.restore_original(original_path="~/some-project/original-configs/config.ini")
+```
+
+
+## Format Versions Supported
+
+| Format | Specification version supported |
+| ------------- | ------------- |
+| INI | No official specification. |
+| JSON | [RFC 7159](https://tools.ietf.org/html/rfc7159.html) |
+| YAML | [v1.2](https://yaml.org/spec/1.2/spec.html) |
+| TOML | [v1.0.0-rc.1](https://github.com/toml-lang/toml/releases/tag/v1.0.0-rc.1) |
-Full documentation and API reference is available at https://config-file.readthedocs.io
+For `ini` and `json`, Python's standard library modules are used.
+Regarding `ini`, there is no formal specification so the syntax that configparser
+supports is what is supported here.
## License
diff --git a/config_file/__init__.py b/config_file/__init__.py
index 3bae28a..853da2a 100644
--- a/config_file/__init__.py
+++ b/config_file/__init__.py
@@ -1,10 +1,6 @@
-from config_file.config_file import ConfigFile
-from config_file.parsers.base_parser import BaseParser, ParsingError
+from .config_file import ConfigFile
+from .exceptions import ParsingError
__version__ = "0.10.0"
-__all__ = [
- "ConfigFile",
- "ParsingError",
- "BaseParser",
-]
+__all__ = ["ConfigFile", "ParsingError"]
diff --git a/config_file/abstract_parser.py b/config_file/abstract_parser.py
new file mode 100644
index 0000000..689fece
--- /dev/null
+++ b/config_file/abstract_parser.py
@@ -0,0 +1,118 @@
+from abc import ABC, abstractmethod
+from typing import Any
+
+
+class AbstractParser(ABC):
+ """Abstract Parser is the API contract for all parsers.
+
+ Every parser in ConfigFile implements this parser, and
+ any user created parsers must implement this parser in
+ order for this package to be able to use it.
+
+ Every key is specified in a dot (.) syntax
+ e.g. retrieving.some.deeply.nested.value
+
+ If there is no dot in the key, it is assumed we are
+ performing an action on a top level key, which could
+ be an entire section.
+
+ Args:
+ file_contents: The stringified version of a file.
+
+ Attributes:
+ file_contents: The stringified version of a file.
+ """
+
+ @abstractmethod
+ def __init__(self, file_contents: str) -> None:
+ self.file_contents = file_contents
+
+ @abstractmethod
+ def reset_internal_contents(self, file_contents: str) -> None:
+ """Reset the state of this parser to a new file.
+
+ When restoring to the original file in ConfigFile,
+ we need a way to reset the internal contents to this
+ new file.
+
+ While this may be as simple as setting the file_contents
+ attribute value to the passed in file_contents argument,
+ it likely would not be. This is because the initial
+ passed in file contents would likely be parsed into some
+ special form for the parser to work with more easily.
+
+ Args:
+ file_contents: The file contents of the new file.
+ """
+ raise NotImplementedError
+
+ @abstractmethod
+ def get(self, key: str) -> Any:
+ """Retrieve the value of a key from the working file.
+
+ Args:
+ key: The key to retrieve.
+
+ Returns:
+ Whatever value the given key happens to contain.
+
+ Raises:
+ KeyError: If the key to retrieve does not exist.
+ """
+ raise NotImplementedError
+
+ @abstractmethod
+ def set(self, key: str, value: Any) -> None:
+ """Set the value of a key in the working file.
+
+ If the key does not exist, it should be created.
+
+ Args:
+ key: The key to set.
+ value: The value to set the key to.
+ """
+ raise NotImplementedError
+
+ @abstractmethod
+ def delete(self, key: str) -> None:
+ """Deletes a key from the working file.
+
+ Args:
+ key: The key we would like to remove.
+
+ Raises:
+ KeyError: If the key to remove does not exist.
+ """
+ raise NotImplementedError
+
+ @abstractmethod
+ def stringify(self) -> str:
+ """Stringify the working file.
+
+ Since the ConfigFile does not write out to disk
+ after every operation, this method is what is
+ used as the output for saving the file again.
+ This parser should never write out to the disk.
+
+ Returns:
+ The file we are working with as a string.
+ """
+ raise NotImplementedError
+
+ @abstractmethod
+ def has(self, key: str, wild: bool = False) -> bool:
+ """Check whether the given key is in the parsed working file.
+
+ This should not behave like a wild card, as in check
+ if the key exists anywhere in the working file. Instead,
+ if a key is given without a dot, it should be assumed we
+ are checking the top level.
+
+ Args:
+ key: The key to search for.
+ wild: Optionally search for any occurrence of key in the file.
+
+ Returns:
+ True if the working file has the key. False otherwise.
+ """
+ raise NotImplementedError
diff --git a/config_file/base_parser.py b/config_file/base_parser.py
new file mode 100644
index 0000000..a440dcb
--- /dev/null
+++ b/config_file/base_parser.py
@@ -0,0 +1,139 @@
+from types import ModuleType
+from typing import Any, Type
+
+from config_file.abstract_parser import AbstractParser
+from config_file.exceptions import ParsingError
+from config_file.nested_lookup import get_occurrence_of_key
+from config_file.utils import split_on_dot
+
+
+class BaseParser(AbstractParser):
+ def __init__(
+ self, file_contents: str, module: ModuleType, decode_error: Type[Exception]
+ ):
+ """The BaseParser implements the AbstractParser for us by giving it any module.
+
+ As long as the module has a `loads` and `dumps` method, the BaseParser can use
+ it. Every file is then represented and worked with as a dictionary.
+
+ Args:
+ file_contents: The contents of the file to parse.
+
+ module: The module to use to parse the files.
+ Must have a `loads` and `dumps` method.
+
+ decode_error: The error the module raises when the
+ file cannot be decoded.
+
+ Raises:
+ ParsingError: If the decode_error is raised.
+ """
+ super().__init__(file_contents)
+ self.__module = module
+ self.__decode_error = decode_error
+ self.parsed_content = self.parse_file_contents(module, decode_error)
+
+ def parse_file_contents(self, module: ModuleType, decode_error: Exception) -> dict:
+ """Parse the file contents by running the `loads` method on the module.
+
+ Args:
+ module: The module to use to parse the file.
+ decode_error: The error that is raised from the module if the file
+ cannot be decoded.
+
+ Raises:
+ ParsingError: If the decode_error is raised while running `loads`.
+
+ Returns:
+ The parsed file as a dictionary.
+ """
+ try:
+ return module.loads(self.file_contents)
+ except decode_error as error:
+ raise ParsingError(error)
+
+ def reset_internal_contents(self, file_contents: str) -> None:
+ """Reset the file contents and parsed contents of the parser.
+
+ Args:
+ file_contents: The new file contents.
+
+ Raises:
+ ParsingError: If we're unable to parse the new file contents.
+ """
+ self.file_contents = file_contents
+ self.parsed_content = self.parse_file_contents(
+ self.__module, self.__decode_error
+ )
+
+ def get(self, search_key: str) -> Any:
+ key_causing_error = None
+
+ try:
+ if "." not in search_key:
+ key_causing_error = search_key
+ return self.parsed_content[search_key]
+ else:
+ split_keys = split_on_dot(search_key)
+
+ content_reference = self.parsed_content
+ for key in split_keys:
+ key_causing_error = key
+ content_reference = content_reference[key]
+
+ except (KeyError, TypeError):
+ raise KeyError(
+ f"cannot `get` {search_key} because "
+ f"{key_causing_error} is not subscriptable."
+ )
+
+ return content_reference
+
+ def set(self, key: str, value: Any) -> None:
+ if "." not in key:
+ self.parsed_content[key] = value
+ return
+
+ keys = split_on_dot(key)
+ content_reference = self.parsed_content
+ for index, key in enumerate(keys):
+ if index == len(keys) - 1:
+ content_reference[key] = value
+ return
+
+ try:
+ content_reference = content_reference[key]
+ except KeyError:
+ content_reference[key] = {}
+ content_reference = content_reference[key]
+
+ def delete(self, key: str) -> None:
+ try:
+ if "." not in key:
+ del self.parsed_content[key]
+ else:
+ indexes = split_on_dot(key)
+ indexes_length = len(indexes)
+
+ content_reference = self.parsed_content
+ for index, key in enumerate(indexes):
+ if index == indexes_length - 1:
+ del content_reference[key]
+ break
+
+ content_reference = content_reference[key]
+ except (KeyError, TypeError):
+ raise KeyError(f"The specified key '{key}' to delete was not found.")
+
+ def stringify(self) -> str:
+ return self.__module.dumps(self.parsed_content)
+
+ def has(self, search_key: str, wild: bool = False) -> bool:
+ if wild:
+ return get_occurrence_of_key(self.parsed_content, key=search_key) > 0
+
+ try:
+ self.get(search_key)
+ return True
+ except (KeyError, ParsingError):
+ return False
diff --git a/config_file/config_file.py b/config_file/config_file.py
index 91202da..2a8d9ae 100644
--- a/config_file/config_file.py
+++ b/config_file/config_file.py
@@ -1,155 +1,188 @@
-import inspect
-from pathlib import Path, PurePath
+from pathlib import Path
from shutil import copyfile
+from typing import Any, Union
-from config_file.parsers.base_parser import BaseParser, ParsingError
-from config_file.parsers.ini_parser import IniParser
-from config_file.parsers.json_parser import JsonParser
-from config_file.utils import split_on_dot
+from config_file.config_file_path import ConfigFilePath
+from config_file.parse_value import parse_value
+from config_file.utils import Default
class ConfigFile:
- def __init__(self, file_path, parser: BaseParser = None):
+ def __init__(self, file_path: Union[str, Path]) -> None:
"""
- Saves the config file path and expands it if needed, reads in
+ Stores the config file path and expands it if needed, reads in
the file contents, and determines what parser should be used for
the given file.
- :param file_path: The path to your configuration file.
- :param parser: A custom parser you'd like used for your config file.
- It must be a concrete implementation of BaseParser.
+ Args:
+ file_path: The path to your configuration file.
- :raises ValueError: If the specified file path does not have an extension
- that is supported or it is a directory.
+ Raises:
+ ValueError: If the specified file path does not have an extension
+ that is supported or it is a directory.
+ FileNotFoundError: If the specified file path does not exist.
"""
- self.path = self.__create_config_path(file_path)
- self.contents = self.__read_config_file()
- self.parser = self.__determine_parser(file_path, parser)
-
- @staticmethod
- def __create_config_path(file_path, original: bool = False) -> str:
- if isinstance(file_path, PurePath):
- file_path = str(file_path)
-
- if len(file_path) > 1 and file_path[0] == "~":
- return str(Path(file_path).expanduser())
-
- if original:
- file_parts = split_on_dot(file_path, only_last_dot=True)
- file_parts.insert(-1, "original")
- file_path = ".".join(file_parts)
-
- if Path(file_path).is_dir():
- raise ValueError(f"The specified config file ({file_path}) is a directory.")
-
- return file_path
-
- def __determine_parser(self, file_path, parser: BaseParser):
- if isinstance(file_path, PurePath):
- file_path = str(file_path)
-
- if parser is not None and not inspect.isabstract(parser):
- return parser(self.contents)
-
- file_type = split_on_dot(file_path, only_last_dot=True)[-1]
- if file_type == "ini":
- return IniParser(self.contents)
- elif file_type == "json":
- return JsonParser(self.contents)
- else:
- raise ValueError(
- f"File path contains an unsupported or "
- f"unrecognized file type: {file_path}"
- )
-
- def __read_config_file(self):
- with open(self.path, "r") as file:
- return file.read()
-
- def get(self, key: str, parse_types: bool = False, return_type=None, default=None):
+ self.__path = ConfigFilePath(file_path).validate()
+ self.__parser = self.__path.parser
+
+ @property
+ def path(self) -> Path:
+ return Path(self.__path)
+
+ @property
+ def original_path(self) -> Path:
+ return Path(self.__path.original_path)
+
+ def __getitem__(self, key: str):
+ return self.__parser.parsed_content[key]
+
+ def __setitem__(self, key: str, value: Any):
+ self.__parser.parsed_content[key] = value
+
+ def __delitem__(self, key: str):
+ del self.__parser.parsed_content[key]
+
+ def get(
+ self,
+ key: str,
+ parse_types: bool = False,
+ return_type: Any = None,
+ default: Any = Default(None),
+ ) -> Any:
"""
Retrieve the value of a key.
- :param key: The key to retrieve.
- :param parse_types: Automatically parse ints, floats, booleans, dicts, and
- lists. This recursively parses all types in whatever you're
- retrieving, not just a single type. e.g. If you are
- retrieving a section, all values in that section with be
- parsed.
- :param return_type: The type to coerce the return value to.
- :param default: The default value to return if the value of the key is empty.
+ Args:
+ key: The key to retrieve.
+ parse_types: Automatically parse ints, floats, booleans, dicts, and
+ lists. This recursively parses all types in whatever you're
+ retrieving, not just a single type.
+
+ e.g. If you are retrieving a section, all values in that
+ section will be parsed.
- :return: The value of the key.
+ return_type: The type to coerce the return value to.
+ default: The default value to return if the value of the key is empty.
+
+ Returns:
+ The value of the key.
+
+ Raises:
+ KeyError: If a key is attempted to be retrieved that does not exist.
+ ValueError: If the value is not able to be coerced into return_type.
"""
- if default is None:
- key_value = self.parser.get(key, parse_types=parse_types)
- else:
- try:
- key_value = self.parser.get(key, parse_types=parse_types)
- except ParsingError:
- return default
+ try:
+ key_value = self.__parser.get(key)
+ except KeyError as error:
+ if isinstance(default, Default) and default.value is None:
+ raise KeyError(error)
+ else:
+ key_value = default
+
+ if parse_types:
+ key_value = parse_value(key_value)
return return_type(key_value) if return_type else key_value
- def set(self, key: str, value):
- """Sets the value of a key."""
- return self.parser.set(key, value)
+ def set(self, key: str, value: Any) -> None:
+ """Sets the value of a key.
- def delete(self, section_key: str):
- """Deletes a key/value pair or entire sections."""
- return self.parser.delete(section_key)
+ If the given key does not exist, it will be automatically
+ created for you. That includes if there are multiple keys
+ in a row that do not exist.
+ e.g. set('exists.does_not.does_not.also_does_not', 5)
- def stringify(self) -> str:
- """Convert the parsed internal representation of the file back into a string."""
- return self.parser.stringify()
+ The behavior of how this is done, however, depends on the
+ file used. For example, with INI, subsections are not supported.
+ So it would create a key in the section `exists` called `does_not`
+ and set it to the value {'does_not': {'also_does_not': 5}}.
- def has(self, section_key: str) -> bool:
+ Args:
+ key: The section, sub-section, or key to delete.
+ value: The value to set the key to.
"""
- Check if a section, sub-section, or key exists in the file
- using a section.key format.
+ self.__parser.set(key, value)
+
+ def delete(self, key: str) -> None:
+ """Deletes a section or key.
+
+ Args:
+ key: The section, sub-section, or key to delete.
- Some formats, like JSON, do not have sections and therefore,
- it would only be checking if the key exists.
+ Raises:
+ KeyError: If a key is attempted to be deleted that
+ does not exist.
"""
- return self.parser.has(section_key)
+ self.__parser.delete(key)
- def restore_original(self, original_file_path=None):
+ def stringify(self) -> str:
+ """Retrieves file contents as a string.
+
+ Returns:
+ The internal representation of the file
+ that has been read in converted to a string.
+ """
+ return self.__parser.stringify()
+
+ def has(self, key: str, wild: bool = False) -> bool:
"""
- Restores the original the config file by deleting it and copying the original
- back in its place. The internal contents of this config file object are then set
- to the newly reset config file.
+ Check if a section, sub-section, or key exists.
+
+ Some formats, like JSON, do not have sections and
+ therefore, it would only be checking if a particular
+ key exists.
+
+ Args:
+ key: The section, sub-section, or key to find.
+ wild: Whether or not to search everywhere.
- :param original_file_path: The path to the original config file to reset it to.
- If this is not provided and, say, your configuration file is config.json, the
- method would look for a config.original.json in the same folder by default.
+ Without `wild`, a single word `key` without a `.`
+ will look at the outer most hierarchy of the file for it.
- :return: True if the reset succeeded
- :raises OSError: If the original configuration file is not present or if an
- error occurred when trying to copy the file.
+ With `wild`, that single word `key` will be searched
+ for throughout the entire file.
+
+ Returns:
+ True if the key exists. False otherwise.
"""
- if original_file_path is None:
- original_file_path = self.__create_config_path(
- str(self.path), original=True
- )
+ return self.__parser.has(key, wild=wild)
+
+ def restore_original(self, original_path: Union[str, Path, None] = None) -> None:
+ """Restores the original the configuration file.
+
+ The current one is deleted and the original is copied back
+ in its place. The internal contents are then reset to the
+ new file.
- if not Path(original_file_path).exists():
- raise OSError(
- f"The {original_file_path} file to restore to does not exist."
- )
+ Args:
+ original_path: The original file to reset to.
- Path(self.path).expanduser().unlink()
- copyfile(original_file_path, self.path)
- self.contents = self.__read_config_file()
- self.parser.parsed_content = self.parser.parse(self.contents)
+ Defaults to the original_path property if it is not
+ provided.
- return True
+ Raises:
+ FileNotFoundError: If the original configuration file (whether
+ calculated or passed in) does not exist or if the current
+ configuration path is passed in as the original_path (since
+ it is deleted before the original file is copied over).
- def save(self):
+ OSError: If the current configuration path is not writable.
"""
- Save the configuration changes by writing the file out to the specified path
- :return: True if the save succeeded.
+ original_path = ConfigFilePath(
+ original_path if original_path else self.original_path
+ ).validate()
+
+ self.__path.unlink()
+ copyfile(original_path, self.__path)
+ self.__parser.reset_internal_contents(self.__path.contents)
+
+ def save(self) -> None:
"""
- with open(self.path, "w") as config_file:
- config_file.write(self.parser.stringify())
+ Save your configuration changes.
- return True
+ This writes the file back out, including any changes
+ you've made, to the specified path given from this
+ object's constructor.
+ """
+ with open(str(self.__path), "w") as config_file:
+ config_file.write(self.stringify())
diff --git a/config_file/config_file_path.py b/config_file/config_file_path.py
new file mode 100644
index 0000000..11a5daa
--- /dev/null
+++ b/config_file/config_file_path.py
@@ -0,0 +1,116 @@
+import os
+from pathlib import Path as _Path_
+from pathlib import _posix_flavour, _windows_flavour
+from typing import Type
+
+from config_file.abstract_parser import AbstractParser
+from config_file.ini_parser import IniParser
+from config_file.json_parser import JsonParser
+from config_file.toml_parser import TomlParser
+from config_file.yaml_parser import YamlParser
+
+from .utils import split_on_dot
+
+
+class ConfigFilePath(_Path_):
+ """A ConfigFilePath object, which subclasses Path.
+
+ It provides us easy ways to grab the original config file
+ path, file extension, validate the path, or determine the parser
+ that should be use for the given file type.
+
+ See https://codereview.stackexchange.com/questions/162426/subclassing-pathlib-path
+ for more details on subclassing the pathlib.Path object.
+ """
+
+ _flavour = _windows_flavour if os.name == "nt" else _posix_flavour
+
+ @property
+ def original_path(self) -> "ConfigFilePath":
+ """Computes the original configuration file path.
+
+ e.g. ConfigFilePath("./config.ini").original_path -> "./config.original.ini"
+
+ Returns:
+ The path to the original configuration file, which
+ may or may not exist.
+ """
+ file_parts = split_on_dot(self, only_last_dot=True)
+ file_parts.insert(-1, "original")
+ return ConfigFilePath(".".join(file_parts))
+
+ @property
+ def extension(self) -> str:
+ """Retrieves the extension of the file
+ path we passed in, without the '.'.
+
+ e.g. ConfigFilePath("./pyproject.toml").extension -> "toml"
+
+ Returns:
+ The extension of the current file path.
+ """
+ _, extension = os.path.splitext(str(self))
+ return extension[1:]
+
+ @property
+ def parser(self) -> Type[AbstractParser]:
+ """Determine what parser should be used for this file.
+
+ Raises:
+ ValueError: If the extension of the file is not recognized.
+
+ Returns:
+ The instantiated parser that should be used for this file.
+ """
+ if self.extension == "":
+ raise ValueError(
+ "Tried to determine a parser to use, but the file at "
+ f"{self} does not have an extension."
+ )
+
+ if self.extension == "ini":
+ return IniParser(self.contents)
+ elif self.extension == "json":
+ return JsonParser(self.contents)
+ elif self.extension == "yaml" or self.extension == "yml":
+ return YamlParser(self.contents)
+ elif self.extension == "toml":
+ return TomlParser(self.contents)
+ else:
+ raise ValueError(
+ f"File path at `{self}` contains an unrecognized file type."
+ )
+
+ @property
+ def contents(self) -> str:
+ """Retrieve the contents of the file.
+
+ Returns:
+ The contents of the file at this path.
+ """
+ with open(self, "r") as file:
+ return file.read()
+
+ def validate(self) -> "ConfigFilePath":
+ """Validates that the current path exists, is a directory,
+ and expands any home tidles.
+
+ Raises:
+ FileNotFoundError: If the path does not exist.
+ ValueError: If the path leads to a directory.
+
+ Returns:
+ A ConfigFilePath object with any ~'s expanded.
+ """
+ if len(self.parts) >= 1 and self.parts[0] == "~":
+ self = ConfigFilePath(self.expanduser())
+
+ if not self.exists():
+ raise FileNotFoundError(
+ f"The specified config file ({self}) does not exist."
+ )
+
+ if self.is_dir():
+ raise ValueError(f"The specified config file ({self}) is a directory")
+
+ return self
diff --git a/config_file/exceptions.py b/config_file/exceptions.py
new file mode 100644
index 0000000..f68b7e8
--- /dev/null
+++ b/config_file/exceptions.py
@@ -0,0 +1,9 @@
+class ParsingError(ValueError):
+ """
+ Unable to parse the configuration file.
+
+ Since every module that parses the different
+ files has it's own decode error, this standardizes
+ it for the package to only raise a ParsingError
+ if a error occurs in those instances.
+ """
diff --git a/config_file/ini_parser.py b/config_file/ini_parser.py
new file mode 100644
index 0000000..72974f1
--- /dev/null
+++ b/config_file/ini_parser.py
@@ -0,0 +1,13 @@
+import configparser
+
+from .base_parser import BaseParser
+from .ini_parser_compat import IniParserCompatibility
+
+
+class IniParser(BaseParser):
+ def __init__(self, file_contents: str):
+ super().__init__(
+ file_contents=file_contents,
+ module=IniParserCompatibility,
+ decode_error=configparser.Error,
+ )
diff --git a/config_file/ini_parser_compat.py b/config_file/ini_parser_compat.py
new file mode 100644
index 0000000..9dfea2e
--- /dev/null
+++ b/config_file/ini_parser_compat.py
@@ -0,0 +1,42 @@
+import configparser
+from io import StringIO
+
+
+class IniParserCompatibility:
+ """
+ Provides compatibility with the json, yaml,
+ and toml API so we can use the BaseParser
+ easily, while still being able to leverage
+ the built-in configparser to parse the file.
+
+ It is used as the `module` parameter
+ for BaseParser, which requires us to have a
+ `dumps` and `loads` method.
+ """
+
+ @staticmethod
+ def loads(file_contents: str) -> dict:
+ parser = configparser.ConfigParser()
+ parser.read_string(file_contents)
+
+ return IniParserCompatibility.__create_configparser_dict(parser)
+
+ @staticmethod
+ def dumps(file_contents: dict) -> str:
+ parser = configparser.ConfigParser()
+ buffer = StringIO()
+
+ parser.read_dict(file_contents)
+ parser.write(buffer)
+
+ return buffer.getvalue()
+
+ @staticmethod
+ def __create_configparser_dict(parser: configparser.ConfigParser) -> dict:
+ result = {}
+ items = dict(parser.items())
+
+ for section in parser.sections():
+ result.update({str(section): dict(items[section])})
+
+ return result
diff --git a/config_file/json_parser.py b/config_file/json_parser.py
new file mode 100644
index 0000000..5314cd7
--- /dev/null
+++ b/config_file/json_parser.py
@@ -0,0 +1,15 @@
+import json
+
+from .base_parser import BaseParser
+
+
+class JsonParser(BaseParser):
+ def __init__(self, file_contents: str):
+ super().__init__(
+ file_contents=file_contents,
+ module=json,
+ decode_error=json.decoder.JSONDecodeError,
+ )
+
+ def stringify(self) -> str:
+ return json.dumps(self.parsed_content, indent=4)
diff --git a/config_file/nested_lookup.py b/config_file/nested_lookup.py
new file mode 100644
index 0000000..7b13d83
--- /dev/null
+++ b/config_file/nested_lookup.py
@@ -0,0 +1,402 @@
+import copy
+import warnings
+from collections import defaultdict
+
+__all__ = [
+ "get_all_keys",
+ "get_occurrences_and_values",
+ "get_occurrence_of_value",
+ "get_occurrence_of_key",
+ "nested_update",
+ "nested_delete",
+ "nested_alter",
+ "nested_lookup",
+]
+
+
+values_list = []
+
+
+def nested_lookup(key, document, wild=False, with_keys=False):
+ """Lookup a key in a nested document, return a list of values"""
+ if with_keys:
+ d = defaultdict(list)
+ for k, v in _nested_lookup(key, document, wild=wild, with_keys=with_keys):
+ d[k].append(v)
+ return d
+ return list(_nested_lookup(key, document, wild=wild, with_keys=with_keys))
+
+
+def _is_case_insensitive_substring(a, b):
+ """return True if `a` is a case insensitive substring of `b`, else False"""
+ return str(a).lower() in str(b).lower()
+
+
+def _nested_lookup(key, document, wild=False, with_keys=False):
+ """Lookup a key in a nested document, yield a value"""
+ if isinstance(document, list):
+ for d in document:
+ for result in _nested_lookup(key, d, wild=wild, with_keys=with_keys):
+ yield result
+
+ if isinstance(document, dict):
+ for k, v in document.items():
+ if key == k or (wild and _is_case_insensitive_substring(key, k)):
+ if with_keys:
+ yield k, v
+ else:
+ yield v
+ if isinstance(v, dict):
+ for result in _nested_lookup(key, v, wild=wild, with_keys=with_keys):
+ yield result
+ elif isinstance(v, list):
+ for d in v:
+ for result in _nested_lookup(
+ key, d, wild=wild, with_keys=with_keys
+ ):
+ yield result
+
+
+def get_all_keys(dictionary):
+ """
+ Method to get all keys from a nested dictionary as a List
+ Args:
+ dictionary: Nested dictionary
+ Returns:
+ List of keys in the dictionary
+ """
+ result_list = []
+
+ def recrusion(document):
+ if isinstance(document, list):
+ for list_items in document:
+ recrusion(document=list_items)
+ elif isinstance(document, dict):
+ for key, value in document.items():
+ result_list.append(key)
+ recrusion(document=value)
+ return
+
+ recrusion(document=dictionary)
+ return result_list
+
+
+def get_occurrence_of_key(dictionary, key):
+ """
+ Method to get occurrence of a key in a nested dictionary
+
+ Args:
+ dictionary: Nested dictionary
+ key: Key to search for the occurrences
+ Return:
+ Number of occurrence (Integer)
+ """
+ return _get_occurrence(dictionary=dictionary, item="key", keyword=key)
+
+
+def get_occurrences_and_values(items, value):
+ """
+ Method to get occurrence of a value in a nested list of dictionary
+
+ Args:
+ items: list of dictionary: Nested dictionary
+ value: Value to search for the occurrences
+
+ Return:
+ Dict where the key is the value arg and his value is a new
+ dict with occurrences and values
+ """
+ occurrences = {}
+ occurrence = 0
+ value_list = []
+
+ for item in items:
+ occurrence_result, values = _get_occurrence_with_values(
+ dictionary=item, item="value", keyword=value
+ )
+ occurrence = occurrence + occurrence_result
+ if occurrence_result:
+ value_list.extend(values)
+
+ occurrences[value] = {"occurrences": occurrence, "values": value_list}
+
+ return occurrences
+
+
+def _get_occurrence_with_values(dictionary, item, keyword):
+ occurrence = [0]
+
+ result_recursion = _recursion(dictionary, item, keyword, occurrence, True)
+
+ global values_list
+ values_list = []
+
+ return occurrence[0], result_recursion
+
+
+def get_occurrence_of_value(dictionary, value):
+ """
+ Method to get occurrence of a value in a nested dictionary
+
+ Args:
+ dictionary: Nested dictionary
+ value: Value to search for the occurrences
+ Return:
+ Number of occurrence (Integer)
+ """
+ return _get_occurrence(dictionary=dictionary, item="value", keyword=value)
+
+
+def _recursion(dictionary, item, keyword, occurrence, with_values=False):
+
+ global values_list
+
+ if item == "key":
+ if dictionary.get(keyword) is not None:
+ occurrence[0] += 1
+ elif keyword in list(dictionary.values()):
+ occurrence[0] += list(dictionary.values()).count(keyword)
+ if with_values:
+ values_list.append(dictionary)
+ for key, value in dictionary.items():
+ if isinstance(value, dict):
+ _recursion(value, item, keyword, occurrence, with_values)
+ elif isinstance(value, list):
+ for list_items in value:
+ if hasattr(list_items, "items"):
+ _recursion(list_items, item, keyword, occurrence, with_values)
+ elif list_items == keyword:
+ occurrence[0] += 1 if item == "value" else 0
+
+ if values_list:
+ return values_list
+
+
+def _get_occurrence(dictionary, item, keyword):
+ """
+ Method to get occurrence of a key or value in a nested dictionary
+
+ Args:
+ dictionary: Nested dictionary
+ item: Mostly (key or value)
+ keyword: key word to find occurrence
+ Return:
+ Number of occurrence of the given keyword in the dict
+ """
+ occurrence = [0]
+ _recursion(dictionary, item, keyword, occurrence)
+
+ global values_list
+ values_list = []
+
+ return occurrence[0]
+
+
+def nested_delete(document, key, in_place=False):
+ if not in_place:
+ document = copy.deepcopy(document)
+ return _nested_delete(document=document, key=key)
+
+
+def _nested_delete(document, key):
+ """
+ Method to delete a key->value pair from a nested document
+ Args:
+ document: Might be List of Dicts (or) Dict of Lists (or)
+ Dict of List of Dicts etc...
+ key: Key to delete
+ Return:
+ Returns a document that includes everything but the given key
+ """
+ if isinstance(document, list):
+ for list_items in document:
+ _nested_delete(document=list_items, key=key)
+ elif isinstance(document, dict):
+ if document.get(key):
+ del document[key]
+ for dict_key, dict_value in document.items():
+ _nested_delete(document=dict_value, key=key)
+ return document
+
+
+def nested_update(document, key, value, in_place=False, treat_as_element=True):
+ """
+ Method to update a key->value pair in a nested document
+
+ Args:
+ document: Might be List of Dicts (or) Dict of Lists (or)
+ Dict of List of Dicts etc...
+
+ key: Key to update the value
+
+ value: Value to set
+
+ in_place (bool):
+ True: modify the dict in place;
+ False: create a deep copy of the dict and modify it
+ Defaults to False
+
+ treat_as_element (bool):
+ True: if a list is provided as "value", the function trys
+ to match the list elements to the occurences of the key.
+ If the key occures more often than the provided list has
+ elements, the first element gets recycled.
+ False: the provided list is treated as one scalar value and
+ will be set as value to every key that matches.
+ Defaults to True (because of backwards portability of the package).
+
+ Return:
+ Returns a document that has updated key, value pair.
+ """
+
+ # check if a list or scalar value is provided and create a list
+ # from the scalar value
+ # check the length of the list and provide it to _nested_update
+ if not treat_as_element and not isinstance(value, list):
+ raise Exception("The value must be a list when treat_as_element is False.")
+ elif treat_as_element:
+ value = [value]
+
+ if not in_place:
+ document = copy.deepcopy(document)
+ return _nested_update(document=document, key=key, value=value)
+
+
+def _nested_update(document, key, value):
+ """
+ Method to update a key->value pair in a nested document.
+ If the number of passed values is less than the number of key matches
+ when scanning for updates, use last value as default.
+ Args:
+ document: Might be List of Dicts (or) Dict of Lists (or)
+ Dict of List of Dicts etc...
+ key (str): Key to update the value
+ value (list): value(s) which should be used for replacement purpouse
+ Return:
+ Returns a document that has updated key, value pair.
+ """
+ if isinstance(document, list):
+ for list_items in document:
+ _nested_update(document=list_items, key=key, value=value)
+ elif isinstance(document, dict):
+ for dict_key, dict_value in document.items():
+ if dict_key == key:
+ document[key] = value[0]
+ if len(value) > 1:
+ value.pop(0)
+ _nested_update(document=dict_value, key=key, value=value)
+ return document
+
+
+def nested_alter(
+ document,
+ key,
+ callback_function=None,
+ function_parameters=None,
+ conversion_function=None,
+ wild_alter=False,
+ in_place=False,
+):
+ """
+ Method to alter all values of the occurences of the key "key".
+ The provided callback_function is used to alter the scalar values
+ Args:
+ document: Might be List of Dicts (or) Dict of Lists (or)
+ Dict of List of Dicts etc...
+ key: Key to update the value
+ callback_function :A callback function which alters a scalar value
+ HINT: You should be aware that not every element might be of
+ the same type, please check this in your function!
+ function_parameters (list):
+ If the callback_function has additional input arguments except
+ the scalar value, please specify those in this list.
+ conversion_function: A conversion function like str() which should be
+ applied to every found value before it is passed to the
+ "callback_function"
+ wild_alter: Find matching elements via wild-match by the given keys
+ and alter those.
+ HINT: Keep in mind that the wild-match might return unexpected types!
+ in_place (bool):
+ True: modify the dict in place;
+ False: create a deep copy of the dict and modify it
+ Defaults to False
+ Return:
+ Returns a document that has updated key, value pair.
+ """
+ # check if a list or scalar value is provided and create a list from
+ # the scalar value
+ # check the length of the list and provide it to _nested_update
+ if isinstance(key, list):
+ key_len = len(key)
+ else:
+ key = [key]
+ key_len = len(key)
+
+ if not in_place:
+ document = copy.deepcopy(document)
+ return _nested_alter(
+ document=document,
+ keys=key,
+ callback_function=callback_function,
+ function_parameters=function_parameters,
+ conversion_function=conversion_function,
+ wild_alter=wild_alter,
+ in_place=in_place,
+ key_len=key_len,
+ )
+
+
+def _call_callback(
+ value_list, callback_function, function_parameters, conversion_function
+):
+ """
+ internal helper to call the callback function
+ """
+ return_list = []
+ # loop over all values
+ for value in value_list:
+ # apply the conversion function
+ if conversion_function is not None:
+ value = conversion_function(value)
+ # if functions arguments are present, expand the list to variables
+ # via the magic operator *
+ if function_parameters:
+ trans_val = callback_function(value, *function_parameters)
+ else:
+ trans_val = callback_function(value)
+ # append the transformed element to the list
+ return_list.append(trans_val)
+ return return_list
+
+
+def _nested_alter(
+ document,
+ keys,
+ callback_function,
+ function_parameters,
+ conversion_function,
+ wild_alter,
+ in_place,
+ key_len,
+):
+
+ # return data if no callback_function is provided
+ if callback_function is None:
+ warnings.warn("Please provide a callback_function to nested_alter().")
+ return document
+
+ # iterate over all given keys in the list
+ for key in keys:
+ # try to find the key:
+ findings = nested_lookup(key, document, with_keys=True, wild=wild_alter)
+ for k, v in findings.items():
+ trans_val = _call_callback(
+ v, callback_function, function_parameters, conversion_function
+ )
+ # use the transformed value and apply the update to the key
+ # (dont treat the lists as elements here)
+ document = nested_update(
+ document, k, trans_val, in_place=in_place, treat_as_element=False
+ )
+
+ return document
diff --git a/config_file/parse_value.py b/config_file/parse_value.py
new file mode 100644
index 0000000..12032d6
--- /dev/null
+++ b/config_file/parse_value.py
@@ -0,0 +1,218 @@
+"""This module allows you to parse a string into its native type."""
+import ast
+import re
+from distutils.util import strtobool
+from typing import Any
+
+
+def parse_value(value: Any) -> Any:
+ """Parse a value into native type.
+
+ parse_value('5') -> 5 (int)
+ parse_value('-5') -> -5 (int)
+
+ parse_value('5.52') -> 5.52 (float)
+ parse_value('-53.2') -> -53.2 (float)
+
+ parse_value('blahfafda') -> 'blahfafda' (string)
+
+ parse_value('true') -> True (bool)
+ parse_value('FALSE') -> False (bool)
+
+ parse_value(" [ [ [ [] ]] ] ") -> [[[[]]]] (list)
+
+ Args:
+ value: The value to parse.
+
+ Returns:
+ The parsed value, if it could be parsed
+ as a dictionary, list, int, float, or bool.
+ Otherwise, it simply returns the original
+ passed in value.
+ """
+ if isinstance(value, dict):
+ parsed = {}
+
+ for item in value:
+ parsed[item] = parse_value(value[item])
+
+ return parsed
+
+ if isinstance(value, list):
+ parsed = []
+
+ for item in value:
+ parsed.append(parse_value(item))
+
+ return parsed
+
+ if can_be_parsed_as_int(value):
+ return int(value.strip()) if isinstance(value, str) else int(value)
+
+ if can_be_parsed_as_float(value):
+ return float(value.strip()) if isinstance(value, str) else float(value)
+
+ if can_be_parsed_as_bool(value):
+ return bool(value) if isinstance(value, bool) else bool(strtobool(value))
+
+ if can_be_parsed_as_dict(value):
+ return parse_value(ast.literal_eval(value.strip()))
+
+ if can_be_parsed_as_list(value):
+ return parse_value(ast.literal_eval(value.strip()))
+
+ return value
+
+
+def can_be_parsed_as_int(value: Any) -> bool:
+ """Check whether a value can be parsed as a integer.
+
+ can_be_parsed_as_int(5) -> True
+ can_be_parsed_as_int("5") -> True
+ can_be_parsed_as_int("-5") -> True
+ can_be_parsed_as_int(True) -> False
+
+ Args:
+ value: The value to check if it can be parsed as an integer.
+
+ Returns:
+ True if we can parse the value as a integer. False otherwise.
+ """
+ if isinstance(value, int) and not isinstance(value, bool):
+ return True
+
+ if not isinstance(value, str):
+ return False
+
+ value = value.strip()
+
+ if value.startswith("-"):
+ return value[1:].isdigit()
+
+ return value.isdigit()
+
+
+def can_be_parsed_as_float(value: Any) -> bool:
+ """Checks whether a value can be parsed as a float.
+
+ can_be_parsed_as_float(45) -> False
+ can_be_parsed_as_float(1.1) -> True
+ can_be_parsed_as_float("1.1") -> True
+ can_be_parsed_as_float("-1.1") -> True
+ can_be_parsed_as_float(".1") -> True
+
+ Args:
+ value: The value to be parsed.
+
+ Returns:
+ True if the value can be parsed as a float. False otherwise.
+ """
+ FLOAT_REGEX = r"^\d*\.\d+$"
+
+ if isinstance(value, float):
+ return True
+
+ if not isinstance(value, str):
+ return False
+
+ value = value.strip()
+
+ if value.startswith("-"):
+ value = value[1:]
+
+ return bool(re.match(FLOAT_REGEX, value))
+
+
+def can_be_parsed_as_bool(value: Any) -> bool:
+ """Checks whether a value can be parsed as a boolean.
+
+ can_be_parsed_as_bool(True) -> True
+ can_be_parsed_as_bool("true") -> True
+ can_be_parsed_as_bool("false") -> True
+ can_be_parsed_as_bool("TRUE") -> True
+ can_be_parsed_as_bool(0) -> False
+
+ Args:
+ value: The value to be parsed.
+
+ Returns:
+ True if the value can be parsed as a boolean. False otherwise.
+ """
+ if isinstance(value, bool):
+ return True
+
+ if not isinstance(value, str):
+ return False
+
+ value = value.lower().strip()
+
+ return value == "true" or value == "false"
+
+
+def can_be_parsed_as_dict(value: Any) -> bool:
+ """Checks whether a value can be parsed as a dictionary.
+
+ can_be_parsed_as_dict({}) -> True
+ can_be_parsed_as_dict("{}") -> True
+ can_be_parsed_as_dict(" { } ") -> True
+ can_be_parsed_as_dict("{ 'hello': 5 }") -> True
+ can_be_parsed_as_dict([]]) -> False
+ can_be_parsed_as_dict(" { invalid } ") -> False
+
+ Args:
+ value: The value to be parsed.
+
+ Returns:
+ True if the value can be parsed as a dictionary. False otherwise.
+ """
+ if isinstance(value, dict):
+ return True
+
+ if not isinstance(value, str):
+ return False
+
+ value = value.strip()
+
+ if value[0] == "{" and value[-1] == "}":
+ try:
+ ast.literal_eval(value)
+ return True
+ except Exception:
+ return False
+
+ return False
+
+
+def can_be_parsed_as_list(value: Any) -> bool:
+ """Checks whether a value can be parsed as a list.
+
+ can_be_parsed_as_list([]) -> True
+ can_be_parsed_as_list([1, 2]) -> True
+ can_be_parsed_as_list("[]") -> True
+ can_be_parsed_as_list(" [] ") -> True
+ can_be_parsed_as_list("[1, 2]") -> True
+ can_be_parsed_as_list({}) -> False
+ can_be_parsed_as_list(" [ invalid ] ") -> False
+
+ Args:
+ value: The value to be parsed.
+
+ Returns:
+ True if the value can be parsed as a list. False otherwise.
+ """
+ if isinstance(value, list):
+ return True
+
+ if not isinstance(value, str):
+ return False
+
+ value = value.strip()
+
+ if value[0] == "[" and value[-1] == "]":
+ try:
+ ast.literal_eval(value)
+ return True
+ except Exception:
+ return False
+
+ return False
diff --git a/config_file/parsers/__init__.py b/config_file/parsers/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/config_file/parsers/__init__.py
+++ /dev/null
diff --git a/config_file/parsers/base_parser.py b/config_file/parsers/base_parser.py
deleted file mode 100644
index 42f93b1..0000000
--- a/config_file/parsers/base_parser.py
+++ /dev/null
@@ -1,79 +0,0 @@
-from abc import ABC, abstractmethod
-
-
-class BaseParser(ABC):
- """
- The abstract base parser for all other parsers to implement.
-
- All the keys are specified in a 'dot' syntax. So if you have
- sections with subsections with a key that you're trying to get
- the value of, you'd use 'section.subsection.key' as the key parameter.
- """
-
- @abstractmethod
- def __init__(self, file_contents: str):
- """
- All parsers will take in the file as a string, parse
- them internally to their own representation that they
- can work with, and are able to stringify them back out
- when we need to save (write) them.
-
- It is up to the caller of the parser to read in the file to
- the parser and save the file when they are done using stringify().
- """
- self.content = file_contents
- self.parsed_content = self.parse(self.content)
-
- @abstractmethod
- def get(self, key, parse_types=False):
- """
- Retrieve the value of a key in its native type.
- This means the string 'true' will be parsed back as the
- boolean True.
-
- If parse_types is set to False, all values will be returned
- back as strings.
- """
- raise NotImplementedError
-
- @abstractmethod
- def set(self, key, value) -> bool:
- """Sets the value of a key."""
- raise NotImplementedError
-
- @abstractmethod
- def delete(self, section_key) -> bool:
- """Deletes a key/value pair or entire sections."""
- raise NotImplementedError
-
- @abstractmethod
- def stringify(self) -> str:
- """
- Using self.__contents, converts the parsed internal representation
- of the file back into a string.
- """
- raise NotImplementedError
-
- @abstractmethod
- def has(self, section_key: str) -> bool:
- """
- Check if a section, sub-section, or key exists in the file
- using a section.key format.
-
- Some formats, like JSON, do not have sections and therefore,
- it would only be checking if
- """
- raise NotImplementedError
-
- @abstractmethod
- def parse(self, file_contents: str):
- """
- Parse the file_contents into an internal representation
- the given parser can work with. It should not return anything
- if you're going to be using the super() constructor.
- """
- raise NotImplementedError
-
-
-class ParsingError(Exception):
- """Unable to parse the configuration file"""
diff --git a/config_file/parsers/ini_parser.py b/config_file/parsers/ini_parser.py
deleted file mode 100644
index 81f2d1b..0000000
--- a/config_file/parsers/ini_parser.py
+++ /dev/null
@@ -1,123 +0,0 @@
-import configparser
-from io import StringIO
-
-from config_file.parsers.base_parser import BaseParser, ParsingError
-from config_file.parsers.parse_value import parse_value
-from config_file.utils import split_on_dot
-
-
-class IniParser(BaseParser):
- def __init__(self, file_contents: str):
- """Reads in the file contents into the configparser."""
- super().__init__(file_contents)
-
- def parse(self, file_contents: str):
- try:
- parser = configparser.ConfigParser()
- parser.read_string(file_contents)
- return parser
- except configparser.Error as error:
- raise ParsingError(error)
-
- def get(self, section_key: str, parse_types: bool = False):
- """
- Read the value of `section.key` of the config file.
-
- :param section_key: The section and key to read from in the config file.
- e.g. 'section1.key2'
- :param parse_types: Coerces the return value to its native type.
- :return: The value of the key, parsed to its native type if parse_types is True.
-
- :raises ValueError: if the section_key given is not in a dot format. e.g.
- 'section1.key'
- :raises ParsingError: if the specified `section.key` is not found, in an
- invalid format, or if we are unable to coerce the return value to value_type.
- """
- if "." not in section_key:
- return self.__retrieve_section(section_key, parse_types)
-
- try:
- section, key = split_on_dot(section_key, only_last_dot=True)
- value = self.parsed_content.get(section, key)
- return parse_value(value) if parse_types else value
- except configparser.Error as error:
- raise ParsingError(error.message)
-
- def __retrieve_section(self, section, parse_types):
- items = dict(self.parsed_content.items(section))
-
- if not parse_types:
- return items
-
- for item in items:
- items[item] = parse_value(items[item])
-
- return items
-
- def set(self, section_key: str, value) -> bool:
- """
- Sets the value of 'section.key' of the config file. If the specified section
- is not in the configuration file, it will be created before adding the key
- to it.
-
- :param section_key: The key to set from the config file. e.g. 'section1.key'
-
- :param value: The value to set the key to. It can be any type that can
- be converted to a string.
-
- :return: True if the setting was successful.
-
- :raises ValueError: If there is no dot (.) in section_key
- """
- section, key = split_on_dot(section_key, only_last_dot=True)
-
- if value is not None and not self.parsed_content.has_section(section):
- self.parsed_content.add_section(section)
-
- if not isinstance(value, str):
- value = str(value)
-
- self.parsed_content.set(section, key, value)
- return True
-
- def delete(self, section_key: str) -> bool:
- """
- Deletes a key or an entire section.
-
- :param section_key: The key to delete from the config file.
- e.g. 'ocr.engine'. If no dot (.) is present, it will assume you are trying
- to delete the entire section.
-
- :return: True if the deletion succeeded.
-
- :raise ValueError: If the section or key does not exist in the config file.
- """
- if "." not in section_key:
- if not self.parsed_content.has_section(section_key):
- raise ValueError(
- f"Cannot delete {section_key} because it is not in the config file."
- )
-
- self.parsed_content.remove_section(section_key)
- return True
-
- section, key = split_on_dot(section_key, only_last_dot=True)
- if key not in self.parsed_content[section]:
- raise ValueError(
- f"Cannot delete {section}.{key} because {key} is not in {section}."
- )
-
- self.parsed_content.remove_option(section, key)
- return True
-
- def stringify(self) -> str:
- buffer = StringIO()
- self.parsed_content.write(buffer)
- return buffer.getvalue()
-
- def has(self, section_key: str) -> bool:
- if "." not in section_key:
- return self.parsed_content.has_section(section_key)
-
- section, key = split_on_dot(section_key, only_last_dot=True)
- return self.parsed_content.has_option(section, key)
diff --git a/config_file/parsers/json_parser.py b/config_file/parsers/json_parser.py
deleted file mode 100644
index 20eb085..0000000
--- a/config_file/parsers/json_parser.py
+++ /dev/null
@@ -1,129 +0,0 @@
-import json
-
-from nested_lookup import (
- get_occurrence_of_key,
- nested_delete,
- nested_lookup,
- nested_update,
-)
-
-from config_file.parsers.base_parser import BaseParser, ParsingError
-from config_file.parsers.parse_value import parse_value
-from config_file.utils import split_on_dot
-
-
-class JsonParser(BaseParser):
- """
- The JsonParser allows use of json files with ConfigFile. The syntax it
- supports is a bit more flexible than the IniParser.
-
- By default, the dot syntax is used. However, if you'd like to get/set/delete all
- of a particular key, you can specify so with an optional parameter.
-
- Example:
-
- json = {
- "key1": {
- "key2": "foo",
- "key1": "bar"
- },
- "foo": "bar"
- }
- parser = JsonParser(json.dumps(json))
- parser.get('key1')
- >>> { "key2": "foo", "key1": "bar" }
- parser.get('key1.key2')
- >>> "foo"
- parser.get('key1', get_all=True)
- >>> [{ "key2": "foo", "key1": "bar" }, "bar"]
- """
-
- def __init__(self, file_contents: str):
- """Reads in the file contents into the parser."""
- super().__init__(file_contents)
-
- def parse(self, file_contents: str):
- try:
- return json.loads(file_contents)
- except json.decoder.JSONDecodeError as error:
- raise ParsingError(error)
-
- def get(self, key: str, parse_types: bool = False, get_all: bool = False):
- """
- Retrieve values using a dot syntax.
-
- :param key: The key to retrieve. e.g. 'foo.bar.boo'
-
- :param parse_types: Whether you'd like the type parsed into its native one.
-
- :param get_all: Specify whether you'd like to recursively receive
- all values that match the given key. Returned as a list.
- e.g. 'foo' would retrieve all values that have the key 'foo', anywhere
- in the json.
-
- :return: the value of the given key
- """
- if get_all:
- result = nested_lookup(key, self.parsed_content)
- elif "." in key:
- split_keys = split_on_dot(key)
- result = self.parsed_content
-
- # Used so we can more precisely specify what key is causing the error.
- key_for_error = None
- try:
- for key in split_keys:
- key_for_error = key
- result = result[key]
- except TypeError:
- raise ParsingError(
- f"Cannot get {key} because {key_for_error} is not subscriptable."
- )
- else:
- result = self.parsed_content[key]
-
- return parse_value(result) if parse_types else result
-
- def set(self, key: str, value, set_all: bool = False):
- if set_all:
- nested_update(self.parsed_content, key, value, in_place=True)
- elif "." in key:
- indexes = split_on_dot(key)
- indexes_length = len(indexes)
-
- ref = self.parsed_content
- for index, key in enumerate(indexes):
- if index == indexes_length - 1:
- ref[key] = value
- break
-
- ref = ref[key]
- else:
- self.parsed_content[key] = value
-
- return True
-
- def delete(self, key, delete_all: bool = False):
- if delete_all:
- nested_delete(self.parsed_content, key, in_place=True)
- elif "." in key:
- indexes = split_on_dot(key)
- indexes_length = len(indexes)
-
- ref = self.parsed_content
- for index, key in enumerate(indexes):
- if index == indexes_length - 1:
- del ref[key]
- break
-
- ref = ref[key]
- else:
- del self.parsed_content[key]
-
- return True
-
- def stringify(self) -> str:
- return json.dumps(self.parsed_content)
-
- def has(self, search_key: str) -> bool:
- return get_occurrence_of_key(self.parsed_content, key=search_key) > 0
diff --git a/config_file/parsers/parse_value.py b/config_file/parsers/parse_value.py
deleted file mode 100644
index e58781a..0000000
--- a/config_file/parsers/parse_value.py
+++ /dev/null
@@ -1,87 +0,0 @@
-"""
-Parse types allows you to check or parse a string into its native type.
-
-Example:
- parse_value('5') -> 5 (int)
- parse_value('-5') -> -5 (int)
-
- parse_value('5.52') -> 5.52 (float)
- parse_value('-53.2') -> -53.2 (float)
-
- parse_value('blahfafda') -> 'blahfafda' (string)
-
- parse_value('true') -> True (bool)
- parse_value('FALSE') -> False (bool)
-
-
-"5".isdigit() -> True
-"-5".isdigit() -> False
-can_be_parsed_as_int("-5") -> True
-"""
-import re
-from distutils.util import strtobool
-
-
-def parse_value(value):
- if can_be_parsed_as_int(value):
- return int(value)
-
- if can_be_parsed_as_float(value):
- return float(value)
-
- if can_be_parsed_as_bool(value):
- return value if type(value) is bool else bool(strtobool(value))
-
- if type(value) is dict:
- parsed = {}
-
- for item in value:
- parsed[item] = parse_value(value[item])
-
- return parsed
-
- if type(value) is list:
- parsed = []
-
- for item in value:
- parsed.append(parse_value(item))
-
- return parsed
-
- return value
-
-
-def can_be_parsed_as_int(value) -> bool:
- if type(value) is int:
- return True
-
- if type(value) is not str:
- return False
-
- if value.startswith("-"):
- return value[1:].isdigit()
-
- return value.isdigit()
-
-
-def can_be_parsed_as_float(value) -> bool:
- if type(value) is float:
- return True
-
- if type(value) is not str:
- return False
-
- if value.startswith("-"):
- return bool(re.match(r"^\d*\.\d+$", value[1:]))
-
- return bool(re.match(r"^\d*\.\d+$", value))
-
-
-def can_be_parsed_as_bool(value) -> bool:
- if type(value) is bool:
- return True
-
- if type(value) is not str:
- return False
-
- return value.lower() == "true" or value.lower() == "false"
diff --git a/config_file/toml_parser.py b/config_file/toml_parser.py
new file mode 100644
index 0000000..d3cf226
--- /dev/null
+++ b/config_file/toml_parser.py
@@ -0,0 +1,18 @@
+from .base_parser import BaseParser
+
+
+class TomlParser(BaseParser):
+ def __init__(self, file_contents: str):
+ try:
+ import tomlkit
+ from tomlkit.exceptions import ParseError
+
+ super().__init__(
+ file_contents=file_contents, module=tomlkit, decode_error=ParseError,
+ )
+ except ImportError:
+ raise ImportError(
+ "It doesn't appear `tomlkit` is installed, but a toml "
+ "file was attempted to be used. Install the `toml` "
+ "extra first with `pip install config-file[toml]`."
+ )
diff --git a/config_file/utils.py b/config_file/utils.py
index 61f0ae0..cbbf7a7 100644
--- a/config_file/utils.py
+++ b/config_file/utils.py
@@ -1,21 +1,38 @@
-def split_on_dot(line: str, only_last_dot=False):
+from pathlib import Path
+from typing import List, Union
+
+
+def split_on_dot(line: Union[str, Path], only_last_dot: bool = False) -> List[str]:
"""
Split a string on the dot character (.).
- :param line: The line ot split on.
- :param only_last_dot: Only split on the last occurrence of the dot.
+ Args:
+ line: The line ot split on.
+ only_last_dot: Only split on the last occurrence of the dot.
- :raises ValueError: if the line does not have a dot.
+ Raises:
+ ValueError: if the line does not have a dot.
"""
+ if isinstance(line, Path):
+ line = str(line)
+
if "." not in line:
- # TODO: This is used in the parser for section.keys where a more specific
- # error message would be nice, but it is only used more generically to, say,
- # split a file path. We may just have to insert some try-catches to catch the
- # ValueError and insert a more specific error message or create a custom error
- # for this method?
- raise ValueError(
- "section_key must contain the section and key separated by a dot. "
- + "e.g. 'section.key'"
- )
+ raise ValueError(f"The given string does not have a dot to split on: {line}")
return line.rsplit(".", 1) if only_last_dot else line.split(".")
+
+
+class Default:
+ """
+ Default is used for the `default` value in ConfigFile's `get`.
+
+ Previously, the default value for `get` was None. However, then
+ the user cannot have `get` return a default value of None. So this
+ class is used instead to get around that limitation.
+ """
+
+ def __init__(self, value):
+ self.value = value
+
+ def __repr__(self):
+ return "Default Value: {} ({})".format(self.value, type(self.value))
diff --git a/config_file/yaml_parser.py b/config_file/yaml_parser.py
new file mode 100644
index 0000000..8d88881
--- /dev/null
+++ b/config_file/yaml_parser.py
@@ -0,0 +1,21 @@
+from .base_parser import BaseParser
+
+
+class YamlParser(BaseParser):
+ def __init__(self, file_contents: str):
+ try:
+ from ruamel.yaml import YAML, YAMLError, round_trip_dump, round_trip_load
+
+ yaml = YAML(typ="safe")
+ yaml.loads = round_trip_load
+ yaml.dumps = round_trip_dump
+
+ super().__init__(
+ file_contents=file_contents, module=yaml, decode_error=YAMLError
+ )
+ except ImportError:
+ raise ImportError(
+ "It doesn't appear `ruamel.yaml` is installed, but a yaml "
+ "file was attempted to be used. Install the `yaml` "
+ "extra first with `pip install config-file[yaml]`."
+ )
diff --git a/docs/Makefile b/docs/Makefile
deleted file mode 100644
index d0c3cbf..0000000
--- a/docs/Makefile
+++ /dev/null
@@ -1,20 +0,0 @@
-# Minimal makefile for Sphinx documentation
-#
-
-# You can set these variables from the command line, and also
-# from the environment for the first two.
-SPHINXOPTS ?=
-SPHINXBUILD ?= sphinx-build
-SOURCEDIR = source
-BUILDDIR = build
-
-# Put it first so that "make" without argument is like "make help".
-help:
- @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
-
-.PHONY: help Makefile
-
-# Catch-all target: route all unknown targets to Sphinx using the new
-# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
-%: Makefile
- @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
diff --git a/docs/make.bat b/docs/make.bat
deleted file mode 100644
index 6247f7e..0000000
--- a/docs/make.bat
+++ /dev/null
@@ -1,35 +0,0 @@
-@ECHO OFF
-
-pushd %~dp0
-
-REM Command file for Sphinx documentation
-
-if "%SPHINXBUILD%" == "" (
- set SPHINXBUILD=sphinx-build
-)
-set SOURCEDIR=source
-set BUILDDIR=build
-
-if "%1" == "" goto help
-
-%SPHINXBUILD% >NUL 2>NUL
-if errorlevel 9009 (
- echo.
- echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
- echo.installed, then set the SPHINXBUILD environment variable to point
- echo.to the full path of the 'sphinx-build' executable. Alternatively you
- echo.may add the Sphinx directory to PATH.
- echo.
- echo.If you don't have Sphinx installed, grab it from
- echo.http://sphinx-doc.org/
- exit /b 1
-)
-
-%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
-goto end
-
-:help
-%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
-
-:end
-popd
diff --git a/docs/source/api-reference.rst b/docs/source/api-reference.rst
deleted file mode 100644
index 4ea8c91..0000000
--- a/docs/source/api-reference.rst
+++ /dev/null
@@ -1,2 +0,0 @@
-API Reference
-============= \ No newline at end of file
diff --git a/docs/source/conf.py b/docs/source/conf.py
deleted file mode 100644
index 1c16a92..0000000
--- a/docs/source/conf.py
+++ /dev/null
@@ -1,58 +0,0 @@
-# Configuration file for the Sphinx documentation builder.
-#
-# This file only contains a selection of the most common options. For a full
-# list see the documentation:
-# https://www.sphinx-doc.org/en/master/usage/configuration.html
-
-# -- Path setup --------------------------------------------------------------
-
-# If extensions (or modules to document with autodoc) are in another directory,
-# add these directories to sys.path here. If the directory is relative to the
-# documentation root, use os.path.abspath to make it absolute, like shown here.
-
-import os
-import sys
-
-sys.path.insert(0, os.path.abspath("../.."))
-
-
-# -- Project information -----------------------------------------------------
-
-project = "Config File"
-copyright = "2020, Eugene Triguba"
-author = "Eugene Triguba"
-
-# The full version, including alpha/beta/rc tags
-release = "0.10.0"
-
-
-# -- General configuration ---------------------------------------------------
-
-# Add any Sphinx extension module names here, as strings. They can be
-# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
-# ones.
-extensions = ["sphinx.ext.autodoc", "sphinx.ext.autosectionlabel"]
-
-# Add any paths that contain templates here, relative to this directory.
-templates_path = ["_templates"]
-
-# List of patterns, relative to source directory, that match files and
-# directories to ignore when looking for source files.
-# This pattern also affects html_static_path and html_extra_path.
-exclude_patterns = []
-
-# Specify the master doc for read the docs
-master_doc = "index"
-
-
-# -- Options for HTML output -------------------------------------------------
-
-# The theme to use for HTML and HTML Help pages. See the documentation for
-# a list of builtin themes.
-#
-html_theme = "sphinx_rtd_theme"
-
-# Add any paths that contain custom static files (such as style sheets) here,
-# relative to this directory. They are copied after the builtin static files,
-# so a file named "default.css" will overwrite the builtin "default.css".
-html_static_path = ["_static"]
diff --git a/docs/source/getting-started.rst b/docs/source/getting-started.rst
deleted file mode 100644
index 92264a3..0000000
--- a/docs/source/getting-started.rst
+++ /dev/null
@@ -1,141 +0,0 @@
-Getting Started
-===============
-
-Example
--------
-
-The ``config_file`` package exposes ``ConfigFile``, ``ParsingError``,
-and ``BaseParser`` to the public API.
-
-Sample Configuration File
-~~~~~~~~~~~~~~~~~~~~~~~~~
-
-``config.ini``
-
-.. code:: ini
-
- [calendar]
- today = monday
- start_week_on_sunday = false
- today_index = 0
- quarter_hours_passed = 0.25
-
-Create a ConfigFile
-~~~~~~~~~~~~~~~~~~~
-
-.. code:: python
-
- from config_file import ConfigFile
-
- config = ConfigFile("~/.config/test/config.ini")
-
-Output your config file as a string
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-.. code:: python
-
- config.stringify()
- >>> '[calendar]\ntoday = monday\nstart_week_on_sunday = false\ntoday_index = 0\nquarter_hours_passed = 0.25\n\n'
-
-Retrieve values or sections
-~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-A section.key format is used for retrieving and setting values.
-
-.. code:: python
-
- # Values from the config file are automatically parsed
- config.get("calendar.start_week_on_sunday")
- >>> False
-
- # Unless you don't want them to be parsed
- config.get("calendar.start_week_on_sunday", parse_types=False)
- >>> 'false'
-
- config.get("calendar")
- >>> {'today': 'monday', 'start_week_on_sunday': False, 'today_index': 0, 'quarter_hours_passed': 0.25}
-
-Set values
-~~~~~~~~~~
-
-.. code:: python
-
- config.set("calendar.today_index", 20)
- >>> True
- config.stringify()
- >>> '[calendar]\ntoday = monday\nstart_week_on_sunday = false\ntoday_index = 20\nquarter_hours_passed = 0.25\n\n'
-
- # If you specify a section that isn't in your config file, the section and the key are added for you.
- config.set("week.tuesday_index", 2)
- >>> True
- config.stringify()
- >>> '[calendar]\ntoday = monday\nstart_week_on_sunday = false\ntoday_index = 20\nquarter_hours_passed = 0.25\n\n[week]\ntuesday_index = 2\n\n'
-
-.. _delete-sections-or-keyvalue-pairs:
-
-Delete sections or key/value pairs.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-.. code:: python
-
- config.delete('week')
- >>> True
- config.stringify()
- >>> '[calendar]\ntoday = monday\nstart_week_on_sunday = false\ntoday_index = 20\nquarter_hours_passed = 0.25\n\n'
-
- config.delete('calendar.today')
- >>> True
- config.stringify()
- >>> '[calendar]\nstart_week_on_sunday = false\ntoday_index = 20\nquarter_hours_passed = 0.25\n\n'
-
-Check whether you have a particular section or key
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-.. code:: python
-
- config.has('calendar')
- >>> True
-
- config.has('week')
- >>> False
-
- config.has('calendar.start_week_on_sunday')
- >>> True
-
-Save when you're done
-~~~~~~~~~~~~~~~~~~~~~
-
-Write the contents of the file back out. ``set()`` and ``delete()`` both
-modify the contents of the file and require a call to ``save()`` to
-write those changes back out.
-
-.. code:: python
-
- config.save()
- >>> True
-
-Restore the file back to its original
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-The current configuration file would be deleted and replaced by a copy
-of the original. By default, since our passed in config file was at path
-``~/.config/test/config.ini``, ``restore_original()`` will look for
-``~/.config/test/config.original.ini``.
-
-.. code:: python
-
- config.restore_original()
- >>> True
-
- # But you can also specify the original config file explicitly.
- config.restore_original(original_file_path="~/some_other_directory/this_is_actually_the_original.ini")
- >>> True
-
-Using your own parser
----------------------
-
-You can still use config file, even if you don't use one of our supported
-configuration formats. The ``ConfigFile`` object swaps in the parser it needs
-based on the file format. However, the constructor takes in an optional
-parser argument that you can use to supply your own custom parser. The only
-requirement is that the parser must be a concrete implementation of ``BaseParser``. \ No newline at end of file
diff --git a/docs/source/index.rst b/docs/source/index.rst
deleted file mode 100644
index 6b59715..0000000
--- a/docs/source/index.rst
+++ /dev/null
@@ -1,22 +0,0 @@
-Config File Documentation
-=========================
-
-Config File is a package that allows you to easily manipulate your configuration
-files whether they are in INI, JSON, YAML, or TOML.
-
-**Table of Contents:**
-
-.. toctree::
- :maxdepth: 2
-
- getting-started
- api-reference
- license
-
-
-Indices and tables
-==================
-
-* :ref:`genindex`
-* :ref:`modindex`
-* :ref:`search`
diff --git a/docs/source/license.rst b/docs/source/license.rst
deleted file mode 100644
index 01f3963..0000000
--- a/docs/source/license.rst
+++ /dev/null
@@ -1,4 +0,0 @@
-License
-=======
-
-.. include:: ../../LICENSE \ No newline at end of file
diff --git a/poetry.lock b/poetry.lock
index 9ee97f5..af82db2 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -12,15 +12,16 @@ description = "A small Python module for determining appropriate platform-specif
name = "appdirs"
optional = false
python-versions = "*"
-version = "1.4.3"
+version = "1.4.4"
[[package]]
category = "dev"
description = "Utilities for refactoring imports in python-like syntax."
+marker = "python_version >= \"3.6.1\" and python_version < \"4.0.0\""
name = "aspy.refactor-imports"
optional = false
-python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
-version = "1.1.0"
+python-versions = ">=3.6.1"
+version = "2.1.1"
[package.dependencies]
cached-property = "*"
@@ -43,7 +44,7 @@ marker = "sys_platform == \"win32\""
name = "atomicwrites"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
-version = "1.3.0"
+version = "1.4.0"
[[package]]
category = "dev"
@@ -112,6 +113,7 @@ version = "1.0.0"
[[package]]
category = "dev"
description = "A decorator for caching properties in classes."
+marker = "python_version >= \"3.6.1\" and python_version < \"4.0.0\""
name = "cached-property"
optional = false
python-versions = "*"
@@ -123,7 +125,7 @@ description = "Python package for providing Mozilla's CA Bundle."
name = "certifi"
optional = false
python-versions = "*"
-version = "2019.11.28"
+version = "2020.6.20"
[[package]]
category = "dev"
@@ -147,7 +149,7 @@ description = "Composable command line interface toolkit"
name = "click"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
-version = "7.1.1"
+version = "7.1.2"
[[package]]
category = "dev"
@@ -164,7 +166,7 @@ description = "Code coverage measurement for Python"
name = "coverage"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4"
-version = "5.0.4"
+version = "5.2.1"
[package.extras]
toml = ["toml"]
@@ -175,7 +177,7 @@ description = "Distribution utilities"
name = "distlib"
optional = false
python-versions = "*"
-version = "0.3.0"
+version = "0.3.1"
[[package]]
category = "dev"
@@ -187,14 +189,6 @@ version = "0.16"
[[package]]
category = "dev"
-description = "Discover and load entry points from installed packages."
-name = "entrypoints"
-optional = false
-python-versions = ">=2.7"
-version = "0.3"
-
-[[package]]
-category = "dev"
description = "A platform independent file lock."
name = "filelock"
optional = false
@@ -203,17 +197,20 @@ version = "3.0.12"
[[package]]
category = "dev"
-description = "the modular source code checker: pep8, pyflakes and co"
+description = "the modular source code checker: pep8 pyflakes and co"
name = "flake8"
optional = false
-python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
-version = "3.7.9"
+python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7"
+version = "3.8.3"
[package.dependencies]
-entrypoints = ">=0.3.0,<0.4.0"
mccabe = ">=0.6.0,<0.7.0"
-pycodestyle = ">=2.5.0,<2.6.0"
-pyflakes = ">=2.1.0,<2.2.0"
+pycodestyle = ">=2.6.0a1,<2.7.0"
+pyflakes = ">=2.2.0,<2.3.0"
+
+[package.dependencies.importlib-metadata]
+python = "<3.8"
+version = "*"
[[package]]
category = "dev"
@@ -221,7 +218,7 @@ description = "File identification library for Python"
name = "identify"
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7"
-version = "1.4.13"
+version = "1.4.25"
[package.extras]
license = ["editdistance"]
@@ -232,7 +229,7 @@ description = "Internationalized Domain Names in Applications (IDNA)"
name = "idna"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
-version = "2.9"
+version = "2.10"
[[package]]
category = "dev"
@@ -249,14 +246,14 @@ marker = "python_version < \"3.8\""
name = "importlib-metadata"
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7"
-version = "1.6.0"
+version = "1.7.0"
[package.dependencies]
zipp = ">=0.5"
[package.extras]
docs = ["sphinx", "rst.linker"]
-testing = ["packaging", "importlib-resources"]
+testing = ["packaging", "pep517", "importlib-resources (>=1.3)"]
[[package]]
category = "dev"
@@ -265,13 +262,9 @@ marker = "python_version < \"3.7\""
name = "importlib-resources"
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7"
-version = "1.4.0"
+version = "3.0.0"
[package.dependencies]
-[package.dependencies.importlib-metadata]
-python = "<3.8"
-version = "*"
-
[package.dependencies.zipp]
python = "<3.8"
version = ">=0.4"
@@ -281,6 +274,14 @@ docs = ["sphinx", "rst.linker", "jaraco.packaging"]
[[package]]
category = "dev"
+description = "iniconfig: brain-dead simple config-ini parsing"
+name = "iniconfig"
+optional = false
+python-versions = "*"
+version = "1.0.1"
+
+[[package]]
+category = "dev"
description = "A Python utility / library to sort Python imports."
name = "isort"
optional = false
@@ -299,7 +300,7 @@ description = "A very fast and expressive template engine."
name = "jinja2"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
-version = "2.11.1"
+version = "2.11.2"
[package.dependencies]
MarkupSafe = ">=0.23"
@@ -329,18 +330,31 @@ description = "More routines for operating on iterables, beyond itertools"
name = "more-itertools"
optional = false
python-versions = ">=3.5"
-version = "8.2.0"
+version = "8.4.0"
[[package]]
-category = "main"
-description = "Python functions for working with deeply nested documents (lists and dicts)"
-name = "nested-lookup"
+category = "dev"
+description = "Optional static typing for Python"
+name = "mypy"
optional = false
-python-versions = "*"
-version = "0.2.21"
+python-versions = ">=3.5"
+version = "0.782"
[package.dependencies]
-six = "*"
+mypy-extensions = ">=0.4.3,<0.5.0"
+typed-ast = ">=1.4.0,<1.5.0"
+typing-extensions = ">=3.7.4"
+
+[package.extras]
+dmypy = ["psutil (>=4.0)"]
+
+[[package]]
+category = "dev"
+description = "Experimental type system extensions for programs checked with the mypy typechecker."
+name = "mypy-extensions"
+optional = false
+python-versions = "*"
+version = "0.4.3"
[[package]]
category = "dev"
@@ -348,7 +362,7 @@ description = "Node.js virtual environment builder"
name = "nodeenv"
optional = false
python-versions = "*"
-version = "1.3.5"
+version = "1.4.0"
[[package]]
category = "dev"
@@ -356,7 +370,7 @@ description = "Core utilities for Python packages"
name = "packaging"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
-version = "20.3"
+version = "20.4"
[package.dependencies]
pyparsing = ">=2.0.2"
@@ -368,7 +382,7 @@ description = "Utility library for gitignore style pattern matching of file path
name = "pathspec"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
-version = "0.7.0"
+version = "0.8.0"
[[package]]
category = "dev"
@@ -388,6 +402,17 @@ dev = ["pre-commit", "tox"]
[[package]]
category = "dev"
+description = "A collection of helpful Python tools!"
+name = "pockets"
+optional = false
+python-versions = "*"
+version = "0.9.1"
+
+[package.dependencies]
+six = ">=1.5.2"
+
+[[package]]
+category = "dev"
description = "A framework for managing and maintaining multi-language pre-commit hooks."
name = "pre-commit"
optional = false
@@ -414,11 +439,22 @@ version = "*"
[[package]]
category = "dev"
+description = "Cross-platform lib for process and system monitoring in Python."
+name = "psutil"
+optional = false
+python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
+version = "5.7.2"
+
+[package.extras]
+test = ["ipaddress", "mock", "unittest2", "enum34", "pywin32", "wmi"]
+
+[[package]]
+category = "dev"
description = "library with cross-python path, ini-parsing, io, code, log facilities"
name = "py"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
-version = "1.8.1"
+version = "1.9.0"
[[package]]
category = "dev"
@@ -426,7 +462,7 @@ description = "Python style guide checker"
name = "pycodestyle"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
-version = "2.5.0"
+version = "2.6.0"
[[package]]
category = "dev"
@@ -434,7 +470,7 @@ description = "passive checker of Python programs"
name = "pyflakes"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
-version = "2.1.1"
+version = "2.2.0"
[[package]]
category = "dev"
@@ -450,7 +486,7 @@ description = "Python parsing module"
name = "pyparsing"
optional = false
python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
-version = "2.4.6"
+version = "2.4.7"
[[package]]
category = "dev"
@@ -458,24 +494,25 @@ description = "pytest: simple powerful testing with Python"
name = "pytest"
optional = false
python-versions = ">=3.5"
-version = "5.4.1"
+version = "6.0.1"
[package.dependencies]
atomicwrites = ">=1.0"
attrs = ">=17.4.0"
colorama = "*"
+iniconfig = "*"
more-itertools = ">=4.0.0"
packaging = "*"
pluggy = ">=0.12,<1.0"
-py = ">=1.5.0"
-wcwidth = "*"
+py = ">=1.8.2"
+toml = "*"
[package.dependencies.importlib-metadata]
python = "<3.8"
version = ">=0.12"
[package.extras]
-checkqa-mypy = ["mypy (v0.761)"]
+checkqa_mypy = ["mypy (0.780)"]
testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"]
[[package]]
@@ -483,15 +520,28 @@ category = "dev"
description = "Pytest plugin for measuring coverage."
name = "pytest-cov"
optional = false
-python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
-version = "2.8.1"
+python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
+version = "2.10.0"
[package.dependencies]
coverage = ">=4.4"
-pytest = ">=3.6"
+pytest = ">=4.6"
[package.extras]
-testing = ["fields", "hunter", "process-tests (2.0.2)", "six", "virtualenv"]
+testing = ["fields", "hunter", "process-tests (2.0.2)", "six", "pytest-xdist", "virtualenv"]
+
+[[package]]
+category = "dev"
+description = "pytest-sugar is a plugin for pytest that changes the default look and feel of pytest (e.g. progressbar, show tests that fail instantly)."
+name = "pytest-sugar"
+optional = false
+python-versions = "*"
+version = "0.9.4"
+
+[package.dependencies]
+packaging = ">=14.1"
+pytest = ">=2.9"
+termcolor = ">=1.1.0"
[[package]]
category = "dev"
@@ -499,10 +549,10 @@ description = "World timezone definitions, modern and historical"
name = "pytz"
optional = false
python-versions = "*"
-version = "2019.3"
+version = "2020.1"
[[package]]
-category = "main"
+category = "dev"
description = "YAML parser and emitter for Python"
name = "pyyaml"
optional = false
@@ -515,7 +565,7 @@ description = "Alternative regular expression module, to replace re."
name = "regex"
optional = false
python-versions = "*"
-version = "2020.2.20"
+version = "2020.7.14"
[[package]]
category = "dev"
@@ -523,7 +573,7 @@ description = "Python HTTP for Humans."
name = "requests"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
-version = "2.23.0"
+version = "2.24.0"
[package.dependencies]
certifi = ">=2017.4.17"
@@ -536,23 +586,50 @@ security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"]
socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7)", "win-inet-pton"]
[[package]]
+category = "main"
+description = "ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order"
+name = "ruamel.yaml"
+optional = true
+python-versions = "*"
+version = "0.16.10"
+
+[package.dependencies]
+[package.dependencies."ruamel.yaml.clib"]
+python = "<3.9"
+version = ">=0.1.2"
+
+[package.extras]
+docs = ["ryd"]
+jinja2 = ["ruamel.yaml.jinja2 (>=0.2)"]
+
+[[package]]
+category = "main"
+description = "C version of reader, parser and emitter for ruamel.yaml derived from libyaml"
+marker = "platform_python_implementation == \"CPython\" and python_version < \"3.9\""
+name = "ruamel.yaml.clib"
+optional = true
+python-versions = "*"
+version = "0.2.0"
+
+[[package]]
category = "dev"
description = "Statically populate the `known_third_party` `isort` setting."
+marker = "python_version >= \"3.6.1\" and python_version < \"4.0.0\""
name = "seed-isort-config"
optional = false
-python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7"
-version = "1.9.4"
+python-versions = ">=3.6.1"
+version = "2.2.0"
[package.dependencies]
"aspy.refactor-imports" = "*"
[[package]]
-category = "main"
+category = "dev"
description = "Python 2 and 3 compatibility utilities"
name = "six"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
-version = "1.14.0"
+version = "1.15.0"
[[package]]
category = "dev"
@@ -653,6 +730,18 @@ test = ["pytest", "flake8", "mypy"]
[[package]]
category = "dev"
+description = "Sphinx \"napoleon\" extension."
+name = "sphinxcontrib-napoleon"
+optional = false
+python-versions = "*"
+version = "0.7"
+
+[package.dependencies]
+pockets = ">=0.3"
+six = ">=1.5.2"
+
+[[package]]
+category = "dev"
description = "sphinxcontrib-qthelp is a sphinx extension which outputs QtHelp document."
name = "sphinxcontrib-qthelp"
optional = false
@@ -681,18 +770,35 @@ description = "tasks runner for python projects"
name = "taskipy"
optional = false
python-versions = ">=3.6,<4.0"
-version = "1.2.1"
+version = "1.3.0"
[package.dependencies]
+psutil = ">=5.7.2,<6.0.0"
toml = ">=0.10.0,<0.11.0"
[[package]]
-category = "main"
+category = "dev"
+description = "ANSII Color formatting for output in terminal."
+name = "termcolor"
+optional = false
+python-versions = "*"
+version = "1.1.0"
+
+[[package]]
+category = "dev"
description = "Python Library for Tom's Obvious, Minimal Language"
name = "toml"
optional = false
python-versions = "*"
-version = "0.10.0"
+version = "0.10.1"
+
+[[package]]
+category = "main"
+description = "Style preserving TOML library"
+name = "tomlkit"
+optional = true
+python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
+version = "0.6.0"
[[package]]
category = "dev"
@@ -704,15 +810,23 @@ version = "1.4.1"
[[package]]
category = "dev"
+description = "Backported and Experimental Type Hints for Python 3.5+"
+name = "typing-extensions"
+optional = false
+python-versions = "*"
+version = "3.7.4.2"
+
+[[package]]
+category = "dev"
description = "HTTP library with thread-safe connection pooling, file post, and more."
name = "urllib3"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4"
-version = "1.25.8"
+version = "1.25.10"
[package.extras]
brotli = ["brotlipy (>=0.6.0)"]
-secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"]
+secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "pyOpenSSL (>=0.14)", "ipaddress"]
socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7,<2.0)"]
[[package]]
@@ -721,11 +835,11 @@ description = "Virtual Python Environment builder"
name = "virtualenv"
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7"
-version = "20.0.15"
+version = "20.0.30"
[package.dependencies]
appdirs = ">=1.4.3,<2"
-distlib = ">=0.3.0,<1"
+distlib = ">=0.3.1,<1"
filelock = ">=3.0.0,<4"
six = ">=1.9.0,<2"
@@ -735,19 +849,11 @@ version = ">=0.12,<2"
[package.dependencies.importlib-resources]
python = "<3.7"
-version = ">=1.0,<2"
+version = ">=1.0"
[package.extras]
-docs = ["sphinx (>=2.0.0,<3)", "sphinx-argparse (>=0.2.5,<1)", "sphinx-rtd-theme (>=0.4.3,<1)", "towncrier (>=19.9.0rc1)", "proselint (>=0.10.2,<1)"]
-testing = ["pytest (>=4.0.0,<6)", "coverage (>=4.5.1,<6)", "pytest-mock (>=2.0.0,<3)", "pytest-env (>=0.6.2,<1)", "pytest-timeout (>=1.3.4,<2)", "packaging (>=20.0)", "xonsh (>=0.9.13,<1)"]
-
-[[package]]
-category = "dev"
-description = "Measures number of Terminal column cells of wide-character codes"
-name = "wcwidth"
-optional = false
-python-versions = "*"
-version = "0.1.9"
+docs = ["proselint (>=0.10.2)", "sphinx (>=3)", "sphinx-argparse (>=0.2.5)", "sphinx-rtd-theme (>=0.4.3)", "towncrier (>=19.9.0rc1)"]
+testing = ["coverage (>=5)", "coverage-enable-subprocess (>=1)", "flaky (>=3)", "pytest (>=4)", "pytest-env (>=0.6.2)", "pytest-freezegun (>=0.4.1)", "pytest-mock (>=2)", "pytest-randomly (>=1)", "pytest-timeout (>=1)", "pytest-xdist (>=1.31.0)", "packaging (>=20.0)", "xonsh (>=0.9.16)"]
[[package]]
category = "dev"
@@ -763,11 +869,11 @@ docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"]
testing = ["jaraco.itertools", "func-timeout"]
[extras]
-toml = ["toml"]
-yaml = ["pyyaml"]
+toml = ["tomlkit"]
+yaml = ["ruamel.yaml"]
[metadata]
-content-hash = "08e43891b71c2bd97878564d8084ce7950165cfcccea39d0ad362363de3055c3"
+content-hash = "77ccb2f3b39aa3e40a6efccf08acd2065c796a615940f8c3bbc5a05666c1f813"
python-versions = "^3.6"
[metadata.files]
@@ -776,20 +882,20 @@ alabaster = [
{file = "alabaster-0.7.12.tar.gz", hash = "sha256:a661d72d58e6ea8a57f7a86e37d86716863ee5e92788398526d58b26a4e4dc02"},
]
appdirs = [
- {file = "appdirs-1.4.3-py2.py3-none-any.whl", hash = "sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e"},
- {file = "appdirs-1.4.3.tar.gz", hash = "sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92"},
+ {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"},
+ {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"},
]
"aspy.refactor-imports" = [
- {file = "aspy.refactor_imports-1.1.0-py2.py3-none-any.whl", hash = "sha256:6d465c18cadad7e5a87810ecf8e516cb6f78e91871f4f55d0f228c6c376bd16a"},
- {file = "aspy.refactor_imports-1.1.0.tar.gz", hash = "sha256:88418d9bd1a0d50b9d3836504469dce6f26ee8b2d78bd58b805d73dd8b381d55"},
+ {file = "aspy.refactor_imports-2.1.1-py2.py3-none-any.whl", hash = "sha256:9df76bf19ef81620068b785a386740ab3c8939fcbdcebf20c4a4e0057230d782"},
+ {file = "aspy.refactor_imports-2.1.1.tar.gz", hash = "sha256:eec8d1a73bedf64ffb8b589ad919a030c1fb14acf7d1ce0ab192f6eedae895c5"},
]
"aspy.yaml" = [
{file = "aspy.yaml-1.3.0-py2.py3-none-any.whl", hash = "sha256:463372c043f70160a9ec950c3f1e4c3a82db5fca01d334b6bc89c7164d744bdc"},
{file = "aspy.yaml-1.3.0.tar.gz", hash = "sha256:e7c742382eff2caed61f87a39d13f99109088e5e93f04d76eb8d4b28aa143f45"},
]
atomicwrites = [
- {file = "atomicwrites-1.3.0-py2.py3-none-any.whl", hash = "sha256:03472c30eb2c5d1ba9227e4c2ca66ab8287fbfbbda3888aa93dc2e28fc6811b4"},
- {file = "atomicwrites-1.3.0.tar.gz", hash = "sha256:75a9445bac02d8d058d5e1fe689654ba5a6556a1dfd8ce6ec55a0ed79866cfa6"},
+ {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"},
+ {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"},
]
attrs = [
{file = "attrs-19.3.0-py2.py3-none-any.whl", hash = "sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c"},
@@ -815,8 +921,8 @@ cached-property = [
{file = "cached_property-1.5.1-py2.py3-none-any.whl", hash = "sha256:3a026f1a54135677e7da5ce819b0c690f156f37976f3e30c5430740725203d7f"},
]
certifi = [
- {file = "certifi-2019.11.28-py2.py3-none-any.whl", hash = "sha256:017c25db2a153ce562900032d5bc68e9f191e44e9a0f762f373977de9df1fbb3"},
- {file = "certifi-2019.11.28.tar.gz", hash = "sha256:25b64c7da4cd7479594d035c08c2d809eb4aab3a26e5a990ea98cc450c320f1f"},
+ {file = "certifi-2020.6.20-py2.py3-none-any.whl", hash = "sha256:8fc0819f1f30ba15bdb34cceffb9ef04d99f420f68eb75d901e9560b8749fc41"},
+ {file = "certifi-2020.6.20.tar.gz", hash = "sha256:5930595817496dd21bb8dc35dad090f1c2cd0adfaf21204bf6732ca5d8ee34d3"},
]
cfgv = [
{file = "cfgv-3.0.0-py2.py3-none-any.whl", hash = "sha256:f22b426ed59cd2ab2b54ff96608d846c33dfb8766a67f0b4a6ce130ce244414f"},
@@ -827,92 +933,96 @@ chardet = [
{file = "chardet-3.0.4.tar.gz", hash = "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae"},
]
click = [
- {file = "click-7.1.1-py2.py3-none-any.whl", hash = "sha256:e345d143d80bf5ee7534056164e5e112ea5e22716bbb1ce727941f4c8b471b9a"},
- {file = "click-7.1.1.tar.gz", hash = "sha256:8a18b4ea89d8820c5d0c7da8a64b2c324b4dabb695804dbfea19b9be9d88c0cc"},
+ {file = "click-7.1.2-py2.py3-none-any.whl", hash = "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"},
+ {file = "click-7.1.2.tar.gz", hash = "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a"},
]
colorama = [
{file = "colorama-0.4.3-py2.py3-none-any.whl", hash = "sha256:7d73d2a99753107a36ac6b455ee49046802e59d9d076ef8e47b61499fa29afff"},
{file = "colorama-0.4.3.tar.gz", hash = "sha256:e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1"},
]
coverage = [
- {file = "coverage-5.0.4-cp27-cp27m-macosx_10_12_x86_64.whl", hash = "sha256:8a620767b8209f3446197c0e29ba895d75a1e272a36af0786ec70fe7834e4307"},
- {file = "coverage-5.0.4-cp27-cp27m-macosx_10_13_intel.whl", hash = "sha256:73aa6e86034dad9f00f4bbf5a666a889d17d79db73bc5af04abd6c20a014d9c8"},
- {file = "coverage-5.0.4-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:408ce64078398b2ee2ec08199ea3fcf382828d2f8a19c5a5ba2946fe5ddc6c31"},
- {file = "coverage-5.0.4-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:cda33311cb9fb9323958a69499a667bd728a39a7aa4718d7622597a44c4f1441"},
- {file = "coverage-5.0.4-cp27-cp27m-win32.whl", hash = "sha256:5f587dfd83cb669933186661a351ad6fc7166273bc3e3a1531ec5c783d997aac"},
- {file = "coverage-5.0.4-cp27-cp27m-win_amd64.whl", hash = "sha256:9fad78c13e71546a76c2f8789623eec8e499f8d2d799f4b4547162ce0a4df435"},
- {file = "coverage-5.0.4-cp27-cp27mu-manylinux1_i686.whl", hash = "sha256:2e08c32cbede4a29e2a701822291ae2bc9b5220a971bba9d1e7615312efd3037"},
- {file = "coverage-5.0.4-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:922fb9ef2c67c3ab20e22948dcfd783397e4c043a5c5fa5ff5e9df5529074b0a"},
- {file = "coverage-5.0.4-cp35-cp35m-macosx_10_12_x86_64.whl", hash = "sha256:c3fc325ce4cbf902d05a80daa47b645d07e796a80682c1c5800d6ac5045193e5"},
- {file = "coverage-5.0.4-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:046a1a742e66d065d16fb564a26c2a15867f17695e7f3d358d7b1ad8a61bca30"},
- {file = "coverage-5.0.4-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:6ad6ca45e9e92c05295f638e78cd42bfaaf8ee07878c9ed73e93190b26c125f7"},
- {file = "coverage-5.0.4-cp35-cp35m-win32.whl", hash = "sha256:eda55e6e9ea258f5e4add23bcf33dc53b2c319e70806e180aecbff8d90ea24de"},
- {file = "coverage-5.0.4-cp35-cp35m-win_amd64.whl", hash = "sha256:4a8a259bf990044351baf69d3b23e575699dd60b18460c71e81dc565f5819ac1"},
- {file = "coverage-5.0.4-cp36-cp36m-macosx_10_13_x86_64.whl", hash = "sha256:f372cdbb240e09ee855735b9d85e7f50730dcfb6296b74b95a3e5dea0615c4c1"},
- {file = "coverage-5.0.4-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:a37c6233b28e5bc340054cf6170e7090a4e85069513320275a4dc929144dccf0"},
- {file = "coverage-5.0.4-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:443be7602c790960b9514567917af538cac7807a7c0c0727c4d2bbd4014920fd"},
- {file = "coverage-5.0.4-cp36-cp36m-win32.whl", hash = "sha256:165a48268bfb5a77e2d9dbb80de7ea917332a79c7adb747bd005b3a07ff8caf0"},
- {file = "coverage-5.0.4-cp36-cp36m-win_amd64.whl", hash = "sha256:0a907199566269e1cfa304325cc3b45c72ae341fbb3253ddde19fa820ded7a8b"},
- {file = "coverage-5.0.4-cp37-cp37m-macosx_10_13_x86_64.whl", hash = "sha256:513e6526e0082c59a984448f4104c9bf346c2da9961779ede1fc458e8e8a1f78"},
- {file = "coverage-5.0.4-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:3844c3dab800ca8536f75ae89f3cf566848a3eb2af4d9f7b1103b4f4f7a5dad6"},
- {file = "coverage-5.0.4-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:641e329e7f2c01531c45c687efcec8aeca2a78a4ff26d49184dce3d53fc35014"},
- {file = "coverage-5.0.4-cp37-cp37m-win32.whl", hash = "sha256:db1d4e38c9b15be1521722e946ee24f6db95b189d1447fa9ff18dd16ba89f732"},
- {file = "coverage-5.0.4-cp37-cp37m-win_amd64.whl", hash = "sha256:62061e87071497951155cbccee487980524d7abea647a1b2a6eb6b9647df9006"},
- {file = "coverage-5.0.4-cp38-cp38-macosx_10_13_x86_64.whl", hash = "sha256:65a7e00c00472cd0f59ae09d2fb8a8aaae7f4a0cf54b2b74f3138d9f9ceb9cb2"},
- {file = "coverage-5.0.4-cp38-cp38-manylinux1_i686.whl", hash = "sha256:1f66cf263ec77af5b8fe14ef14c5e46e2eb4a795ac495ad7c03adc72ae43fafe"},
- {file = "coverage-5.0.4-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:85596aa5d9aac1bf39fe39d9fa1051b0f00823982a1de5766e35d495b4a36ca9"},
- {file = "coverage-5.0.4-cp38-cp38-win32.whl", hash = "sha256:86a0ea78fd851b313b2e712266f663e13b6bc78c2fb260b079e8b67d970474b1"},
- {file = "coverage-5.0.4-cp38-cp38-win_amd64.whl", hash = "sha256:03f630aba2b9b0d69871c2e8d23a69b7fe94a1e2f5f10df5049c0df99db639a0"},
- {file = "coverage-5.0.4-cp39-cp39-win32.whl", hash = "sha256:7c9762f80a25d8d0e4ab3cb1af5d9dffbddb3ee5d21c43e3474c84bf5ff941f7"},
- {file = "coverage-5.0.4-cp39-cp39-win_amd64.whl", hash = "sha256:4482f69e0701139d0f2c44f3c395d1d1d37abd81bfafbf9b6efbe2542679d892"},
- {file = "coverage-5.0.4.tar.gz", hash = "sha256:1b60a95fc995649464e0cd48cecc8288bac5f4198f21d04b8229dc4097d76823"},
+ {file = "coverage-5.2.1-cp27-cp27m-macosx_10_13_intel.whl", hash = "sha256:40f70f81be4d34f8d491e55936904db5c527b0711b2a46513641a5729783c2e4"},
+ {file = "coverage-5.2.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:675192fca634f0df69af3493a48224f211f8db4e84452b08d5fcebb9167adb01"},
+ {file = "coverage-5.2.1-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:2fcc8b58953d74d199a1a4d633df8146f0ac36c4e720b4a1997e9b6327af43a8"},
+ {file = "coverage-5.2.1-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:64c4f340338c68c463f1b56e3f2f0423f7b17ba6c3febae80b81f0e093077f59"},
+ {file = "coverage-5.2.1-cp27-cp27m-win32.whl", hash = "sha256:52f185ffd3291196dc1aae506b42e178a592b0b60a8610b108e6ad892cfc1bb3"},
+ {file = "coverage-5.2.1-cp27-cp27m-win_amd64.whl", hash = "sha256:30bc103587e0d3df9e52cd9da1dd915265a22fad0b72afe54daf840c984b564f"},
+ {file = "coverage-5.2.1-cp27-cp27mu-manylinux1_i686.whl", hash = "sha256:9ea749fd447ce7fb1ac71f7616371f04054d969d412d37611716721931e36efd"},
+ {file = "coverage-5.2.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:ce7866f29d3025b5b34c2e944e66ebef0d92e4a4f2463f7266daa03a1332a651"},
+ {file = "coverage-5.2.1-cp35-cp35m-macosx_10_13_x86_64.whl", hash = "sha256:4869ab1c1ed33953bb2433ce7b894a28d724b7aa76c19b11e2878034a4e4680b"},
+ {file = "coverage-5.2.1-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:a3ee9c793ffefe2944d3a2bd928a0e436cd0ac2d9e3723152d6fd5398838ce7d"},
+ {file = "coverage-5.2.1-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:28f42dc5172ebdc32622a2c3f7ead1b836cdbf253569ae5673f499e35db0bac3"},
+ {file = "coverage-5.2.1-cp35-cp35m-win32.whl", hash = "sha256:e26c993bd4b220429d4ec8c1468eca445a4064a61c74ca08da7429af9bc53bb0"},
+ {file = "coverage-5.2.1-cp35-cp35m-win_amd64.whl", hash = "sha256:4186fc95c9febeab5681bc3248553d5ec8c2999b8424d4fc3a39c9cba5796962"},
+ {file = "coverage-5.2.1-cp36-cp36m-macosx_10_13_x86_64.whl", hash = "sha256:b360d8fd88d2bad01cb953d81fd2edd4be539df7bfec41e8753fe9f4456a5082"},
+ {file = "coverage-5.2.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:1adb6be0dcef0cf9434619d3b892772fdb48e793300f9d762e480e043bd8e716"},
+ {file = "coverage-5.2.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:098a703d913be6fbd146a8c50cc76513d726b022d170e5e98dc56d958fd592fb"},
+ {file = "coverage-5.2.1-cp36-cp36m-win32.whl", hash = "sha256:962c44070c281d86398aeb8f64e1bf37816a4dfc6f4c0f114756b14fc575621d"},
+ {file = "coverage-5.2.1-cp36-cp36m-win_amd64.whl", hash = "sha256:b1ed2bdb27b4c9fc87058a1cb751c4df8752002143ed393899edb82b131e0546"},
+ {file = "coverage-5.2.1-cp37-cp37m-macosx_10_13_x86_64.whl", hash = "sha256:c890728a93fffd0407d7d37c1e6083ff3f9f211c83b4316fae3778417eab9811"},
+ {file = "coverage-5.2.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:538f2fd5eb64366f37c97fdb3077d665fa946d2b6d95447622292f38407f9258"},
+ {file = "coverage-5.2.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:27ca5a2bc04d68f0776f2cdcb8bbd508bbe430a7bf9c02315cd05fb1d86d0034"},
+ {file = "coverage-5.2.1-cp37-cp37m-win32.whl", hash = "sha256:aab75d99f3f2874733946a7648ce87a50019eb90baef931698f96b76b6769a46"},
+ {file = "coverage-5.2.1-cp37-cp37m-win_amd64.whl", hash = "sha256:c2ff24df02a125b7b346c4c9078c8936da06964cc2d276292c357d64378158f8"},
+ {file = "coverage-5.2.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:304fbe451698373dc6653772c72c5d5e883a4aadaf20343592a7abb2e643dae0"},
+ {file = "coverage-5.2.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:c96472b8ca5dc135fb0aa62f79b033f02aa434fb03a8b190600a5ae4102df1fd"},
+ {file = "coverage-5.2.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:8505e614c983834239f865da2dd336dcf9d72776b951d5dfa5ac36b987726e1b"},
+ {file = "coverage-5.2.1-cp38-cp38-win32.whl", hash = "sha256:700997b77cfab016533b3e7dbc03b71d33ee4df1d79f2463a318ca0263fc29dd"},
+ {file = "coverage-5.2.1-cp38-cp38-win_amd64.whl", hash = "sha256:46794c815e56f1431c66d81943fa90721bb858375fb36e5903697d5eef88627d"},
+ {file = "coverage-5.2.1-cp39-cp39-macosx_10_13_x86_64.whl", hash = "sha256:16042dc7f8e632e0dcd5206a5095ebd18cb1d005f4c89694f7f8aafd96dd43a3"},
+ {file = "coverage-5.2.1-cp39-cp39-manylinux1_i686.whl", hash = "sha256:c1bbb628ed5192124889b51204de27c575b3ffc05a5a91307e7640eff1d48da4"},
+ {file = "coverage-5.2.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:4f6428b55d2916a69f8d6453e48a505c07b2245653b0aa9f0dee38785939f5e4"},
+ {file = "coverage-5.2.1-cp39-cp39-win32.whl", hash = "sha256:9e536783a5acee79a9b308be97d3952b662748c4037b6a24cbb339dc7ed8eb89"},
+ {file = "coverage-5.2.1-cp39-cp39-win_amd64.whl", hash = "sha256:b8f58c7db64d8f27078cbf2a4391af6aa4e4767cc08b37555c4ae064b8558d9b"},
+ {file = "coverage-5.2.1.tar.gz", hash = "sha256:a34cb28e0747ea15e82d13e14de606747e9e484fb28d63c999483f5d5188e89b"},
]
distlib = [
- {file = "distlib-0.3.0.zip", hash = "sha256:2e166e231a26b36d6dfe35a48c4464346620f8645ed0ace01ee31822b288de21"},
+ {file = "distlib-0.3.1-py2.py3-none-any.whl", hash = "sha256:8c09de2c67b3e7deef7184574fc060ab8a793e7adbb183d942c389c8b13c52fb"},
+ {file = "distlib-0.3.1.zip", hash = "sha256:edf6116872c863e1aa9d5bb7cb5e05a022c519a4594dc703843343a9ddd9bff1"},
]
docutils = [
{file = "docutils-0.16-py2.py3-none-any.whl", hash = "sha256:0c5b78adfbf7762415433f5515cd5c9e762339e23369dbe8000d84a4bf4ab3af"},
{file = "docutils-0.16.tar.gz", hash = "sha256:c2de3a60e9e7d07be26b7f2b00ca0309c207e06c100f9cc2a94931fc75a478fc"},
]
-entrypoints = [
- {file = "entrypoints-0.3-py2.py3-none-any.whl", hash = "sha256:589f874b313739ad35be6e0cd7efde2a4e9b6fea91edcc34e58ecbb8dbe56d19"},
- {file = "entrypoints-0.3.tar.gz", hash = "sha256:c70dd71abe5a8c85e55e12c19bd91ccfeec11a6e99044204511f9ed547d48451"},
-]
filelock = [
{file = "filelock-3.0.12-py3-none-any.whl", hash = "sha256:929b7d63ec5b7d6b71b0fa5ac14e030b3f70b75747cef1b10da9b879fef15836"},
{file = "filelock-3.0.12.tar.gz", hash = "sha256:18d82244ee114f543149c66a6e0c14e9c4f8a1044b5cdaadd0f82159d6a6ff59"},
]
flake8 = [
- {file = "flake8-3.7.9-py2.py3-none-any.whl", hash = "sha256:49356e766643ad15072a789a20915d3c91dc89fd313ccd71802303fd67e4deca"},
- {file = "flake8-3.7.9.tar.gz", hash = "sha256:45681a117ecc81e870cbf1262835ae4af5e7a8b08e40b944a8a6e6b895914cfb"},
+ {file = "flake8-3.8.3-py2.py3-none-any.whl", hash = "sha256:15e351d19611c887e482fb960eae4d44845013cc142d42896e9862f775d8cf5c"},
+ {file = "flake8-3.8.3.tar.gz", hash = "sha256:f04b9fcbac03b0a3e58c0ab3a0ecc462e023a9faf046d57794184028123aa208"},
]
identify = [
- {file = "identify-1.4.13-py2.py3-none-any.whl", hash = "sha256:a7577a1f55cee1d21953a5cf11a3c839ab87f5ef909a4cba6cf52ed72b4c6059"},
- {file = "identify-1.4.13.tar.gz", hash = "sha256:ab246293e6585a1c6361a505b68d5b501a0409310932b7de2c2ead667b564d89"},
+ {file = "identify-1.4.25-py2.py3-none-any.whl", hash = "sha256:ccd88716b890ecbe10920659450a635d2d25de499b9a638525a48b48261d989b"},
+ {file = "identify-1.4.25.tar.gz", hash = "sha256:110ed090fec6bce1aabe3c72d9258a9de82207adeaa5a05cd75c635880312f9a"},
]
idna = [
- {file = "idna-2.9-py2.py3-none-any.whl", hash = "sha256:a068a21ceac8a4d63dbfd964670474107f541babbd2250d61922f029858365fa"},
- {file = "idna-2.9.tar.gz", hash = "sha256:7588d1c14ae4c77d74036e8c22ff447b26d0fde8f007354fd48a7814db15b7cb"},
+ {file = "idna-2.10-py2.py3-none-any.whl", hash = "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"},
+ {file = "idna-2.10.tar.gz", hash = "sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6"},
]
imagesize = [
{file = "imagesize-1.2.0-py2.py3-none-any.whl", hash = "sha256:6965f19a6a2039c7d48bca7dba2473069ff854c36ae6f19d2cde309d998228a1"},
{file = "imagesize-1.2.0.tar.gz", hash = "sha256:b1f6b5a4eab1f73479a50fb79fcf729514a900c341d8503d62a62dbc4127a2b1"},
]
importlib-metadata = [
- {file = "importlib_metadata-1.6.0-py2.py3-none-any.whl", hash = "sha256:2a688cbaa90e0cc587f1df48bdc97a6eadccdcd9c35fb3f976a09e3b5016d90f"},
- {file = "importlib_metadata-1.6.0.tar.gz", hash = "sha256:34513a8a0c4962bc66d35b359558fd8a5e10cd472d37aec5f66858addef32c1e"},
+ {file = "importlib_metadata-1.7.0-py2.py3-none-any.whl", hash = "sha256:dc15b2969b4ce36305c51eebe62d418ac7791e9a157911d58bfb1f9ccd8e2070"},
+ {file = "importlib_metadata-1.7.0.tar.gz", hash = "sha256:90bb658cdbbf6d1735b6341ce708fc7024a3e14e99ffdc5783edea9f9b077f83"},
]
importlib-resources = [
- {file = "importlib_resources-1.4.0-py2.py3-none-any.whl", hash = "sha256:dd98ceeef3f5ad2ef4cc287b8586da4ebad15877f351e9688987ad663a0a29b8"},
- {file = "importlib_resources-1.4.0.tar.gz", hash = "sha256:4019b6a9082d8ada9def02bece4a76b131518866790d58fdda0b5f8c603b36c2"},
+ {file = "importlib_resources-3.0.0-py2.py3-none-any.whl", hash = "sha256:d028f66b66c0d5732dae86ba4276999855e162a749c92620a38c1d779ed138a7"},
+ {file = "importlib_resources-3.0.0.tar.gz", hash = "sha256:19f745a6eca188b490b1428c8d1d4a0d2368759f32370ea8fb89cad2ab1106c3"},
+]
+iniconfig = [
+ {file = "iniconfig-1.0.1-py3-none-any.whl", hash = "sha256:80cf40c597eb564e86346103f609d74efce0f6b4d4f30ec8ce9e2c26411ba437"},
+ {file = "iniconfig-1.0.1.tar.gz", hash = "sha256:e5f92f89355a67de0595932a6c6c02ab4afddc6fcdc0bfc5becd0d60884d3f69"},
]
isort = [
{file = "isort-4.3.21-py2.py3-none-any.whl", hash = "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd"},
{file = "isort-4.3.21.tar.gz", hash = "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1"},
]
jinja2 = [
- {file = "Jinja2-2.11.1-py2.py3-none-any.whl", hash = "sha256:b0eaf100007721b5c16c1fc1eecb87409464edc10469ddc9a22a27a99123be49"},
- {file = "Jinja2-2.11.1.tar.gz", hash = "sha256:93187ffbc7808079673ef52771baa950426fd664d3aad1d0fa3e95644360e250"},
+ {file = "Jinja2-2.11.2-py2.py3-none-any.whl", hash = "sha256:f0a4641d3cf955324a89c04f3d94663aa4d638abe8f733ecd3582848e1c37035"},
+ {file = "Jinja2-2.11.2.tar.gz", hash = "sha256:89aab215427ef59c34ad58735269eb58b1a5808103067f7bb9d5836c651b3bb0"},
]
markupsafe = [
{file = "MarkupSafe-1.1.1-cp27-cp27m-macosx_10_6_intel.whl", hash = "sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161"},
@@ -954,62 +1064,99 @@ mccabe = [
{file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"},
]
more-itertools = [
- {file = "more-itertools-8.2.0.tar.gz", hash = "sha256:b1ddb932186d8a6ac451e1d95844b382f55e12686d51ca0c68b6f61f2ab7a507"},
- {file = "more_itertools-8.2.0-py3-none-any.whl", hash = "sha256:5dd8bcf33e5f9513ffa06d5ad33d78f31e1931ac9a18f33d37e77a180d393a7c"},
-]
-nested-lookup = [
- {file = "nested-lookup-0.2.21.tar.gz", hash = "sha256:23789e328bd1d0b3f9db93cf51b7103a978dd0d8a834770d2c19b365e934ab96"},
+ {file = "more-itertools-8.4.0.tar.gz", hash = "sha256:68c70cc7167bdf5c7c9d8f6954a7837089c6a36bf565383919bb595efb8a17e5"},
+ {file = "more_itertools-8.4.0-py3-none-any.whl", hash = "sha256:b78134b2063dd214000685165d81c154522c3ee0a1c0d4d113c80361c234c5a2"},
+]
+mypy = [
+ {file = "mypy-0.782-cp35-cp35m-macosx_10_6_x86_64.whl", hash = "sha256:2c6cde8aa3426c1682d35190b59b71f661237d74b053822ea3d748e2c9578a7c"},
+ {file = "mypy-0.782-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:9c7a9a7ceb2871ba4bac1cf7217a7dd9ccd44c27c2950edbc6dc08530f32ad4e"},
+ {file = "mypy-0.782-cp35-cp35m-win_amd64.whl", hash = "sha256:c05b9e4fb1d8a41d41dec8786c94f3b95d3c5f528298d769eb8e73d293abc48d"},
+ {file = "mypy-0.782-cp36-cp36m-macosx_10_6_x86_64.whl", hash = "sha256:6731603dfe0ce4352c555c6284c6db0dc935b685e9ce2e4cf220abe1e14386fd"},
+ {file = "mypy-0.782-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:f05644db6779387ccdb468cc47a44b4356fc2ffa9287135d05b70a98dc83b89a"},
+ {file = "mypy-0.782-cp36-cp36m-win_amd64.whl", hash = "sha256:b7fbfabdbcc78c4f6fc4712544b9b0d6bf171069c6e0e3cb82440dd10ced3406"},
+ {file = "mypy-0.782-cp37-cp37m-macosx_10_6_x86_64.whl", hash = "sha256:3fdda71c067d3ddfb21da4b80e2686b71e9e5c72cca65fa216d207a358827f86"},
+ {file = "mypy-0.782-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:d7df6eddb6054d21ca4d3c6249cae5578cb4602951fd2b6ee2f5510ffb098707"},
+ {file = "mypy-0.782-cp37-cp37m-win_amd64.whl", hash = "sha256:a4a2cbcfc4cbf45cd126f531dedda8485671545b43107ded25ce952aac6fb308"},
+ {file = "mypy-0.782-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6bb93479caa6619d21d6e7160c552c1193f6952f0668cdda2f851156e85186fc"},
+ {file = "mypy-0.782-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:81c7908b94239c4010e16642c9102bfc958ab14e36048fa77d0be3289dda76ea"},
+ {file = "mypy-0.782-cp38-cp38-win_amd64.whl", hash = "sha256:5dd13ff1f2a97f94540fd37a49e5d255950ebcdf446fb597463a40d0df3fac8b"},
+ {file = "mypy-0.782-py3-none-any.whl", hash = "sha256:e0b61738ab504e656d1fe4ff0c0601387a5489ca122d55390ade31f9ca0e252d"},
+ {file = "mypy-0.782.tar.gz", hash = "sha256:eff7d4a85e9eea55afa34888dfeaccde99e7520b51f867ac28a48492c0b1130c"},
+]
+mypy-extensions = [
+ {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"},
+ {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"},
]
nodeenv = [
- {file = "nodeenv-1.3.5-py2.py3-none-any.whl", hash = "sha256:5b2438f2e42af54ca968dd1b374d14a1194848955187b0e5e4be1f73813a5212"},
+ {file = "nodeenv-1.4.0-py2.py3-none-any.whl", hash = "sha256:4b0b77afa3ba9b54f4b6396e60b0c83f59eaeb2d63dc3cc7a70f7f4af96c82bc"},
]
packaging = [
- {file = "packaging-20.3-py2.py3-none-any.whl", hash = "sha256:82f77b9bee21c1bafbf35a84905d604d5d1223801d639cf3ed140bd651c08752"},
- {file = "packaging-20.3.tar.gz", hash = "sha256:3c292b474fda1671ec57d46d739d072bfd495a4f51ad01a055121d81e952b7a3"},
+ {file = "packaging-20.4-py2.py3-none-any.whl", hash = "sha256:998416ba6962ae7fbd6596850b80e17859a5753ba17c32284f67bfff33784181"},
+ {file = "packaging-20.4.tar.gz", hash = "sha256:4357f74f47b9c12db93624a82154e9b120fa8293699949152b22065d556079f8"},
]
pathspec = [
- {file = "pathspec-0.7.0-py2.py3-none-any.whl", hash = "sha256:163b0632d4e31cef212976cf57b43d9fd6b0bac6e67c26015d611a647d5e7424"},
- {file = "pathspec-0.7.0.tar.gz", hash = "sha256:562aa70af2e0d434367d9790ad37aed893de47f1693e4201fd1d3dca15d19b96"},
+ {file = "pathspec-0.8.0-py2.py3-none-any.whl", hash = "sha256:7d91249d21749788d07a2d0f94147accd8f845507400749ea19c1ec9054a12b0"},
+ {file = "pathspec-0.8.0.tar.gz", hash = "sha256:da45173eb3a6f2a5a487efba21f050af2b41948be6ab52b6a1e3ff22bb8b7061"},
]
pluggy = [
{file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"},
{file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"},
]
+pockets = [
+ {file = "pockets-0.9.1-py2.py3-none-any.whl", hash = "sha256:68597934193c08a08eb2bf6a1d85593f627c22f9b065cc727a4f03f669d96d86"},
+ {file = "pockets-0.9.1.tar.gz", hash = "sha256:9320f1a3c6f7a9133fe3b571f283bcf3353cd70249025ae8d618e40e9f7e92b3"},
+]
pre-commit = [
{file = "pre_commit-1.21.0-py2.py3-none-any.whl", hash = "sha256:f92a359477f3252452ae2e8d3029de77aec59415c16ae4189bcfba40b757e029"},
{file = "pre_commit-1.21.0.tar.gz", hash = "sha256:8f48d8637bdae6fa70cc97db9c1dd5aa7c5c8bf71968932a380628c25978b850"},
]
+psutil = [
+ {file = "psutil-5.7.2-cp27-none-win32.whl", hash = "sha256:f2018461733b23f308c298653c8903d32aaad7873d25e1d228765e91ae42c3f2"},
+ {file = "psutil-5.7.2-cp27-none-win_amd64.whl", hash = "sha256:66c18ca7680a31bf16ee22b1d21b6397869dda8059dbdb57d9f27efa6615f195"},
+ {file = "psutil-5.7.2-cp35-cp35m-win32.whl", hash = "sha256:5e9d0f26d4194479a13d5f4b3798260c20cecf9ac9a461e718eb59ea520a360c"},
+ {file = "psutil-5.7.2-cp35-cp35m-win_amd64.whl", hash = "sha256:4080869ed93cce662905b029a1770fe89c98787e543fa7347f075ade761b19d6"},
+ {file = "psutil-5.7.2-cp36-cp36m-win32.whl", hash = "sha256:d8a82162f23c53b8525cf5f14a355f5d1eea86fa8edde27287dd3a98399e4fdf"},
+ {file = "psutil-5.7.2-cp36-cp36m-win_amd64.whl", hash = "sha256:0ee3c36428f160d2d8fce3c583a0353e848abb7de9732c50cf3356dd49ad63f8"},
+ {file = "psutil-5.7.2-cp37-cp37m-win32.whl", hash = "sha256:ff1977ba1a5f71f89166d5145c3da1cea89a0fdb044075a12c720ee9123ec818"},
+ {file = "psutil-5.7.2-cp37-cp37m-win_amd64.whl", hash = "sha256:a5b120bb3c0c71dfe27551f9da2f3209a8257a178ed6c628a819037a8df487f1"},
+ {file = "psutil-5.7.2-cp38-cp38-win32.whl", hash = "sha256:10512b46c95b02842c225f58fa00385c08fa00c68bac7da2d9a58ebe2c517498"},
+ {file = "psutil-5.7.2-cp38-cp38-win_amd64.whl", hash = "sha256:68d36986ded5dac7c2dcd42f2682af1db80d4bce3faa126a6145c1637e1b559f"},
+ {file = "psutil-5.7.2.tar.gz", hash = "sha256:90990af1c3c67195c44c9a889184f84f5b2320dce3ee3acbd054e3ba0b4a7beb"},
+]
py = [
- {file = "py-1.8.1-py2.py3-none-any.whl", hash = "sha256:c20fdd83a5dbc0af9efd622bee9a5564e278f6380fffcacc43ba6f43db2813b0"},
- {file = "py-1.8.1.tar.gz", hash = "sha256:5e27081401262157467ad6e7f851b7aa402c5852dbcb3dae06768434de5752aa"},
+ {file = "py-1.9.0-py2.py3-none-any.whl", hash = "sha256:366389d1db726cd2fcfc79732e75410e5fe4d31db13692115529d34069a043c2"},
+ {file = "py-1.9.0.tar.gz", hash = "sha256:9ca6883ce56b4e8da7e79ac18787889fa5206c79dcc67fb065376cd2fe03f342"},
]
pycodestyle = [
- {file = "pycodestyle-2.5.0-py2.py3-none-any.whl", hash = "sha256:95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe3f6fac3491ae56"},
- {file = "pycodestyle-2.5.0.tar.gz", hash = "sha256:e40a936c9a450ad81df37f549d676d127b1b66000a6c500caa2b085bc0ca976c"},
+ {file = "pycodestyle-2.6.0-py2.py3-none-any.whl", hash = "sha256:2295e7b2f6b5bd100585ebcb1f616591b652db8a741695b3d8f5d28bdc934367"},
+ {file = "pycodestyle-2.6.0.tar.gz", hash = "sha256:c58a7d2815e0e8d7972bf1803331fb0152f867bd89adf8a01dfd55085434192e"},
]
pyflakes = [
- {file = "pyflakes-2.1.1-py2.py3-none-any.whl", hash = "sha256:17dbeb2e3f4d772725c777fabc446d5634d1038f234e77343108ce445ea69ce0"},
- {file = "pyflakes-2.1.1.tar.gz", hash = "sha256:d976835886f8c5b31d47970ed689944a0262b5f3afa00a5a7b4dc81e5449f8a2"},
+ {file = "pyflakes-2.2.0-py2.py3-none-any.whl", hash = "sha256:0d94e0e05a19e57a99444b6ddcf9a6eb2e5c68d3ca1e98e90707af8152c90a92"},
+ {file = "pyflakes-2.2.0.tar.gz", hash = "sha256:35b2d75ee967ea93b55750aa9edbbf72813e06a66ba54438df2cfac9e3c27fc8"},
]
pygments = [
{file = "Pygments-2.6.1-py3-none-any.whl", hash = "sha256:ff7a40b4860b727ab48fad6360eb351cc1b33cbf9b15a0f689ca5353e9463324"},
{file = "Pygments-2.6.1.tar.gz", hash = "sha256:647344a061c249a3b74e230c739f434d7ea4d8b1d5f3721bc0f3558049b38f44"},
]
pyparsing = [
- {file = "pyparsing-2.4.6-py2.py3-none-any.whl", hash = "sha256:c342dccb5250c08d45fd6f8b4a559613ca603b57498511740e65cd11a2e7dcec"},
- {file = "pyparsing-2.4.6.tar.gz", hash = "sha256:4c830582a84fb022400b85429791bc551f1f4871c33f23e44f353119e92f969f"},
+ {file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"},
+ {file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"},
]
pytest = [
- {file = "pytest-5.4.1-py3-none-any.whl", hash = "sha256:0e5b30f5cb04e887b91b1ee519fa3d89049595f428c1db76e73bd7f17b09b172"},
- {file = "pytest-5.4.1.tar.gz", hash = "sha256:84dde37075b8805f3d1f392cc47e38a0e59518fb46a431cfdaf7cf1ce805f970"},
+ {file = "pytest-6.0.1-py3-none-any.whl", hash = "sha256:8b6007800c53fdacd5a5c192203f4e531eb2a1540ad9c752e052ec0f7143dbad"},
+ {file = "pytest-6.0.1.tar.gz", hash = "sha256:85228d75db9f45e06e57ef9bf4429267f81ac7c0d742cc9ed63d09886a9fe6f4"},
]
pytest-cov = [
- {file = "pytest-cov-2.8.1.tar.gz", hash = "sha256:cc6742d8bac45070217169f5f72ceee1e0e55b0221f54bcf24845972d3a47f2b"},
- {file = "pytest_cov-2.8.1-py2.py3-none-any.whl", hash = "sha256:cdbdef4f870408ebdbfeb44e63e07eb18bb4619fae852f6e760645fa36172626"},
+ {file = "pytest-cov-2.10.0.tar.gz", hash = "sha256:1a629dc9f48e53512fcbfda6b07de490c374b0c83c55ff7a1720b3fccff0ac87"},
+ {file = "pytest_cov-2.10.0-py2.py3-none-any.whl", hash = "sha256:6e6d18092dce6fad667cd7020deed816f858ad3b49d5b5e2b1cc1c97a4dba65c"},
+]
+pytest-sugar = [
+ {file = "pytest-sugar-0.9.4.tar.gz", hash = "sha256:b1b2186b0a72aada6859bea2a5764145e3aaa2c1cfbb23c3a19b5f7b697563d3"},
]
pytz = [
- {file = "pytz-2019.3-py2.py3-none-any.whl", hash = "sha256:1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d"},
- {file = "pytz-2019.3.tar.gz", hash = "sha256:b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be"},
+ {file = "pytz-2020.1-py2.py3-none-any.whl", hash = "sha256:a494d53b6d39c3c6e44c3bec237336e14305e4f29bbf800b599253057fbb79ed"},
+ {file = "pytz-2020.1.tar.gz", hash = "sha256:c35965d010ce31b23eeb663ed3cc8c906275d6be1a34393a1d73a41febf4a048"},
]
pyyaml = [
{file = "PyYAML-5.3.1-cp27-cp27m-win32.whl", hash = "sha256:74809a57b329d6cc0fdccee6318f44b9b8649961fa73144a98735b0aaf029f1f"},
@@ -1025,39 +1172,64 @@ pyyaml = [
{file = "PyYAML-5.3.1.tar.gz", hash = "sha256:b8eac752c5e14d3eca0e6dd9199cd627518cb5ec06add0de9d32baeee6fe645d"},
]
regex = [
- {file = "regex-2020.2.20-cp27-cp27m-win32.whl", hash = "sha256:99272d6b6a68c7ae4391908fc15f6b8c9a6c345a46b632d7fdb7ef6c883a2bbb"},
- {file = "regex-2020.2.20-cp27-cp27m-win_amd64.whl", hash = "sha256:974535648f31c2b712a6b2595969f8ab370834080e00ab24e5dbb9d19b8bfb74"},
- {file = "regex-2020.2.20-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:5de40649d4f88a15c9489ed37f88f053c15400257eeb18425ac7ed0a4e119400"},
- {file = "regex-2020.2.20-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:82469a0c1330a4beb3d42568f82dffa32226ced006e0b063719468dcd40ffdf0"},
- {file = "regex-2020.2.20-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:d58a4fa7910102500722defbde6e2816b0372a4fcc85c7e239323767c74f5cbc"},
- {file = "regex-2020.2.20-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:f1ac2dc65105a53c1c2d72b1d3e98c2464a133b4067a51a3d2477b28449709a0"},
- {file = "regex-2020.2.20-cp36-cp36m-win32.whl", hash = "sha256:8c2b7fa4d72781577ac45ab658da44c7518e6d96e2a50d04ecb0fd8f28b21d69"},
- {file = "regex-2020.2.20-cp36-cp36m-win_amd64.whl", hash = "sha256:269f0c5ff23639316b29f31df199f401e4cb87529eafff0c76828071635d417b"},
- {file = "regex-2020.2.20-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:bed7986547ce54d230fd8721aba6fd19459cdc6d315497b98686d0416efaff4e"},
- {file = "regex-2020.2.20-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:046e83a8b160aff37e7034139a336b660b01dbfe58706f9d73f5cdc6b3460242"},
- {file = "regex-2020.2.20-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:b33ebcd0222c1d77e61dbcd04a9fd139359bded86803063d3d2d197b796c63ce"},
- {file = "regex-2020.2.20-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:bba52d72e16a554d1894a0cc74041da50eea99a8483e591a9edf1025a66843ab"},
- {file = "regex-2020.2.20-cp37-cp37m-win32.whl", hash = "sha256:01b2d70cbaed11f72e57c1cfbaca71b02e3b98f739ce33f5f26f71859ad90431"},
- {file = "regex-2020.2.20-cp37-cp37m-win_amd64.whl", hash = "sha256:113309e819634f499d0006f6200700c8209a2a8bf6bd1bdc863a4d9d6776a5d1"},
- {file = "regex-2020.2.20-cp38-cp38-manylinux1_i686.whl", hash = "sha256:25f4ce26b68425b80a233ce7b6218743c71cf7297dbe02feab1d711a2bf90045"},
- {file = "regex-2020.2.20-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:9b64a4cc825ec4df262050c17e18f60252cdd94742b4ba1286bcfe481f1c0f26"},
- {file = "regex-2020.2.20-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:9ff16d994309b26a1cdf666a6309c1ef51ad4f72f99d3392bcd7b7139577a1f2"},
- {file = "regex-2020.2.20-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:c7f58a0e0e13fb44623b65b01052dae8e820ed9b8b654bb6296bc9c41f571b70"},
- {file = "regex-2020.2.20-cp38-cp38-win32.whl", hash = "sha256:200539b5124bc4721247a823a47d116a7a23e62cc6695744e3eb5454a8888e6d"},
- {file = "regex-2020.2.20-cp38-cp38-win_amd64.whl", hash = "sha256:7f78f963e62a61e294adb6ff5db901b629ef78cb2a1cfce3cf4eeba80c1c67aa"},
- {file = "regex-2020.2.20.tar.gz", hash = "sha256:9e9624440d754733eddbcd4614378c18713d2d9d0dc647cf9c72f64e39671be5"},
+ {file = "regex-2020.7.14-cp27-cp27m-win32.whl", hash = "sha256:e46d13f38cfcbb79bfdb2964b0fe12561fe633caf964a77a5f8d4e45fe5d2ef7"},
+ {file = "regex-2020.7.14-cp27-cp27m-win_amd64.whl", hash = "sha256:6961548bba529cac7c07af2fd4d527c5b91bb8fe18995fed6044ac22b3d14644"},
+ {file = "regex-2020.7.14-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:c50a724d136ec10d920661f1442e4a8b010a4fe5aebd65e0c2241ea41dbe93dc"},
+ {file = "regex-2020.7.14-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:8a51f2c6d1f884e98846a0a9021ff6861bdb98457879f412fdc2b42d14494067"},
+ {file = "regex-2020.7.14-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:9c568495e35599625f7b999774e29e8d6b01a6fb684d77dee1f56d41b11b40cd"},
+ {file = "regex-2020.7.14-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:51178c738d559a2d1071ce0b0f56e57eb315bcf8f7d4cf127674b533e3101f88"},
+ {file = "regex-2020.7.14-cp36-cp36m-win32.whl", hash = "sha256:9eddaafb3c48e0900690c1727fba226c4804b8e6127ea409689c3bb492d06de4"},
+ {file = "regex-2020.7.14-cp36-cp36m-win_amd64.whl", hash = "sha256:14a53646369157baa0499513f96091eb70382eb50b2c82393d17d7ec81b7b85f"},
+ {file = "regex-2020.7.14-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:1269fef3167bb52631ad4fa7dd27bf635d5a0790b8e6222065d42e91bede4162"},
+ {file = "regex-2020.7.14-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:d0a5095d52b90ff38592bbdc2644f17c6d495762edf47d876049cfd2968fbccf"},
+ {file = "regex-2020.7.14-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:4c037fd14c5f4e308b8370b447b469ca10e69427966527edcab07f52d88388f7"},
+ {file = "regex-2020.7.14-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:bc3d98f621898b4a9bc7fecc00513eec8f40b5b83913d74ccb445f037d58cd89"},
+ {file = "regex-2020.7.14-cp37-cp37m-win32.whl", hash = "sha256:46bac5ca10fb748d6c55843a931855e2727a7a22584f302dd9bb1506e69f83f6"},
+ {file = "regex-2020.7.14-cp37-cp37m-win_amd64.whl", hash = "sha256:0dc64ee3f33cd7899f79a8d788abfbec168410be356ed9bd30bbd3f0a23a7204"},
+ {file = "regex-2020.7.14-cp38-cp38-manylinux1_i686.whl", hash = "sha256:5ea81ea3dbd6767873c611687141ec7b06ed8bab43f68fad5b7be184a920dc99"},
+ {file = "regex-2020.7.14-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:bbb332d45b32df41200380fff14712cb6093b61bd142272a10b16778c418e98e"},
+ {file = "regex-2020.7.14-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:c11d6033115dc4887c456565303f540c44197f4fc1a2bfb192224a301534888e"},
+ {file = "regex-2020.7.14-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:75aaa27aa521a182824d89e5ab0a1d16ca207318a6b65042b046053cfc8ed07a"},
+ {file = "regex-2020.7.14-cp38-cp38-win32.whl", hash = "sha256:d6cff2276e502b86a25fd10c2a96973fdb45c7a977dca2138d661417f3728341"},
+ {file = "regex-2020.7.14-cp38-cp38-win_amd64.whl", hash = "sha256:7a2dd66d2d4df34fa82c9dc85657c5e019b87932019947faece7983f2089a840"},
+ {file = "regex-2020.7.14.tar.gz", hash = "sha256:3a3af27a8d23143c49a3420efe5b3f8cf1a48c6fc8bc6856b03f638abc1833bb"},
]
requests = [
- {file = "requests-2.23.0-py2.py3-none-any.whl", hash = "sha256:43999036bfa82904b6af1d99e4882b560e5e2c68e5c4b0aa03b655f3d7d73fee"},
- {file = "requests-2.23.0.tar.gz", hash = "sha256:b3f43d496c6daba4493e7c431722aeb7dbc6288f52a6e04e7b6023b0247817e6"},
+ {file = "requests-2.24.0-py2.py3-none-any.whl", hash = "sha256:fe75cc94a9443b9246fc7049224f75604b113c36acb93f87b80ed42c44cbb898"},
+ {file = "requests-2.24.0.tar.gz", hash = "sha256:b3559a131db72c33ee969480840fff4bb6dd111de7dd27c8ee1f820f4f00231b"},
+]
+"ruamel.yaml" = [
+ {file = "ruamel.yaml-0.16.10-py2.py3-none-any.whl", hash = "sha256:0962fd7999e064c4865f96fb1e23079075f4a2a14849bcdc5cdba53a24f9759b"},
+ {file = "ruamel.yaml-0.16.10.tar.gz", hash = "sha256:099c644a778bf72ffa00524f78dd0b6476bca94a1da344130f4bf3381ce5b954"},
+]
+"ruamel.yaml.clib" = [
+ {file = "ruamel.yaml.clib-0.2.0-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:9c6d040d0396c28d3eaaa6cb20152cb3b2f15adf35a0304f4f40a3cf9f1d2448"},
+ {file = "ruamel.yaml.clib-0.2.0-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:4d55386129291b96483edcb93b381470f7cd69f97585829b048a3d758d31210a"},
+ {file = "ruamel.yaml.clib-0.2.0-cp27-cp27m-win32.whl", hash = "sha256:8073c8b92b06b572e4057b583c3d01674ceaf32167801fe545a087d7a1e8bf52"},
+ {file = "ruamel.yaml.clib-0.2.0-cp27-cp27m-win_amd64.whl", hash = "sha256:615b0396a7fad02d1f9a0dcf9f01202bf9caefee6265198f252c865f4227fcc6"},
+ {file = "ruamel.yaml.clib-0.2.0-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:a0ff786d2a7dbe55f9544b3f6ebbcc495d7e730df92a08434604f6f470b899c5"},
+ {file = "ruamel.yaml.clib-0.2.0-cp35-cp35m-macosx_10_6_intel.whl", hash = "sha256:ea4362548ee0cbc266949d8a441238d9ad3600ca9910c3fe4e82ee3a50706973"},
+ {file = "ruamel.yaml.clib-0.2.0-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:77556a7aa190be9a2bd83b7ee075d3df5f3c5016d395613671487e79b082d784"},
+ {file = "ruamel.yaml.clib-0.2.0-cp35-cp35m-win32.whl", hash = "sha256:392b7c371312abf27fb549ec2d5e0092f7ef6e6c9f767bfb13e83cb903aca0fd"},
+ {file = "ruamel.yaml.clib-0.2.0-cp35-cp35m-win_amd64.whl", hash = "sha256:ed5b3698a2bb241b7f5cbbe277eaa7fe48b07a58784fba4f75224fd066d253ad"},
+ {file = "ruamel.yaml.clib-0.2.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:7aee724e1ff424757b5bd8f6c5bbdb033a570b2b4683b17ace4dbe61a99a657b"},
+ {file = "ruamel.yaml.clib-0.2.0-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:d0d3ac228c9bbab08134b4004d748cf9f8743504875b3603b3afbb97e3472947"},
+ {file = "ruamel.yaml.clib-0.2.0-cp36-cp36m-win32.whl", hash = "sha256:f9dcc1ae73f36e8059589b601e8e4776b9976effd76c21ad6a855a74318efd6e"},
+ {file = "ruamel.yaml.clib-0.2.0-cp36-cp36m-win_amd64.whl", hash = "sha256:1e77424825caba5553bbade750cec2277ef130647d685c2b38f68bc03453bac6"},
+ {file = "ruamel.yaml.clib-0.2.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:d10e9dd744cf85c219bf747c75194b624cc7a94f0c80ead624b06bfa9f61d3bc"},
+ {file = "ruamel.yaml.clib-0.2.0-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:550168c02d8de52ee58c3d8a8193d5a8a9491a5e7b2462d27ac5bf63717574c9"},
+ {file = "ruamel.yaml.clib-0.2.0-cp37-cp37m-win32.whl", hash = "sha256:57933a6986a3036257ad7bf283529e7c19c2810ff24c86f4a0cfeb49d2099919"},
+ {file = "ruamel.yaml.clib-0.2.0-cp37-cp37m-win_amd64.whl", hash = "sha256:b1b7fcee6aedcdc7e62c3a73f238b3d080c7ba6650cd808bce8d7761ec484070"},
+ {file = "ruamel.yaml.clib-0.2.0-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:be018933c2f4ee7de55e7bd7d0d801b3dfb09d21dad0cce8a97995fd3e44be30"},
+ {file = "ruamel.yaml.clib-0.2.0.tar.gz", hash = "sha256:b66832ea8077d9b3f6e311c4a53d06273db5dc2db6e8a908550f3c14d67e718c"},
]
seed-isort-config = [
- {file = "seed_isort_config-1.9.4-py2.py3-none-any.whl", hash = "sha256:81f7adf8dd0bc24e03d0f5eef87561e170757fc7a36050c01e4c29d150757783"},
- {file = "seed_isort_config-1.9.4.tar.gz", hash = "sha256:cecccb911b8d01ecdca16e17d083bf4cd78e928db4d7906125b0373b81f1c7ec"},
+ {file = "seed_isort_config-2.2.0-py2.py3-none-any.whl", hash = "sha256:8601fb715a5a4aac39256bbf73c2da6a81f964da9c9d9897ab9074db3663526f"},
+ {file = "seed_isort_config-2.2.0.tar.gz", hash = "sha256:be4cfef8f9a3fe8ea1817069c6b624538ac0b429636ec746edeb27e98ed628c8"},
]
six = [
- {file = "six-1.14.0-py2.py3-none-any.whl", hash = "sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c"},
- {file = "six-1.14.0.tar.gz", hash = "sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a"},
+ {file = "six-1.15.0-py2.py3-none-any.whl", hash = "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"},
+ {file = "six-1.15.0.tar.gz", hash = "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259"},
]
snowballstemmer = [
{file = "snowballstemmer-2.0.0-py2.py3-none-any.whl", hash = "sha256:209f257d7533fdb3cb73bdbd24f436239ca3b2fa67d56f6ff88e86be08cc5ef0"},
@@ -1087,6 +1259,10 @@ sphinxcontrib-jsmath = [
{file = "sphinxcontrib-jsmath-1.0.1.tar.gz", hash = "sha256:a9925e4a4587247ed2191a22df5f6970656cb8ca2bd6284309578f2153e0c4b8"},
{file = "sphinxcontrib_jsmath-1.0.1-py2.py3-none-any.whl", hash = "sha256:2ec2eaebfb78f3f2078e73666b1415417a116cc848b72e5172e596c871103178"},
]
+sphinxcontrib-napoleon = [
+ {file = "sphinxcontrib-napoleon-0.7.tar.gz", hash = "sha256:407382beed396e9f2d7f3043fad6afda95719204a1e1a231ac865f40abcbfcf8"},
+ {file = "sphinxcontrib_napoleon-0.7-py2.py3-none-any.whl", hash = "sha256:711e41a3974bdf110a484aec4c1a556799eb0b3f3b897521a018ad7e2db13fef"},
+]
sphinxcontrib-qthelp = [
{file = "sphinxcontrib-qthelp-1.0.3.tar.gz", hash = "sha256:4c33767ee058b70dba89a6fc5c1892c0d57a54be67ddd3e7875a18d14cba5a72"},
{file = "sphinxcontrib_qthelp-1.0.3-py2.py3-none-any.whl", hash = "sha256:bd9fc24bcb748a8d51fd4ecaade681350aa63009a347a8c14e637895444dfab6"},
@@ -1096,13 +1272,19 @@ sphinxcontrib-serializinghtml = [
{file = "sphinxcontrib_serializinghtml-1.1.4-py2.py3-none-any.whl", hash = "sha256:f242a81d423f59617a8e5cf16f5d4d74e28ee9a66f9e5b637a18082991db5a9a"},
]
taskipy = [
- {file = "taskipy-1.2.1-py3-none-any.whl", hash = "sha256:99bdaf5b19791c2345806847147e0fc2d28e1ac9446058def5a8b6b3fc9f23e2"},
- {file = "taskipy-1.2.1.tar.gz", hash = "sha256:5eb2c3b1606c896c7fa799848e71e8883b880759224958d07ba760e5db263175"},
+ {file = "taskipy-1.3.0-py3-none-any.whl", hash = "sha256:f1c939009f464a93d87644011bcc36756be67478c1034921adeaeb34bfc0b5fd"},
+ {file = "taskipy-1.3.0.tar.gz", hash = "sha256:9775108e6efcc8a8883492a7427f1a596e4528b2bcf273fcef2b3ba756173160"},
+]
+termcolor = [
+ {file = "termcolor-1.1.0.tar.gz", hash = "sha256:1d6d69ce66211143803fbc56652b41d73b4a400a2891d7bf7a1cdf4c02de613b"},
]
toml = [
- {file = "toml-0.10.0-py2.7.egg", hash = "sha256:f1db651f9657708513243e61e6cc67d101a39bad662eaa9b5546f789338e07a3"},
- {file = "toml-0.10.0-py2.py3-none-any.whl", hash = "sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e"},
- {file = "toml-0.10.0.tar.gz", hash = "sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c"},
+ {file = "toml-0.10.1-py2.py3-none-any.whl", hash = "sha256:bda89d5935c2eac546d648028b9901107a595863cb36bae0c73ac804a9b4ce88"},
+ {file = "toml-0.10.1.tar.gz", hash = "sha256:926b612be1e5ce0634a2ca03470f95169cf16f939018233a670519cb4ac58b0f"},
+]
+tomlkit = [
+ {file = "tomlkit-0.6.0-py2.py3-none-any.whl", hash = "sha256:e5d5f20809c2b09276a6c5d98fb0202325aee441a651db84ac12e0812ab7e569"},
+ {file = "tomlkit-0.6.0.tar.gz", hash = "sha256:74f976908030ff164c0aa1edabe3bf83ea004b3daa5b0940b9c86a060c004e9a"},
]
typed-ast = [
{file = "typed_ast-1.4.1-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:73d785a950fc82dd2a25897d525d003f6378d1cb23ab305578394694202a58c3"},
@@ -1127,17 +1309,18 @@ typed-ast = [
{file = "typed_ast-1.4.1-cp39-cp39-macosx_10_15_x86_64.whl", hash = "sha256:d43943ef777f9a1c42bf4e552ba23ac77a6351de620aa9acf64ad54933ad4d34"},
{file = "typed_ast-1.4.1.tar.gz", hash = "sha256:8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1ba129eb293ec30b"},
]
+typing-extensions = [
+ {file = "typing_extensions-3.7.4.2-py2-none-any.whl", hash = "sha256:f8d2bd89d25bc39dabe7d23df520442fa1d8969b82544370e03d88b5a591c392"},
+ {file = "typing_extensions-3.7.4.2-py3-none-any.whl", hash = "sha256:6e95524d8a547a91e08f404ae485bbb71962de46967e1b71a0cb89af24e761c5"},
+ {file = "typing_extensions-3.7.4.2.tar.gz", hash = "sha256:79ee589a3caca649a9bfd2a8de4709837400dfa00b6cc81962a1e6a1815969ae"},
+]
urllib3 = [
- {file = "urllib3-1.25.8-py2.py3-none-any.whl", hash = "sha256:2f3db8b19923a873b3e5256dc9c2dedfa883e33d87c690d9c7913e1f40673cdc"},
- {file = "urllib3-1.25.8.tar.gz", hash = "sha256:87716c2d2a7121198ebcb7ce7cccf6ce5e9ba539041cfbaeecfb641dc0bf6acc"},
+ {file = "urllib3-1.25.10-py2.py3-none-any.whl", hash = "sha256:e7983572181f5e1522d9c98453462384ee92a0be7fac5f1413a1e35c56cc0461"},
+ {file = "urllib3-1.25.10.tar.gz", hash = "sha256:91056c15fa70756691db97756772bb1eb9678fa585d9184f24534b100dc60f4a"},
]
virtualenv = [
- {file = "virtualenv-20.0.15-py2.py3-none-any.whl", hash = "sha256:4e399f48c6b71228bf79f5febd27e3bbb753d9d5905776a86667bc61ab628a25"},
- {file = "virtualenv-20.0.15.tar.gz", hash = "sha256:9e81279f4a9d16d1c0654a127c2c86e5bca2073585341691882c1e66e31ef8a5"},
-]
-wcwidth = [
- {file = "wcwidth-0.1.9-py2.py3-none-any.whl", hash = "sha256:cafe2186b3c009a04067022ce1dcd79cb38d8d65ee4f4791b8888d6599d1bbe1"},
- {file = "wcwidth-0.1.9.tar.gz", hash = "sha256:ee73862862a156bf77ff92b09034fc4825dd3af9cf81bc5b360668d425f3c5f1"},
+ {file = "virtualenv-20.0.30-py2.py3-none-any.whl", hash = "sha256:8cd7b2a4850b003a11be2fc213e206419efab41115cc14bca20e69654f2ac08e"},
+ {file = "virtualenv-20.0.30.tar.gz", hash = "sha256:7b54fd606a1b85f83de49ad8d80dbec08e983a2d2f96685045b262ebc7481ee5"},
]
zipp = [
{file = "zipp-3.1.0-py3-none-any.whl", hash = "sha256:aa36550ff0c0b7ef7fa639055d797116ee891440eac1a56f378e2d3179e0320b"},
diff --git a/pyproject.toml b/pyproject.toml
index 9cf335a..810e5c8 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -5,54 +5,70 @@ description = "Modify configuration files of various formats with the same simpl
authors = ["Eugene Triguba <eugenetriguba@gmail.com>"]
readme = "README.md"
repository = "https://github.com/eugenetriguba/config_file"
-keywords = ["configuration", "config file", "ini", "json", "toml", "yaml"]
+documentation = "https://config-file.readthedocs.io/"
+keywords = ["configuration", "ini", "json", "toml", "yaml"]
classifiers = [
- "Development Status :: 2 - Pre-Alpha",
+ "Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.6",
+ "Programming Language :: Python :: 3.7",
+ "Programming Language :: Python :: 3.8",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
]
+packages = [
+ { include = "config_file" },
+ { include = "tests", format = "sdist" }
+]
+
[tool.taskipy.tasks]
-test = "poetry run pytest -v --cov=config_file/ --cov-report term-missing tests/"
+test = "task test_cov -- --cov-report term-missing"
+test_cov = "task pytest -- --cov=config_file/"
+test_ci = "task test_cov -- --cov-report=xml"
+lint = "task lint_types && task lint_precommit"
+lint_types = "poetry run mypy config_file/ tests/"
+lint_precommit = "poetry run pre-commit run --all"
+pytest = "poetry run pytest tests/"
[tool.poetry.dependencies]
python = "^3.6"
-nested-lookup = "^0.2.19"
-toml = { version = "^0.10.0", optional = true }
-pyyaml = { version = "^5.3.1", optional = true }
+tomlkit = { version = "^0.6.0", optional = true }
+"ruamel.yaml" = { version = "^0.16.10", optional = true }
[tool.poetry.extras]
-toml = ["toml"]
-yaml = ["pyyaml"]
+toml = ["tomlkit"]
+yaml = ["ruamel.yaml"]
[tool.poetry.dev-dependencies]
pre-commit = "^1.20"
autoflake = "^1.3.1"
isort = "^4.3.21"
-seed-isort-config = "^1.9"
-pytest = "^5.4.1"
+seed-isort-config = { version = "^2.1.1", python = "^3.6.1" }
+pytest = "^6.0.0"
pytest-cov = "^2.8.1"
-sphinx = "^2.4.4"
-sphinx_rtd_theme = "^0.4.3"
+pytest-sugar = "^0.9.3"
taskipy = "^1.2.1"
bump2version = "^1.0.0"
flake8 = "^3.7.9"
black = "^19.10b0"
+sphinx = "^2.4.4"
+sphinx_rtd_theme = "^0.4.3"
+sphinxcontrib-napoleon = "^0.7"
+mypy = "^0.782"
[tool.black]
line-length = 88
-target_version = ['py38']
+target_version = ['py36']
include = '\.pyi?$'
[tool.isort]
line_length = 88
multi_line_output = 3
include_trailing_comma = true
-known_third_party = ["nested_lookup", "pytest"]
+known_third_party = ["pytest"]
known_first_party = ["config_file"]
[build-system]
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..3ec303e
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,68 @@
+from pathlib import Path
+from typing import Callable, Tuple, Type, Union
+
+import pytest
+
+from config_file import ConfigFile
+from config_file.abstract_parser import AbstractParser
+from config_file.config_file_path import ConfigFilePath
+
+
+@pytest.fixture
+def tmp_file(tmp_path) -> Callable[[str, str], Path]:
+ def func(file_name: str, file_contents: str) -> Path:
+ file = tmp_path / file_name
+ file.touch()
+ file.write_text(file_contents, encoding="utf-8")
+ return file
+
+ return func
+
+
+@pytest.fixture
+def template_file(tmp_file: Callable[[str, str], Path]) -> Callable[[str, str], Path]:
+ template_dir = Path(__file__).parent / "templates"
+
+ def func(file_type: str, template_name: str = "default") -> Path:
+ file_name = f"{template_name}.{file_type}"
+ template = template_dir / file_type / file_name
+
+ return tmp_file(file_name, template.read_text(encoding="utf-8"))
+
+ return func
+
+
+@pytest.fixture
+def template_original_file() -> Callable[[Path], Path]:
+ def func(template_path: Union[str, Path]):
+ if isinstance(template_path, str):
+ template_path = Path(template_path)
+
+ original_path = ConfigFilePath(template_path).original_path
+ original_path.touch()
+ original_path.write_text(template_path.read_text(encoding="utf-8"))
+
+ return original_path
+
+ return func
+
+
+@pytest.fixture
+def template_and_parser(
+ template_file: Callable[[str, str], Path]
+) -> Callable[[str, str], Tuple[Path, Type[AbstractParser]]]:
+ def func(
+ file_type: str, template_name: str = "default"
+ ) -> Tuple[Path, Type[AbstractParser]]:
+ test_file = template_file(file_type, template_name)
+ return test_file, ConfigFile(test_file)._ConfigFile__parser
+
+ return func
+
+
+@pytest.fixture
+def templated_parser(template_and_parser) -> Callable[[str, str], Type[AbstractParser]]:
+ def func(file_type: str, template_name: str = "default") -> Type[AbstractParser]:
+ return template_and_parser(file_type, template_name)[1]
+
+ return func
diff --git a/tests/templates/ini/all_strings.ini b/tests/templates/ini/all_strings.ini
new file mode 100644
index 0000000..9ac0ecf
--- /dev/null
+++ b/tests/templates/ini/all_strings.ini
@@ -0,0 +1,7 @@
+[header]
+list = []
+dict = {}
+num = 5
+bool = false
+float = 5.5
+
diff --git a/tests/templates/ini/default.ini b/tests/templates/ini/default.ini
new file mode 100644
index 0000000..4f711db
--- /dev/null
+++ b/tests/templates/ini/default.ini
@@ -0,0 +1,7 @@
+[header_one]
+number_key = 0
+
+[header_two]
+str_key = "string"
+list_key = [1, 2, 3]
+
diff --git a/tests/templates/ini/invalid.ini b/tests/templates/ini/invalid.ini
new file mode 100644
index 0000000..c2a81db
--- /dev/null
+++ b/tests/templates/ini/invalid.ini
@@ -0,0 +1,2 @@
+[[[[[]]]]]
+i am a key \ No newline at end of file
diff --git a/tests/templates/json/all_strings.json b/tests/templates/json/all_strings.json
new file mode 100644
index 0000000..18ada7b
--- /dev/null
+++ b/tests/templates/json/all_strings.json
@@ -0,0 +1,9 @@
+{
+ "header": {
+ "list": "[]",
+ "dict": "{}",
+ "num": "5",
+ "bool": "false",
+ "float": "5.5"
+ }
+} \ No newline at end of file
diff --git a/tests/templates/json/default.json b/tests/templates/json/default.json
new file mode 100644
index 0000000..83d9b1e
--- /dev/null
+++ b/tests/templates/json/default.json
@@ -0,0 +1,13 @@
+{
+ "header_one": {
+ "number_key": 0
+ },
+ "header_two": {
+ "str_key": "string",
+ "list_key": [
+ 1,
+ 2,
+ 3
+ ]
+ }
+} \ No newline at end of file
diff --git a/tests/templates/json/invalid.json b/tests/templates/json/invalid.json
new file mode 100644
index 0000000..8e12c39
--- /dev/null
+++ b/tests/templates/json/invalid.json
@@ -0,0 +1 @@
+{'test': } \ No newline at end of file
diff --git a/tests/templates/toml/all_strings.toml b/tests/templates/toml/all_strings.toml
new file mode 100644
index 0000000..8fda0d8
--- /dev/null
+++ b/tests/templates/toml/all_strings.toml
@@ -0,0 +1,6 @@
+[header]
+list = "[]"
+dict = "{}"
+num = "5"
+bool = "false"
+float = "5.5" \ No newline at end of file
diff --git a/tests/templates/toml/default.toml b/tests/templates/toml/default.toml
new file mode 100644
index 0000000..e0437cf
--- /dev/null
+++ b/tests/templates/toml/default.toml
@@ -0,0 +1,7 @@
+[header_one]
+number_key = 0
+
+[header_two]
+# preserves comments
+str_key = "string"
+list_key = [1, 2, 3]
diff --git a/tests/templates/toml/invalid.toml b/tests/templates/toml/invalid.toml
new file mode 100644
index 0000000..d1b18e3
--- /dev/null
+++ b/tests/templates/toml/invalid.toml
@@ -0,0 +1 @@
+[[[[[[notvalidtoml]]]]]] \ No newline at end of file
diff --git a/tests/templates/yaml/all_strings.yaml b/tests/templates/yaml/all_strings.yaml
new file mode 100644
index 0000000..1c94b37
--- /dev/null
+++ b/tests/templates/yaml/all_strings.yaml
@@ -0,0 +1,6 @@
+header:
+ list: "[]"
+ dict: "{}"
+ num: "5"
+ bool: "false"
+ float: "5.5" \ No newline at end of file
diff --git a/tests/templates/yaml/default.yaml b/tests/templates/yaml/default.yaml
new file mode 100644
index 0000000..8c7c63e
--- /dev/null
+++ b/tests/templates/yaml/default.yaml
@@ -0,0 +1,7 @@
+header_one:
+ number_key: 0
+
+header_two:
+ # preserves comments
+ list_key: [1, 2, 3]
+ str_key: string
diff --git a/tests/templates/yaml/invalid.yaml b/tests/templates/yaml/invalid.yaml
new file mode 100644
index 0000000..cf2a4ff
--- /dev/null
+++ b/tests/templates/yaml/invalid.yaml
@@ -0,0 +1,6 @@
+invalid-yaml:
+yar:
+i:
+am:
+invalid:
+boo \ No newline at end of file
diff --git a/tests/test_abstract_parser.py b/tests/test_abstract_parser.py
new file mode 100644
index 0000000..0012127
--- /dev/null
+++ b/tests/test_abstract_parser.py
@@ -0,0 +1,68 @@
+import pytest
+
+from config_file.abstract_parser import AbstractParser
+
+
+class ConcreteParser(AbstractParser):
+ """
+ ConcreteParser is a concrete implementation of the
+ AbstractParser that just calls the AbstractParser's
+ methods so we can ensure they raise a NotImplementedError.
+ """
+
+ def __init__(self, file_contents):
+ super().__init__(file_contents)
+
+ def get(self, key):
+ super().get(key)
+
+ def set(self, key, value):
+ super().set(key, value)
+
+ def delete(self, section_key):
+ super().delete(section_key)
+
+ def has(self, section_key: str, wild: bool = False):
+ super().has(section_key)
+
+ def stringify(self):
+ super().stringify()
+
+ def reset_internal_contents(self, file_contents: str) -> None:
+ super().reset_internal_contents(file_contents)
+
+
+def test_that_abstract_parser_can_not_be_instantiated():
+ """
+ config_file.abstract_parser.AbstractParser
+
+ Ensure the AbstractParser raises a TypeError when it is
+ instantiated.
+ """
+ with pytest.raises(TypeError):
+ AbstractParser("")
+
+
+@pytest.mark.parametrize(
+ "function, args",
+ [
+ (ConcreteParser("").get, ("",)),
+ (ConcreteParser("").set, ("", "")),
+ (ConcreteParser("").delete, ("",)),
+ (ConcreteParser("").stringify, None),
+ (ConcreteParser("").has, ("",)),
+ (ConcreteParser("").reset_internal_contents, ("",)),
+ ],
+)
+def test_that_abstract_parser_raises_not_implemented_errors(function, args):
+ """
+ config_file.abstract_parser.AbstractParser
+
+ Ensure the AbstractParser raises a NotImplementedError
+ for every method in it.
+ """
+ with pytest.raises(NotImplementedError):
+ if args is None:
+ function()
+ else:
+ function(*args)
diff --git a/tests/test_base_parser.py b/tests/test_base_parser.py
deleted file mode 100644
index 1127a61..0000000
--- a/tests/test_base_parser.py
+++ /dev/null
@@ -1,57 +0,0 @@
-import pytest
-
-from config_file.parsers.base_parser import BaseParser
-
-
-class ConcreteParser(BaseParser):
- def __init__(self, file_contents):
- super().__init__(file_contents)
-
- def get(self, key, parse_types=True):
- super().get(key, parse_types=parse_types)
-
- def set(self, key, value):
- super().set(key, value)
-
- def delete(self, section_key):
- super().delete(section_key)
-
- def has(self, section_key: str) -> bool:
- super().has(section_key)
-
- def stringify(self) -> str:
- super().stringify()
-
- def parse(self, file_contents: str, call_super=False):
- if call_super:
- super().parse(file_contents)
-
- return file_contents
-
-
-def test_that_base_parser_can_not_be_instantiated():
- with pytest.raises(TypeError):
- BaseParser("")
-
-
-@pytest.mark.parametrize(
- "function, args",
- [
- (ConcreteParser("").get, ""),
- (ConcreteParser("").set, ("", "")),
- (ConcreteParser("").delete, ""),
- (ConcreteParser("").stringify, None),
- (ConcreteParser("").has, ""),
- (ConcreteParser("").parse, "call super"),
- ],
-)
-def test_that_base_parser_raises_not_implemented_errors(function, args):
- with pytest.raises(NotImplementedError):
- if args is None:
- function()
- elif type(args) is tuple:
- function(*args)
- elif args == "call super":
- function(args, call_super=True)
- else:
- function(args)
diff --git a/tests/test_config_file.py b/tests/test_config_file.py
index f083538..e120de2 100644
--- a/tests/test_config_file.py
+++ b/tests/test_config_file.py
@@ -1,248 +1,360 @@
import json
from pathlib import Path
+from typing import Callable, Tuple
import pytest
+from config_file.abstract_parser import AbstractParser
from config_file.config_file import ConfigFile
-from config_file.parsers.base_parser import BaseParser
+from config_file.exceptions import ParsingError
+from config_file.ini_parser import IniParser
+SUPPORTED_FILE_TYPES = ["ini", "json", "yaml", "toml"]
-@pytest.mark.parametrize(
- "file_contents, file_name", [("[calendar]\nsunday_index = 0\n\n", "config.ini")]
-)
-def test_that_config_file_initializes_correctly(tmp_path, file_contents, file_name):
- temp = tmp_path / file_name
- temp.write_text(file_contents)
- config = ConfigFile(temp)
- assert config.path == str(temp)
- assert config.contents == temp.read_text()
- assert isinstance(config.parser, BaseParser)
+@pytest.fixture(params=SUPPORTED_FILE_TYPES)
+def template_and_config_file(
+ request, template_file
+) -> Callable[[str], Tuple[Path, ConfigFile]]:
+ """
+ Fixture that is a wrapper around the template_file
+ fixture. Using the function returned, we can retrieve
+ a temporary file that has the contents of the specified
+ template file as well as a ConfigFile with the template
+ already passed in.
+
+ This fixture will make the test function run once for every
+ supported file type, each with the corresponding template
+ in the different file type.
+ """
+
+ def func(template_name: str = "default"):
+ template = template_file(request.param, template_name)
+ return template, ConfigFile(template)
+
+ return func
+
+
+@pytest.fixture(params=SUPPORTED_FILE_TYPES)
+def templated_config_file(template_and_config_file) -> Callable[[str], ConfigFile]:
+ """
+ Wrapper around template_and_config_file for when we
+ only need the ConfigFile and not the template.
+ """
+
+ def func(template_name: str = "default"):
+ return template_and_config_file(template_name)[1]
+
+ return func
+
+
+def test_config_file_init_has_correct_path_and_parser(template_and_config_file):
+ """
+ config_file.config_file.ConfigFile.__init__
+
+ Ensure that an initialized ConfigFile has the
+ correct file path and has a parser that is a AbstractParser.
+ """
+ template_file, config = template_and_config_file()
+
+ assert config.path == template_file
+ assert isinstance(config._ConfigFile__parser, AbstractParser)
+
+
+@pytest.mark.parametrize("file_type", SUPPORTED_FILE_TYPES)
+def test_config_file_raises_error_on_malformed_file(template_file, file_type):
+ """
+ config_file.config_file.ConfigFile.__init__
+
+ Ensure that a ParsingError is raised on a malformed file.
+ """
+ with pytest.raises(ParsingError):
+ ConfigFile(template_file(file_type, template_name="invalid"))
+
+
+def test_config_file_expands_home_tildes_in_path():
+ """
+ config_file.config_file.ConfigFile.__init__
+
+ Ensure that a home tilde (~) in a file path passed
+ to ConfigFile is expanded to the full path.
+ """
+ config_name = "temp.ini"
+ config_path = "~/" + config_name
+
+ try:
+ Path(config_path).expanduser().touch()
+ assert ConfigFile(config_path).path == Path.home() / config_name
+ finally:
+ Path(config_path).expanduser().unlink()
+
+
+@pytest.mark.parametrize("path", ["invalid", "invalid.conf"])
+def test_config_file_raises_error_on_non_existent_path(path):
+ """
+ config_file.config_file.ConfigFile.__init__
+
+ Ensure that when a path to a file that does not exist
+ that is passed into the constructor, it raises a FileNotFoundError.
+ """
+ with pytest.raises(FileNotFoundError):
+ ConfigFile(path)
+
+
+def test_config_file_raises_error_if_path_is_directory():
+ """
+ config_file.config_file.ConfigFile.__init__
+
+ Ensure when a path to a directory is passed into
+ the constructor, it raises a ValueError.
+ """
+ with pytest.raises(ValueError):
+ ConfigFile(".")
@pytest.mark.parametrize(
- "file_contents, file_name, original_file_name",
- [("[calendar]\nsunday_index = 0\n\n", "config.ini", "config.original.ini")],
+ "key, value", [("header_one.list_key", "different value"), ("header_one", {})],
)
-def test_that_config_file_can_restore_the_original(
- tmpdir, file_contents, file_name, original_file_name
+def test_set_can_add_to_or_alter_the_file(templated_config_file, key, value):
+ config = templated_config_file()
+ config.set(key, value)
+
+ assert config.get(key) == value
+
+
+def test_config_file_can_save(template_and_config_file):
+ """
+ config_file.config_file.ConfigFile.save
+
+ Ensure that altering the configuration file and saving it
+ writes those changes out to the filesystem.
+ """
+ template_file, config = template_and_config_file()
+
+ config.set("header_one.number_key", 25)
+ config.save()
+
+ assert config.stringify() == template_file.read_text()
+
+
+def test_restore_original_can_restore_with_calculated_in_path(
+ templated_config_file, template_original_file
):
- config_path = tmpdir / file_name
- config_path.write_text(file_contents, encoding="utf-8")
+ """
+ config_file.config_file.ConfigFile.restore_original
- original_config_path = tmpdir / original_file_name
- original_config_path.write_text(file_contents, encoding="utf-8")
+ Ensure that we can restore the "original" configuration
+ file, using the *calculated* path, after altering the
+ internal config contents.
- config = ConfigFile(str(config_path))
- config.set("calendar.sunday_index", 0)
+ Those internal contents and file should be reset to the
+ original file.
+ """
+ config = templated_config_file()
+ original_file = template_original_file(config.path)
+
+ config.set("header_one.number_key", 5)
config.restore_original()
- assert config.stringify() == ConfigFile(str(original_config_path)).stringify()
- assert config_path.read_text(encoding="utf-8") == original_config_path.read_text(
- encoding="utf-8"
- )
+ assert config.stringify() == original_file.read_text()
+ assert config.path.read_text() == original_file.read_text()
-@pytest.mark.parametrize(
- "file_extension, specify_original_config_path", [("ini", False), ("ini", True)]
-)
-def test_missing_config_files_during_restore(
- tmpdir, file_extension, specify_original_config_path
+
+@pytest.mark.parametrize("file_type", SUPPORTED_FILE_TYPES)
+def test_restore_original_can_restore_with_passed_in_path(
+ template_file, tmp_file, file_type
):
- with pytest.raises(OSError):
- temp_path = tmpdir / f"config.{file_extension}"
- temp_path.write("")
- config = ConfigFile(str(temp_path))
+ """
+ config_file.config_file.ConfigFile.restore_original
- if specify_original_config_path:
- specify_original_config_path = f"does_not_exist.{file_extension}"
- else:
- config.path = f"does_not_exist.{file_extension}"
- specify_original_config_path = None
+ Ensure that we can restore the "original" configuration
+ file, using the *passed* in path, after altering the
+ internal config contents.
+ """
+ config_file = template_file(file_type)
+ config = ConfigFile(config_file)
- config.restore_original(original_file_path=specify_original_config_path)
+ original_file = tmp_file(f"file.{file_type}", config_file.read_text())
+ original_config = ConfigFile(original_file)
+ original_config.set("some_new_section.some_new_key", 5)
+ original_config.save()
+ config.restore_original(original_path=original_file)
-@pytest.mark.parametrize(
- "file_contents, file_name", [("[calendar]\nsunday_index = 0\n\n", "config.ini")]
-)
-def test_that_config_file_can_save(tmpdir, file_contents, file_name):
- config_path = tmpdir / file_name
- config_path.write_text(file_contents, encoding="utf-8")
+ assert config.stringify() == original_config.stringify()
+ assert config.path.read_text() == original_file.read_text()
- config = ConfigFile(str(config_path))
- config.set("calendar.sunday_index", 1)
- config.save()
- assert config.stringify() == Path(config_path).read_text(encoding="utf-8")
+def test_restore_original_raises_error_on_missing_file(templated_config_file):
+ """
+ config_file.config_file.ConfigFile.restore_original
-@pytest.mark.parametrize(
- "section_key, value, parse_type, return_type, default, file_name, file_contents",
- [
- (
- "calendar.sunday_index",
- 0,
- True,
- None,
- False,
- "config.ini",
- "[calendar]\nsunday_index = 0\n\n",
- ),
- (
- "calendar.sunday_index",
- "0",
- False,
- None,
- False,
- "config.ini",
- "[calendar]\nsunday_index = 0\n\n",
- ),
- (
- "calendar.sunday_index",
- 0,
- False,
- None,
- False,
- "config.json",
- json.dumps({"calendar": {"sunday_index": 0}}),
- ),
- (
- "calendar.missing",
- "my default value",
- False,
- None,
- "my default value",
- "config.json",
- json.dumps({"calendar": 5}),
- ),
- (
- "calendar.sunday_index",
- 0,
- False,
- int,
- False,
- "config.ini",
- "[calendar]\nsunday_index = 0\n\n",
- ),
- ],
-)
-def test_that_config_file_can_get(
- tmpdir,
- section_key,
- value,
- return_type,
- parse_type,
- file_name,
- file_contents,
- default,
-):
- config_path = tmpdir / file_name
- config_path.write_text(file_contents, encoding="utf-8")
- config = ConfigFile(str(config_path))
+ Ensure that if we try to restore_original without using
+ the optional original_path argument but we do not
+ have a file at the calculated default path, a FileNotFoundError
+ is raised.
+ """
+ config = templated_config_file()
- ret_val = config.get(section_key, parse_types=parse_type, default=default)
- if return_type is not None:
- assert return_type(ret_val) == value
- else:
- assert ret_val == value
+ with pytest.raises(FileNotFoundError) as error:
+ config.restore_original()
+ assert "The specified config file" in str(error)
+ assert "does not exist" in str(error)
-@pytest.mark.parametrize(
- "file_extension, file_contents, section_key, expected_result",
- [
- ("ini", "[calendar]\nsunday_index = 0\n\n", "calendar.sunday_index", True),
- ("ini", "[calendar]\nsunday_index = 0\n\n", "calendar.blah", False),
- ("ini", "[calendar]\nsunday_index = 0\n\n", "calendar", True),
- ("json", json.dumps({"calendar": {"sunday_index": 0}}), "calendar", True),
- ("json", json.dumps({"calendar": {"sunday_index": 0}}), "blah", False),
- ("json", json.dumps({"calendar": {"sunday_index": 0}}), "sunday_index", True),
- ],
-)
-def test_that_config_file_can_find_sections_and_keys(
- tmpdir, file_extension, file_contents, section_key, expected_result
+
+@pytest.mark.parametrize("key", ["header_one", "header_one.number_key"])
+def test_has_can_find_sections_and_keys(templated_config_file, key):
+ """
+ config_file.config_file.ConfigFile.has
+
+ Ensure that when a section or key that exists
+ is passed to has(), it can find it and returns True.
+ """
+ config = templated_config_file()
+ assert config.has(key)
+
+
+def test_has_returns_false_for_sections_and_keys_that_do_not_exist(
+ templated_config_file,
):
- config_path = tmpdir / f"config.{file_extension}"
- config_path.write_text(file_contents, encoding="utf-8")
- config = ConfigFile(str(config_path))
- assert config.has(section_key) == expected_result
+ """
+ config_file.config_file.ConfigFile.has
+
+ Ensure that when a section or key that does not exist
+ is passed to has(), it can't find it and returns False.
+ """
+ config = templated_config_file()
+ assert not config.has("header_one.blah")
+
+
+def test_has_can_search_for_a_key_anywhere(templated_config_file):
+ config = templated_config_file()
+ assert config.has("list_key", wild=True)
@pytest.mark.parametrize(
- "section_key, file_name, file_contents, deleted_file_contents",
+ "key, value",
[
- (
- "calendar.sunday_index",
- "config.ini",
- "[calendar]\nsunday_index = 0\n\n",
- "[calendar]\n\n",
- ),
- (
- "calendar.sunday_index",
- "config.json",
- json.dumps({"calendar": {"sunday_index": 0}}),
- json.dumps({"calendar": {}}),
- ),
+ ("header_one.number_key", 0),
+ ("header_two.list_key", [1, 2, 3]),
+ ("header_one", {"number_key": 0}),
],
)
-def test_that_config_file_can_delete(
- tmpdir, section_key, file_name, file_contents, deleted_file_contents
+def test_get_can_retrieve_existent_keys(templated_config_file, key, value):
+ """
+ config_file.config_file.ConfigFile.get
+
+ Ensure that we can retrieve a section or key
+ and that it is in its native type (the type that
+ it was set to).
+
+ The one caveat here is the IniParser. The IniParser
+ uses configparser under the hood which simply always
+ returns back a string. However, that is not the case
+ for JsonParser, YamlParser, or TomlParser.
+ """
+ config = templated_config_file()
+
+ if isinstance(config._ConfigFile__parser, IniParser):
+ if type(value) is not dict:
+ # not a section being retrieved
+ value = str(value)
+ else:
+ # section is being retrieved so it should be a dict
+ # but the values inside should be strings.
+ value = json.loads(json.dumps(value), parse_int=str)
+
+ assert config.get(key) == value
+
+
+def test_get_can_parse_all_types(templated_config_file):
+ config = templated_config_file(template_name="all_strings")
+ output = {"list": [], "dict": {}, "num": 5, "bool": False, "float": 5.5}
+
+ assert config.get("header", parse_types=True) == output
+
+
+def test_get_can_use_a_default(templated_config_file):
+ config = templated_config_file()
+ assert config.get("does_not_exist", default="default!") == "default!"
+
+
+def test_get_raises_a_key_error_on_invalid_key(templated_config_file):
+ config = templated_config_file()
+
+ with pytest.raises(KeyError):
+ config.get("does_not_exist")
+
+
+@pytest.mark.parametrize("key", ["header_one.number_key", "header_one"])
+def test_delete_can_remove_sections_and_keys(templated_config_file, key):
+ """
+ config_file.config_file.ConfigFile.delete
+
+ Ensure that we can delete keys and that they are removed
+ from the internal contents of the ConfigFile.
+ """
+ config = templated_config_file()
+
+ config.delete(key)
+
+ assert config.has(key) is False
+
+
+@pytest.mark.parametrize("key", ["", 0, False, {}, "header_one.does_not_exist"])
+def test_delete_raises_key_error_on_invalid_input_or_missing_key(
+ templated_config_file, key
):
- config_path = tmpdir / file_name
- config_path.write_text(file_contents, encoding="utf-8")
- config = ConfigFile(str(config_path))
- config.delete(section_key)
- assert config.stringify() == deleted_file_contents
+ """
+ config_file.config_file.ConfigFile.delete
+ Ensure that a KeyError is raised if we
+ tried to provide a value that is not valid
+ (like the wrong type so it is an invalid key)
+ or one that does not exist.
+ """
+ config = templated_config_file()
-@pytest.mark.parametrize(
- "path, is_dir", [("invalid", False), ("invalid", True), ("invalid.conf", False)]
-)
-def test_invalid_config_paths(tmpdir, path, is_dir):
- with pytest.raises(ValueError):
- temp_path = tmpdir / path
- temp_path.write("")
- ConfigFile(str(tmpdir)) if is_dir else ConfigFile(str(temp_path))
+ with pytest.raises(KeyError):
+ config.delete(key)
-def test_that_custom_parser_can_be_used(tmpdir):
- class CustomParser(BaseParser):
- def __init__(self, file_contents):
- super().__init__(file_contents)
+def test_keys_can_be_set_with_array_notation(template_and_config_file):
+ """
+ config_file.config_file.ConfigFile.__setitem__
- def get(self, key, parse_types=True):
- return key
+ Ensure that the ConfigFile exposes its parsed contents
+ using an array notation so we can set keys that way.
+ """
+ template_file, config = template_and_config_file()
- def set(self, key, value):
- return key, value
+ config["header_one"] = {}
+ config.save()
- def delete(self, section_key):
- return section_key
+ assert config.stringify() == template_file.read_text()
- def has(self, section_key: str) -> bool:
- return True
- def stringify(self) -> str:
- return str(self.parsed_content)
+def test_keys_can_be_retrieved_with_array_notation(templated_config_file):
+ """
+ config_file.config_file.ConfigFile.__getitem__
- def parse(self, file_contents: str):
- return file_contents
+ Ensure that the ConfigFile exposes its parsed contents
+ using an array notation so we can retrieve keys that way.
+ """
+ config = templated_config_file()
+ assert int(config["header_one"]["number_key"]) == 0
- config_path = tmpdir / "config.conf"
- config_path.write_text("", encoding="utf-8")
- config = ConfigFile(str(config_path), parser=CustomParser)
- assert isinstance(config.parser, CustomParser)
- assert config.get("key") == "key"
- assert config.set("key", "value") == ("key", "value")
- assert config.delete("section_key") == "section_key"
- assert config.has("blah")
- assert config.stringify() == ""
+def test_keys_can_be_deleted_with_array_notation(templated_config_file):
+ """
+ config_file.config_file.ConfigFile.__delitem__
-def test_that_a_tidle_in_the_config_path_expands_to_the_absolute_path():
- config_name = "fjlajbkfdajfdioanfks.ini"
- config_path = "~/" + config_name
+ Ensure that the ConfigFile exposes its parsed contents
+ using an array notation so we can delete keys that way.
+ """
+ config = templated_config_file()
+ del config["header_one"]
- try:
- Path(config_path).expanduser().touch()
- assert ConfigFile(config_path).path == str(Path.home() / config_name)
- finally:
- Path(config_path).expanduser().unlink()
+ with pytest.raises(KeyError):
+ config["header_one"]
diff --git a/tests/test_config_file_path.py b/tests/test_config_file_path.py
new file mode 100644
index 0000000..3bb7215
--- /dev/null
+++ b/tests/test_config_file_path.py
@@ -0,0 +1,112 @@
+import os
+from pathlib import Path, _posix_flavour, _windows_flavour
+
+import pytest
+
+from config_file.config_file_path import ConfigFilePath
+from config_file.ini_parser import IniParser
+from config_file.json_parser import JsonParser
+from config_file.toml_parser import TomlParser
+from config_file.yaml_parser import YamlParser
+
+
+def test_config_file_path_is_a_path():
+ """
+ config_file.config_file_path.ConfigFilePath
+
+ Ensure that the ConfigFilePath object is an instance
+ of Path from pathlib.
+ """
+ assert isinstance(ConfigFilePath("."), Path)
+
+
+def test_config_file_path_has_the_correct_flavour():
+ """
+ config_file.config_file_path.ConfigFilePath
+
+ Ensure that the ConfigFilePath object has the
+ correct Path flavor (since Path is actually
+ swapped out, depending on the operating system,
+ to a Posix flavour or Windows flavour)
+ """
+ path = ConfigFilePath(".")
+
+ assert path._flavour == _windows_flavour if os.name == "nt" else _posix_flavour
+
+
+def test_config_file_path_is_able_to_read_the_contents(template_file):
+ """
+ config_file.config_file_path.ConfigFilePath
+
+ Ensure that the contents retrieved are the same
+ as the contents of the file.
+ """
+ template = template_file("ini", "default")
+ path = ConfigFilePath(template)
+
+ assert path.contents == template.read_text()
+
+
+def test_config_file_path_is_able_to_calculate_the_original_path():
+ """
+ config_file.config_file_path.ConfigFilePath
+
+ Ensure that the calculated original configuration
+ path includes a "original" between the filename and
+ extension.
+ """
+ path = ConfigFilePath("path-existing-does-not-matter.txt")
+
+ assert str(path.original_path) == "path-existing-does-not-matter.original.txt"
+
+
+def test_config_file_path_is_able_to_retrieve_the_extension():
+ """
+ config_file.config_file_path.ConfigFilePath
+
+ Ensure that the retrieved extension is correct
+ for the given filepath and that it does not retrieve
+ the dot (.) from the extension.
+ """
+ path = ConfigFilePath("some-file.txt")
+
+ assert path.extension == "txt"
+
+
+@pytest.mark.parametrize(
+ "template_file_type, expected_parser_type",
+ [
+ ("ini", IniParser),
+ ("json", JsonParser),
+ ("yaml", YamlParser),
+ ("toml", TomlParser),
+ ],
+)
+def test_config_file_path_decides_on_the_correct_parser(
+ template_file, template_file_type, expected_parser_type
+):
+ """
+ config_file.config_file_path.ConfigFilePath
+
+ Ensure that a filepath with an extension that is supported
+ retrieves the correct parser for it.
+ """
+ template = template_file(template_file_type, "default")
+ path = ConfigFilePath(template)
+
+ assert isinstance(path.parser, expected_parser_type)
+
+
+@pytest.mark.parametrize("filename", ["some-file", "some-file.unsupported-extension"])
+def test_config_file_path_raises_value_error_on_parser_if_invalid_extension(filename):
+ """
+ config_file.config_file_path.ConfigFilePath
+
+ Ensure that a ValueError is raised if we have a
+ filepath with no extension or a filepath with an
+ unsupported extension.
+ """
+ path = ConfigFilePath(filename)
+
+ with pytest.raises(ValueError):
+ path.parser
diff --git a/tests/test_ini_parser.py b/tests/test_ini_parser.py
deleted file mode 100644
index 7cdeea8..0000000
--- a/tests/test_ini_parser.py
+++ /dev/null
@@ -1,106 +0,0 @@
-import pytest
-
-from config_file.parsers.ini_parser import IniParser, ParsingError
-
-
-@pytest.mark.parametrize("ini_file", ["blahblahblah", "{ 'key1': 5 }"])
-def test_incorrect_ini_formats(ini_file):
- with pytest.raises(ParsingError):
- IniParser(ini_file)
-
-
-@pytest.mark.parametrize(
- "section_key,expected_value,parse_type",
- [
- ("test_section.intkey", 5, True),
- ("test_section.strkey", "blah", True),
- ("test_section.boolkey", False, True),
- ("test_section.floatkey", 5.3, True),
- ("test_section.intkey", "5", False),
- ("test_section.strkey", "blah", False),
- ("test_section.boolkey", "false", False),
- ("test_section.floatkey", "5.3", False),
- (
- "test_section",
- {"intkey": "5", "strkey": "blah", "boolkey": "false", "floatkey": "5.3"},
- False,
- ),
- (
- "test_section",
- {"intkey": 5, "strkey": "blah", "boolkey": False, "floatkey": 5.3},
- True,
- ),
- ],
-)
-def test_that_ini_parser_can_get_values(section_key, expected_value, parse_type):
- ini_file = """[test_section]
-intkey = 5
-strkey = blah
-boolkey = false
-floatkey = 5.3
-
-"""
- parser = IniParser(ini_file)
- assert parser.get(section_key, parse_types=parse_type) == expected_value
-
-
-@pytest.mark.parametrize(
- "test_input", ["invalid.invalid_key"],
-)
-def test_that_getting_unknown_sections_or_keys_throws_errors(test_input):
- with pytest.raises(ParsingError):
- IniParser("").get(test_input)
-
-
-@pytest.mark.parametrize(
- "section_key,value,expected_value",
- [
- ("test.key1", "different value", "[test]\nkey1 = different value\n\n"),
- ("test.key2", 5, "[test]\nkey1 = value1\nkey2 = 5\n\n"),
- ("test2.key", False, "[test]\nkey1 = value1\n\n[test2]\nkey = False\n\n"),
- ],
-)
-def test_that_ini_parser_can_set_values(section_key, value, expected_value):
- ini_file = """[test]\nkey1 = value1\n\n"""
- parser = IniParser(ini_file)
- parser.set(section_key, value)
- assert parser.stringify() == expected_value
-
-
-@pytest.mark.parametrize(
- "ini_file",
- ["[test]\nkey1 = value1\n\n", "[test]\nblah = 5\n\n[section2]\nkey = 2\n\n", ""],
-)
-def test_that_ini_parser_can_be_stringified(ini_file):
- parser = IniParser(ini_file)
- assert parser.stringify() == ini_file
-
-
-@pytest.mark.parametrize(
- "section_key,expected_result",
- [("test_section", ""), ("test_section.key1", "[test_section]\n\n")],
-)
-def test_that_ini_parser_can_delete(section_key, expected_result):
- ini_file = """[test_section]\nkey1 = value\n\n"""
- parser = IniParser(ini_file)
- parser.delete(section_key)
- assert parser.stringify() == expected_result
-
-
-@pytest.mark.parametrize(
- "section_key", ["section_is_not_present", "test_section.but_key_is_not_present"],
-)
-def test_that_ini_parser_delete_raises_value_errors(section_key):
- ini_file = """[test_section]\nkey1 = value\n\n"""
- parser = IniParser(ini_file)
- with pytest.raises(ValueError):
- parser.delete(section_key)
-
-
-@pytest.mark.parametrize(
- "section_key", ["test_section", "test_section.key1"],
-)
-def test_that_ini_parser_can_check_its_section_and_keys(section_key):
- ini_file = """[test_section]\nkey1 = value\n\n"""
- parser = IniParser(ini_file)
- assert parser.has(section_key)
diff --git a/tests/test_json_parser.py b/tests/test_json_parser.py
deleted file mode 100644
index a5e38a1..0000000
--- a/tests/test_json_parser.py
+++ /dev/null
@@ -1,198 +0,0 @@
-import json
-
-import pytest
-
-from config_file.parsers.json_parser import JsonParser, ParsingError
-
-
-@pytest.mark.parametrize("test_json", ["{'test': }", "[section]\nblah = value\n\n"])
-def test_invalid_json(test_json):
- with pytest.raises(ParsingError):
- JsonParser(test_json)
-
-
-def test_that_json_parser_can_stringify():
- json_str = '{"test": 5, "blah": true}'
- parser = JsonParser(json_str)
- assert parser.stringify() == json_str
-
-
-@pytest.mark.parametrize(
- "test_input,expected_result",
- [
- ("glossary", True),
- ("title", True),
- ("example glossary", False),
- ("GlossDiv", True),
- ("title", True),
- ("5", False),
- ("GlossList", True),
- ("GlossEntry", True),
- ("ID", True),
- ("false", False),
- ("GlossTerm", True),
- ("Standard Generalized Markup Language", False),
- ("Acronym", True),
- ("ISO 8879:1986", False),
- ("GlossDef", True),
- ("para", True),
- (
- "A meta-markup language, used to create markup languages "
- "such as DocBook.",
- False,
- ),
- ("GlossSeeAlso", True),
- ("GML", False),
- ("XML", False),
- ("GlossSee", True),
- ("5.5", False),
- ],
-)
-def test_that_json_parser_can_find_keys(test_input, expected_result):
- test_json = {
- "glossary": {
- "title": "example glossary",
- "GlossDiv": {
- "title": "5",
- "GlossList": {
- "GlossEntry": {
- "ID": "false",
- "SortAs": "SGML",
- "GlossTerm": "Standard Generalized Markup Language",
- "Acronym": "SGML",
- "Abbrev": "ISO 8879:1986",
- "GlossDef": {
- "para": "A meta-markup language, used to create markup "
- + "languages such as DocBook.",
- "GlossSeeAlso": ["GML", "XML"],
- },
- "GlossSee": "5.5",
- }
- },
- },
- }
- }
-
- parser = JsonParser(json.dumps(test_json))
- assert parser.has(test_input) == expected_result
-
-
-@pytest.mark.parametrize(
- "test_json, section_key, parse_type, expected_result",
- [
- (
- {"glossary": {"title": "example glossary"}},
- "glossary.title",
- False,
- "example glossary",
- ),
- (
- {"glossary": {"title": "example glossary"}},
- "glossary.title",
- True,
- "example glossary",
- ),
- (
- {"glossary": {"title": "example glossary", "dict": {"blah": "5"}}},
- "glossary.dict",
- False,
- {"blah": "5"},
- ),
- (
- {"glossary": {"title": "example glossary", "dict": {"blah": "5"}}},
- "glossary.dict",
- True,
- {"blah": 5},
- ),
- (
- {
- "glossary": {
- "title": "example glossary",
- "dict": {"blah": "5", "second": {"third": "5"}},
- }
- },
- "glossary.dict",
- True,
- {"blah": 5, "second": {"third": 5}},
- ),
- ],
-)
-def test_that_json_parser_can_get_keys(
- test_json, section_key, parse_type, expected_result
-):
- parser = JsonParser(json.dumps(test_json))
- assert parser.get(section_key, parse_types=parse_type) == expected_result
-
-
-@pytest.mark.parametrize(
- "key, value", [("zip", "zipzip"), ("foo.bar.foobar", 5), ("foo.baz", "bar")]
-)
-def test_that_json_parser_can_set_keys(key, value):
- test_json = {
- "foo": {
- "baz": 5,
- "boo": "4.4",
- "bar": {"test_key": "foobar", "foobar": {"test": True}},
- },
- "bar": {"baz": 10},
- "zip": "piz",
- }
-
- parser = JsonParser(json.dumps(test_json))
- parser.set(key, value)
- assert parser.get(key) == value
-
-
-@pytest.mark.parametrize(
- "key, test_json, expected_json",
- [
- ("foo", {"foo": "bar", "baz": 5}, {"baz": 5}),
- ("foo.bar", {"foo": {"bar": 5}}, {"foo": {}}),
- ],
-)
-def test_that_json_parser_can_delete_keys(key, test_json, expected_json):
- parser = JsonParser(json.dumps(test_json))
- parser.delete(key)
- assert parser.stringify() == json.dumps(expected_json)
-
-
-@pytest.mark.parametrize(
- "test_json, key, expected_output",
- [({"foo": {"bar": 5, "baz": {"bar": 10, "bam": {"bar": 15}}}}, "bar", [5, 10, 15])],
-)
-def test_that_json_parser_can_retrieve_all_keys(test_json, key, expected_output):
- parser = JsonParser(json.dumps(test_json))
- assert parser.get(key, get_all=True) == expected_output
-
-
-@pytest.mark.parametrize(
- "test_json, key, value, expected_output",
- [
- (
- {"foo": {"bar": 5, "baz": {"bar": 10, "bam": {"bar": 15}}}},
- "bar",
- "new_value",
- ["new_value", "new_value", "new_value"],
- )
- ],
-)
-def test_that_json_parser_can_set_all_keys(test_json, key, value, expected_output):
- parser = JsonParser(json.dumps(test_json))
- parser.set(key, value, set_all=True)
- assert parser.get(key, get_all=True) == expected_output
-
-
-@pytest.mark.parametrize(
- "test_json, key, expected_output",
- [
- (
- {"foo": {"bar": 5, "baz": {"bar": 10, "bam": {"bar": 15}}}},
- "bar",
- {"foo": {"baz": {"bam": {}}}},
- )
- ],
-)
-def test_that_json_parser_can_delete_all_keys(test_json, key, expected_output):
- parser = JsonParser(json.dumps(test_json))
- parser.delete(key, delete_all=True)
- assert parser.stringify() == json.dumps(expected_output)
diff --git a/tests/test_nested_lookup.py b/tests/test_nested_lookup.py
new file mode 100644
index 0000000..1239fad
--- /dev/null
+++ b/tests/test_nested_lookup.py
@@ -0,0 +1,1064 @@
+from unittest import TestCase
+
+from config_file.nested_lookup import (
+ get_all_keys,
+ get_occurrence_of_key,
+ get_occurrence_of_value,
+ get_occurrences_and_values,
+ nested_alter,
+ nested_delete,
+ nested_lookup,
+ nested_update,
+)
+
+
+class TestNestedLookup(TestCase):
+ def setUp(self):
+ self.subject_dict = {"a": 1, "b": {"d": 100}, "c": {"d": 200}}
+ self.subject_dict2 = {
+ "name": "Russell Ballestrini",
+ "email_address": "test1@example.com",
+ "other": {
+ "secondary_email": "test2@example.com",
+ "EMAIL_RECOVERY": "test3@example.com",
+ "email_address": "test4@example.com",
+ },
+ }
+ self.subject_dict3 = {
+ "build_version": {
+ "model_name": "MacBook Pro",
+ "build_version": {
+ "processor_name": "Intel Core i7",
+ "processor_speed": "2.7 GHz",
+ "core_details": {
+ "build_version": "4",
+ "l2_cache(per_core)": "256 KB",
+ },
+ },
+ "number_of_cores": "4",
+ "memory": "256 KB",
+ },
+ "os_details": {"product_version": "10.13.6", "build_version": "17G65"},
+ "name": "Test",
+ "date": "YYYY-MM-DD HH:MM:SS",
+ }
+ self.subject_dict4 = {
+ 1: "a",
+ 2: {"b": 44, "C": 55},
+ 3: "d",
+ 4: "e",
+ "6776": "works",
+ }
+
+ def test_nested_lookup(self):
+ results = nested_lookup("d", self.subject_dict)
+ self.assertEqual(2, len(results))
+ self.assertIn(100, results)
+ self.assertIn(200, results)
+ self.assertSetEqual({100, 200}, set(results))
+
+ def test_nested_lookup_wrapped_in_list(self):
+ results = nested_lookup("d", [{}, self.subject_dict, {}])
+ self.assertEqual(2, len(results))
+ self.assertIn(100, results)
+ self.assertIn(200, results)
+ self.assertSetEqual({100, 200}, set(results))
+
+ def test_nested_lookup_wrapped_in_list_in_dict_in_list(self):
+ results = nested_lookup("d", [{}, {"H": [self.subject_dict]}])
+ self.assertEqual(2, len(results))
+ self.assertIn(100, results)
+ self.assertIn(200, results)
+ self.assertSetEqual({100, 200}, set(results))
+
+ def test_nested_lookup_wrapped_in_list_in_list(self):
+ results = nested_lookup("d", [{}, [self.subject_dict, {}]])
+ self.assertEqual(2, len(results))
+ self.assertIn(100, results)
+ self.assertIn(200, results)
+ self.assertSetEqual({100, 200}, set(results))
+
+ def test_nested_lookup_key_is_non_str(self):
+ results = nested_lookup(key=4, document=self.subject_dict4)
+ self.assertIn("e", results)
+
+ def test_wild_nested_lookup(self):
+ results = nested_lookup(key="mail", document=self.subject_dict2, wild=True)
+ self.assertEqual(4, len(results))
+ self.assertIn("test1@example.com", results)
+ self.assertIn("test2@example.com", results)
+ self.assertIn("test3@example.com", results)
+
+ def test_wild_nested_lookup_integer_keys_in_document(self):
+ results = nested_lookup(key="c", document=self.subject_dict4, wild=True)
+ self.assertIn(55, results)
+
+ def test_wild_nested_lookup_integer_key_as_substring(self):
+ # test that wild works converts integers into strings before substring matching.
+ results = nested_lookup(key=77, document=self.subject_dict4, wild=True)
+ self.assertIn("works", results)
+
+ def test_wild_with_keys_nested_lookup(self):
+ matches = nested_lookup(
+ key="mail", document=self.subject_dict2, wild=True, with_keys=True
+ )
+ self.assertEqual(3, len(matches))
+ self.assertIn("email_address", matches)
+ self.assertIn("secondary_email", matches)
+ self.assertIn("EMAIL_RECOVERY", matches)
+ self.assertSetEqual(
+ {"test1@example.com", "test4@example.com"}, set(matches["email_address"])
+ )
+ self.assertIn("test2@example.com", matches["secondary_email"])
+
+ def test_nested_lookup_with_keys(self):
+ matches = nested_lookup("d", self.subject_dict, with_keys=True)
+ self.assertIn("d", matches)
+ self.assertEqual(2, len(matches["d"]))
+ self.assertSetEqual({100, 200}, set(matches["d"]))
+
+ def test_after_key_is_found(self):
+ result = nested_lookup(key="build_version", document=self.subject_dict3)
+ self.assertEqual(4, len(result))
+ self.assertIn("4", result)
+ self.assertIn("17G65", result)
+ match1 = {
+ "processor_name": "Intel Core i7",
+ "processor_speed": "2.7 GHz",
+ "core_details": {"build_version": "4", "l2_cache(per_core)": "256 KB"},
+ }
+ self.assertIn(match1, result)
+ match2 = {
+ "build_version": {
+ "processor_name": "Intel Core i7",
+ "processor_speed": "2.7 GHz",
+ "core_details": {"build_version": "4", "l2_cache(per_core)": "256 KB"},
+ },
+ "memory": "256 KB",
+ "model_name": "MacBook Pro",
+ "number_of_cores": "4",
+ }
+ self.assertIn(match2, result)
+
+
+class TestGetAllKeys(TestCase):
+ def setUp(self):
+ self.sample1 = {
+ "hardware_details": {
+ "model_name": "MacBook Pro",
+ "processor_details": {
+ "processor_name": "Intel Core i7",
+ "processor_speed": "2.7 GHz",
+ "core_details": {
+ "total_numberof_cores": "4",
+ "l2_cache(per_core)": "256 KB",
+ },
+ },
+ "total_number_of_cores": "4",
+ "memory": "16 GB",
+ },
+ "os_details": {"product_version": "10.13.6", "build_version": "17G65"},
+ "name": "Test",
+ "date": "YYYY-MM-DD HH:MM:SS",
+ }
+ self.sample2 = {
+ "hardware_details": {
+ "model_name": "MacBook Pro",
+ "processor_details": [
+ {
+ "processor_name": "Intel Core i7",
+ "processor_speed": "2.7 GHz",
+ "core_details": {
+ "total_numberof_cores": "4",
+ "l2_cache(per_core)": "256 KB",
+ },
+ }
+ ],
+ "total_number_of_cores": "4",
+ "memory": "16 GB",
+ }
+ }
+ self.sample3 = {
+ "hardware_details": {
+ "model_name": "MacBook Pro",
+ "processor_details": [
+ {"processor_name": "Intel Core i7", "processor_speed": "2.7 GHz"},
+ {"total_numberof_cores": "4", "l2_cache(per_core)": "256 KB"},
+ ],
+ "total_number_of_cores": "4",
+ "memory": "16 GB",
+ }
+ }
+ self.sample4 = {
+ "values": [
+ {
+ "checks": [
+ {
+ "monitoring_zones": [
+ "mzdfw",
+ "mzfra",
+ "mzhkg",
+ "mziad",
+ "mzlon",
+ "mzord",
+ "mzsyd",
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ self.sample5 = [
+ {
+ "listings": [
+ {
+ "name": "title",
+ "postcode": "postcode",
+ "full_address": "fulladdress",
+ "city": "city",
+ "lat": "latitude",
+ "lng": "longitude",
+ }
+ ]
+ }
+ ]
+
+ def test_sample_data1(self):
+ result = get_all_keys(self.sample1)
+ self.assertEqual(15, len(result))
+ keys_to_verify = [
+ "model_name",
+ "core_details",
+ "l2_cache(per_core)",
+ "build_version",
+ "date",
+ ]
+ for key in keys_to_verify:
+ self.assertIn(key, result)
+
+ def test_sample_data2(self):
+ result = get_all_keys(self.sample2)
+ self.assertEqual(10, len(result))
+ keys_to_verify = [
+ "hardware_details",
+ "processor_speed",
+ "total_numberof_cores",
+ "memory",
+ ]
+ for key in keys_to_verify:
+ self.assertIn(key, result)
+
+ def test_sample_data3(self):
+ result = get_all_keys(self.sample3)
+ self.assertEqual(9, len(result))
+ keys_to_verify = [
+ "processor_details",
+ "processor_name",
+ "l2_cache(per_core)",
+ "total_number_of_cores",
+ ]
+ for key in keys_to_verify:
+ self.assertIn(key, result)
+
+ def test_sample_data4(self):
+ result = get_all_keys(self.sample4)
+ self.assertEqual(3, len(result))
+ keys_to_verify = ["values", "checks", "monitoring_zones"]
+ for key in keys_to_verify:
+ self.assertIn(key, result)
+
+ def test_sample_data5(self):
+ result = get_all_keys(self.sample5)
+ self.assertEqual(7, len(result))
+ keys_to_verify = [
+ "listings",
+ "name",
+ "postcode",
+ "full_address",
+ "city",
+ "lat",
+ "lng",
+ ]
+ for key in keys_to_verify:
+ self.assertIn(key, result)
+
+
+class TestGetOccurrence(TestCase):
+ def setUp(self):
+ self.sample1 = {
+ "build_version": {
+ "model_name": "MacBook Pro",
+ "build_version": {
+ "processor_name": "Intel Core i7",
+ "processor_speed": "2.7 GHz",
+ "core_details": {
+ "build_version": "4",
+ "l2_cache(per_core)": "256 KB",
+ },
+ },
+ "number_of_cores": "4",
+ "memory": "256 KB",
+ },
+ "os_details": {"product_version": "10.13.6", "build_version": "17G65"},
+ "name": "Test",
+ "date": "YYYY-MM-DD HH:MM:SS",
+ }
+ self.sample2 = {
+ "hardware_details": {
+ "model_name": "MacBook Pro",
+ "processor_details": [
+ {
+ "processor_name": "4",
+ "processor_speed": "2.7 GHz",
+ "core_details": {
+ "total_numberof_cores": "4",
+ "l2_cache(per_core)": "256 KB",
+ },
+ }
+ ],
+ "total_number_of_cores": "4",
+ "memory": "16 GB",
+ }
+ }
+ self.sample3 = {
+ "hardware_details": {
+ "model_name": "MacBook Pro",
+ "processor_details": [
+ {"total_number_of_cores": "4", "processor_speed": "2.7 GHz"},
+ {"total_number_of_cores": "4", "l2_cache(per_core)": "256 KB"},
+ ],
+ "total_number_of_cores": "4",
+ "memory": "16 GB",
+ }
+ }
+ self.sample4 = {
+ "values": [
+ {
+ "checks": [
+ {
+ "monitoring_zones": [
+ "mzdfw",
+ "mzfra",
+ "mzhkg",
+ "mziad",
+ "mzlon",
+ "mzord",
+ "mzsyd",
+ ]
+ }
+ ]
+ }
+ ]
+ }
+
+ self.sample5 = {
+ "hardware_details": {
+ "model_name": "MacBook Pro",
+ "total_number_of_cores": 0,
+ "memory": False,
+ }
+ }
+
+ self.sample6 = [
+ {
+ "processor_name": "4",
+ "processor_speed": "2.7 GHz",
+ "core_details": {
+ "total_numberof_cores": "4",
+ "l2_cache(per_core)": "256 KB",
+ },
+ }
+ ]
+
+ self.sample7 = [
+ {
+ "processor_name": "4",
+ "processor_speed": "2.7 GHz",
+ "core_details": {
+ "total_numberof_cores": "4",
+ "l2_cache(per_core)": "256 KB",
+ },
+ },
+ {
+ "processor_name": "4",
+ "processor_speed": "2.7 GHz",
+ "core_details": {
+ "total_numberof_cores": "4",
+ "l2_cache(per_core)": "256 KB",
+ },
+ },
+ ]
+
+ def test_sample_data1(self):
+ result = get_occurrence_of_key(self.sample1, "build_version")
+ self.assertEqual(4, result)
+ result = get_occurrence_of_value(self.sample1, "256 KB")
+ self.assertEqual(2, result)
+
+ def test_sample_data2(self):
+ result = get_occurrence_of_key(self.sample2, "core_details")
+ self.assertEqual(1, result)
+ result = get_occurrence_of_value(self.sample2, "4")
+ self.assertEqual(3, result)
+
+ def test_sample_data3(self):
+ result = get_occurrence_of_key(self.sample3, "total_number_of_cores")
+ self.assertEqual(3, result)
+ result = get_occurrence_of_value(self.sample3, "4")
+ self.assertEqual(3, result)
+
+ def test_sample_data4(self):
+ result = get_occurrence_of_key(self.sample4, "checks")
+ self.assertEqual(1, result)
+ result = get_occurrence_of_value(self.sample4, "mziad")
+ self.assertEqual(1, result)
+ # Add one more value in key "monitoring_zones" and verify
+ self.sample4["values"][0]["checks"][0]["monitoring_zones"].append("mziad")
+ self.assertEqual(2, get_occurrence_of_value(self.sample4, "mziad"))
+
+ def test_sample_data5(self):
+ self.assertEqual(
+ 1, get_occurrence_of_key(self.sample5, "total_number_of_cores")
+ )
+ self.assertEqual(1, get_occurrence_of_key(self.sample5, "memory"))
+ # Add key 'memory' and verify
+ self.sample5["memory"] = 0
+ self.assertEqual(2, get_occurrence_of_key(self.sample5, "memory"))
+
+ def test_sample_data6(self):
+ value = "4"
+ result = get_occurrences_and_values(self.sample6, value)
+ self.assertEqual(2, result[value]["occurrences"])
+ self.assertEqual(2, len(result[value]["values"]))
+
+ def test_sample_data7(self):
+ value = "2.7 GHz"
+ result = get_occurrences_and_values(self.sample6, value)
+ self.assertEqual(1, result[value]["occurrences"])
+ self.assertEqual(1, len(result[value]["values"]))
+
+ def test_sample_data8(self):
+ value = "4"
+ result = get_occurrences_and_values(self.sample7, value)
+ self.assertEqual(4, result[value]["occurrences"])
+ self.assertEqual(4, len(result[value]["values"]))
+
+ def test_sample_data9(self):
+ value = "5"
+ result = get_occurrences_and_values(self.sample7, value)
+ self.assertEqual(0, result[value]["occurrences"])
+ self.assertEqual(0, len(result[value]["values"]))
+
+
+class BaseLookUpApi(TestCase):
+ def setUp(self):
+ self.sample_data1 = {
+ "build_version": {
+ "model_name": "MacBook Pro",
+ "build_version": {
+ "processor_name": "Intel Core i7",
+ "processor_speed": "2.7 GHz",
+ "core_details": {
+ "build_version": "4",
+ "l2_cache(per_core)": "256 KB",
+ },
+ },
+ "number_of_cores": "4",
+ "memory": "256 KB",
+ },
+ "os_details": {"product_version": "10.13.6", "build_version": "17G65"},
+ "name": "Test",
+ "date": "YYYY-MM-DD HH:MM:SS",
+ }
+
+ self.sample_data2 = {
+ "hardware_details": {
+ "model_name": "MacBook Pro",
+ "processor_details": [
+ {"processor_name": "Intel Core i7", "processor_speed": "2.7 GHz"},
+ {"total_number_of_cores": "4", "l2_cache(per_core)": "256 KB"},
+ ],
+ "total_number_of_cores": "5",
+ "memory": "16 GB",
+ }
+ }
+
+ self.sample_data3 = {
+ "values": [
+ {
+ "checks": [
+ {
+ "monitoring_zones": [
+ "mzdfw",
+ "mzfra",
+ "mzhkg",
+ "mziad",
+ "mzlon",
+ "mzord",
+ "mzsyd",
+ ]
+ }
+ ]
+ }
+ ]
+ }
+
+ self.sample_data4 = {
+ "modelversion": "1.1.0",
+ "vorgangsID": "1",
+ "versorgungsvorschlagDatum": 1510558834978,
+ "eingangsdatum": 1510558834978,
+ "plz": 82269,
+ "vertragsteile": [
+ {
+ "typ": "1",
+ "beitragsDaten": {
+ "endalter": 85,
+ "brutto": 58.76,
+ "netto": 58.76,
+ "zahlungsrhythmus": "MONATLICH",
+ "plz": 86899,
+ },
+ "beginn": 1512082800000,
+ "lebenslang": "True",
+ "ueberschussverwendung": {
+ "ueberschussverwendung": "2",
+ "indexoption": "3",
+ },
+ "deckung": [
+ {
+ "typ": "2",
+ "art": "1",
+ "leistung": {"value": 7500242424.0, "einheit": "2"},
+ "leistungsRhythmus": "1",
+ }
+ ],
+ "zuschlagNachlass": [],
+ },
+ {
+ "typ": "1",
+ "beitragsDaten": {
+ "endalter": 85,
+ "brutto": 0.6,
+ "netto": 0.6,
+ "zahlungsrhythmus": "1",
+ },
+ "zuschlagNachlass": [],
+ },
+ ],
+ }
+
+
+class TestNestedDelete(BaseLookUpApi):
+ def test_sample_data1(self):
+ result = {
+ "os_details": {"product_version": "10.13.6"},
+ "name": "Test",
+ "date": "YYYY-MM-DD HH:MM:SS",
+ }
+ self.assertEqual(result, nested_delete(self.sample_data1, "build_version"))
+
+ def test_sample_data2(self):
+ result = {
+ "hardware_details": {
+ "model_name": "MacBook Pro",
+ "total_number_of_cores": "5",
+ "memory": "16 GB",
+ }
+ }
+ self.assertEqual(result, nested_delete(self.sample_data2, "processor_details"))
+
+ def test_sample_data3(self):
+ result = {"values": [{"checks": [{}]}]}
+ self.assertEqual(result, nested_delete(self.sample_data3, "monitoring_zones"))
+
+
+class TestNestedUpdate(BaseLookUpApi):
+ def test_sample_data1(self):
+ result = {
+ "build_version": "Test1",
+ "os_details": {"product_version": "10.13.6", "build_version": "Test1"},
+ "name": "Test",
+ "date": "YYYY-MM-DD HH:MM:SS",
+ }
+ self.assertEqual(
+ result, nested_update(self.sample_data1, "build_version", "Test1")
+ )
+
+ def test_sample_data1_list_input_treat_list_as_element_true(self):
+ result = {
+ "build_version": ["Test5", "Test6", "Test7"],
+ "os_details": {
+ "product_version": "10.13.6",
+ "build_version": ["Test5", "Test6", "Test7"],
+ },
+ "name": "Test",
+ "date": "YYYY-MM-DD HH:MM:SS",
+ }
+
+ self.assertEqual(
+ result,
+ nested_update(
+ self.sample_data1,
+ "build_version",
+ ["Test5", "Test6", "Test7"],
+ treat_as_element=True,
+ ),
+ )
+
+ def test_nested_update_in_place_false(self):
+ """
+ ested_update should mutate and return a copy of the original document
+ """
+ before_id = id(self.sample_data1)
+ result = nested_update(
+ self.sample_data1, "build_version", "Test2", in_place=False
+ )
+ after_id = id(result)
+ # the object ids should _not_ match.
+ self.assertNotEqual(before_id, after_id)
+
+ def test_nested_update_in_place_true(self):
+ """
+ nested_update should mutate and return the original document
+ """
+ before_id = id(self.sample_data1)
+ result = nested_update(
+ self.sample_data1, "build_version", "Test2", in_place=True
+ )
+ after_id = id(result)
+ # the object ids should match.
+ self.assertEqual(before_id, after_id)
+
+ def test_nested_update_in_place_true_list_input(self):
+ doc = self.sample_data4
+ # get all instances of the given element
+ findings = nested_lookup("plz", doc, False, True)
+ # alter those instances
+ updated_findings = list()
+ for key, val in findings.items():
+ for elem in val:
+ updated_findings.append(elem + 300)
+ # update those instances with the altered results
+ doc_updated = nested_update(
+ doc, "plz", updated_findings, treat_as_element=False
+ )
+ elem1 = doc_updated["plz"] # 85269
+ # 87199
+ elem2 = doc_updated["vertragsteile"][0]["beitragsDaten"]["plz"]
+ self.assertEqual(elem1, 82569)
+ self.assertEqual(elem2, 87199)
+
+ def test_nested_update_in_place_false_list_input(self):
+ doc = self.sample_data4
+ # get all instances of the given element
+ findings = nested_lookup("plz", doc, False, True)
+ # alter those instances
+ updated_findings = list()
+ for key, val in findings.items():
+ for elem in val:
+ updated_findings.append(elem + 300)
+ # update those instances with the altered results
+ doc_updated = nested_update(
+ doc, "plz", updated_findings, in_place=False, treat_as_element=False
+ )
+ elem1 = doc_updated["plz"]
+ elem2 = doc_updated["vertragsteile"][0]["beitragsDaten"]["plz"]
+ self.assertEqual(elem1, 82569)
+ self.assertEqual(elem2, 87199)
+
+ def test_nested_update_in_place_false_list_input_as_element_false(self):
+ doc = self.sample_data4
+ # get all instances of the given element
+ list_input = [1, 2, 3, 4, 5]
+ # update those instances with the altered results
+ doc_updated = nested_update(
+ doc, "plz", list_input, in_place=False, treat_as_element=False
+ )
+ elem1 = doc_updated["plz"]
+ elem2 = doc_updated["vertragsteile"][0]["beitragsDaten"]["plz"]
+ # should not work without specifying "treat_list_as_element = True"
+ # in nested_update
+ self.assertNotEqual(elem1, list_input)
+ self.assertNotEqual(elem2, list_input)
+
+ def test_nested_update_in_place_false_list_input_as_element_true(self):
+ doc = self.sample_data4
+ # get all instances of the given element
+ list_input = [1, 2, 3, 4, 5]
+ # update those instances with the altered results
+ doc_updated = nested_update(
+ doc, "plz", list_input, in_place=False, treat_as_element=True
+ )
+ elem1 = doc_updated["plz"]
+ elem2 = doc_updated["vertragsteile"][0]["beitragsDaten"]["plz"]
+ # should not work without specifying "treat_list_as_element = True"
+ # in nested_update
+ self.assertEqual(elem1, list_input)
+ self.assertEqual(elem2, list_input)
+
+ def test_nested_update_in_place_true_list_input_as_element_false(self):
+ doc = self.sample_data4
+ # get all instances of the given element
+ list_input = [1, 2, 3, 4, 5]
+ # update those instances with the altered results
+ doc_updated = nested_update(
+ doc, "plz", list_input, in_place=True, treat_as_element=False
+ )
+ elem1 = doc_updated["plz"]
+ elem2 = doc_updated["vertragsteile"][0]["beitragsDaten"]["plz"]
+ # should not work without specifying "treat_list_as_element = True"
+ # in nested_update
+ self.assertNotEqual(elem1, list_input)
+ self.assertNotEqual(elem2, list_input)
+
+ def test_nested_update_in_place_true_list_input_as_element_true(self):
+ doc = self.sample_data4
+ # get all instances of the given element
+ list_input = [1, 2, 3, 4, 5]
+ # update those instances with the altered results
+ doc_updated = nested_update(
+ doc, "plz", list_input, in_place=True, treat_as_element=True
+ )
+ elem1 = doc_updated["plz"]
+ elem2 = doc_updated["vertragsteile"][0]["beitragsDaten"]["plz"]
+ # should not work without specifying "treat_list_as_element = True"
+ # in nested_update
+ self.assertEqual(elem1, list_input)
+ self.assertEqual(elem2, list_input)
+
+ def test_nested_delete_in_place_false(self):
+ """
+ nested_delete should mutate and return a copy of the original document
+ """
+ before_id = id(self.sample_data1)
+ result = nested_delete(self.sample_data1, "build_version", in_place=False)
+ after_id = id(result)
+ # the object ids should _not_ match.
+ self.assertNotEqual(before_id, after_id)
+
+ def test_nested_delete_in_place_true(self):
+ """nested_delete should mutate and return the original document"""
+ before_id = id(self.sample_data1)
+ result = nested_delete(self.sample_data1, "build_version", in_place=True)
+ after_id = id(result)
+ # the object ids should match.
+ self.assertEqual(before_id, after_id)
+
+ def test_nested_update_taco_for_example(self):
+ document = [{"taco": 42}, {"salsa": [{"burrito": {"taco": 69}}]}]
+
+ updated_document = nested_update(
+ document, "taco", [100, 200], treat_as_element=False
+ )
+
+ self.assertEqual(updated_document[0]["taco"], 100)
+ # The multi-update version only works for scalar input,
+ # if you need to adress a list of dicts, you have to
+ # manually iterate over those and pass them to nested_update
+ # one by one
+ self.assertEqual(updated_document[1]["salsa"][0]["burrito"]["taco"], 200)
+
+ def test_nested_update_raise_error(self):
+ doc = self.sample_data4
+ # get all instances of the given element
+ list_input = 1
+ # update those instances with the altered results
+ self.assertRaises(
+ Exception,
+ nested_update,
+ doc,
+ "plz",
+ list_input,
+ in_place=True,
+ treat_as_element=False,
+ )
+
+ def test_sample_data2(self):
+ result = {
+ "hardware_details": {
+ "model_name": "MacBook Pro",
+ "processor_details": {"test_key1": "test_value1"},
+ "total_number_of_cores": "5",
+ "memory": "16 GB",
+ }
+ }
+ self.assertEqual(
+ result,
+ nested_update(
+ self.sample_data2, "processor_details", {"test_key1": "test_value1"}
+ ),
+ )
+
+ def test_sample_data3(self):
+ result = {"values": [{"checks": {"key1": ["value1"], "key2": "value2"}}]}
+ self.assertEqual(
+ result,
+ nested_update(
+ self.sample_data3, "checks", {"key1": ["value1"], "key2": "value2"}
+ ),
+ )
+
+ def test_sample_data4(self):
+ result = {
+ "modelversion": {"key1": ["value1"], "key2": "value2"},
+ "vorgangsID": "1",
+ "versorgungsvorschlagDatum": 1510558834978,
+ "eingangsdatum": 1510558834978,
+ "plz": 82269,
+ "vertragsteile": [
+ {
+ "typ": "1",
+ "beitragsDaten": {
+ "endalter": 85,
+ "brutto": 58.76,
+ "netto": 58.76,
+ "zahlungsrhythmus": "MONATLICH",
+ "plz": 86899,
+ },
+ "beginn": 1512082800000,
+ "lebenslang": "True",
+ "ueberschussverwendung": {
+ "ueberschussverwendung": "2",
+ "indexoption": "3",
+ },
+ "deckung": [
+ {
+ "typ": "2",
+ "art": "1",
+ "leistung": {"value": 7500242424.0, "einheit": "2"},
+ "leistungsRhythmus": "1",
+ }
+ ],
+ "zuschlagNachlass": [],
+ },
+ {
+ "typ": "1",
+ "beitragsDaten": {
+ "endalter": 85,
+ "brutto": 0.6,
+ "netto": 0.6,
+ "zahlungsrhythmus": "1",
+ },
+ "zuschlagNachlass": [],
+ },
+ ],
+ }
+ self.assertEqual(
+ result,
+ nested_update(
+ self.sample_data4,
+ "modelversion",
+ {"key1": ["value1"], "key2": "value2"},
+ ),
+ )
+
+
+class TestNestedAlter(BaseLookUpApi):
+ def test_nested_alter_in_place_true(self):
+
+ # callback functions
+ def callback(data):
+ return str(data) + "###"
+
+ doc_updated = nested_alter(
+ self.sample_data4, "vorgangsID", callback, in_place=True
+ )
+
+ vorgangsid = doc_updated["vorgangsID"]
+
+ self.assertEqual(vorgangsid, "1###")
+
+ def test_nested_alter_in_place_false(self):
+
+ # callback functions
+ def callback(data):
+ return str(data) + "###"
+
+ doc_updated = nested_alter(
+ self.sample_data4, "vorgangsID", callback, in_place=False
+ )
+
+ vorgangsid = doc_updated["vorgangsID"]
+
+ # should not work without specifying
+ # "treat_list_as_element = True" in nested_update
+ self.assertEqual(vorgangsid, "1###")
+
+ def test_nested_alter_list_input_in_place_true(self):
+
+ # callback functions
+ def callback(data):
+ return str(data) + "###"
+
+ doc_updated = nested_alter(
+ self.sample_data4, ["plz", "vorgangsID"], callback, in_place=True
+ )
+
+ plz1 = doc_updated["plz"]
+ plz2 = doc_updated["vertragsteile"][0]["beitragsDaten"]["plz"]
+ vorgangsid = doc_updated["vorgangsID"]
+
+ # should not work without specifying
+ # "treat_list_as_element = True" in nested_update
+ self.assertEqual(plz1, "82269###")
+ self.assertEqual(plz2, "86899###")
+ self.assertEqual(vorgangsid, "1###")
+
+ def test_nested_alter_list_input_with_args_in_place_true(self):
+
+ # callback functions
+ def callback(data, str1, str2):
+ return str(data) + str1 + str2
+
+ doc_updated = nested_alter(
+ self.sample_data4,
+ ["plz", "vorgangsID"],
+ callback,
+ function_parameters=["abc", "def"],
+ in_place=True,
+ )
+
+ plz1 = doc_updated["plz"]
+ plz2 = doc_updated["vertragsteile"][0]["beitragsDaten"]["plz"]
+ vorgangsid = doc_updated["vorgangsID"]
+
+ # should not work without specifying
+ # "treat_list_as_element = True" in nested_update
+ self.assertEqual(plz1, "82269abcdef")
+ self.assertEqual(plz2, "86899abcdef")
+ self.assertEqual(vorgangsid, "1abcdef")
+
+ def test_nested_alter_list_input_with_args_in_place_false(self):
+
+ # callback functions
+ def callback(data, str1, str2):
+ return str(data) + str1 + str2
+
+ doc_updated = nested_alter(
+ self.sample_data4,
+ ["plz", "vorgangsID"],
+ callback,
+ function_parameters=["abc", "def"],
+ in_place=False,
+ )
+
+ plz1 = doc_updated["plz"]
+ plz2 = doc_updated["vertragsteile"][0]["beitragsDaten"]["plz"]
+ vorgangsid = doc_updated["vorgangsID"]
+
+ # should not work without specifying
+ # "treat_list_as_element = True" in nested_update
+ self.assertEqual(plz1, "82269abcdef")
+ self.assertEqual(plz2, "86899abcdef")
+ self.assertEqual(vorgangsid, "1abcdef")
+
+ def test_nested_alter_list_input_in_place_false(self):
+
+ # callback functions
+ def callback(data):
+ return str(data) + "###"
+
+ doc_updated = nested_alter(
+ self.sample_data4, ["plz", "vorgangsID"], callback, in_place=False
+ )
+
+ plz1 = doc_updated["plz"]
+ plz2 = doc_updated["vertragsteile"][0]["beitragsDaten"]["plz"]
+ vorgangsid = doc_updated["vorgangsID"]
+
+ # should not work without specifying
+ # "treat_list_as_element = True" in nested_update
+ self.assertEqual(plz1, "82269###")
+ self.assertEqual(plz2, "86899###")
+ self.assertEqual(vorgangsid, "1###")
+
+ def test_nested_alter_taco_for_example(self):
+ documents = [{"taco": 42}, {"salsa": [{"burrito": {"taco": 69}}]}]
+
+ # write a callback function which processes a scalar value.
+ # Be aware about the possible types which can be passed to
+ # the callback functions.
+ # In this example we can be sure that only int will be passed,
+ # in production you should check the type because it could be
+ # anything.
+ def callback(data):
+ return data + 10 # (data/100*10)
+
+ # The alter-version only works for scalar input (one dict),
+ # if you need to adress a list of dicts, you have to
+ # manually iterate over those and pass them to
+ # nested_update one by one
+ out = []
+ for elem in documents:
+ altered_document = nested_alter(elem, "taco", callback)
+ out.append(altered_document)
+
+ self.maxDiff = None
+ self.assertEqual(out[0]["taco"], 52)
+ self.assertEqual(out[1]["salsa"][0]["burrito"]["taco"], 79)
+
+ def test_nested_alter_work_with_right_order(self):
+ document = {"taco": 42, "salsa": [{"burrito": {"key": 20}}], "key": 50}
+
+ def callback(data):
+ return data + 100
+
+ altered_document = nested_alter(document, "key", callback, in_place=True)
+
+ self.assertEqual(altered_document["salsa"][0]["burrito"]["key"], 120)
+ self.assertEqual(altered_document["key"], 150)
+
+ def test_sample_data4(self):
+
+ result = {
+ "modelversion": "1.1.0",
+ "vorgangsID": "1",
+ "versorgungsvorschlagDatum": 1510558834978,
+ "eingangsdatum": 1510558834978,
+ "plz": 82270,
+ "vertragsteile": [
+ {
+ "typ": "1",
+ "beitragsDaten": {
+ "endalter": 85,
+ "brutto": 58.76,
+ "netto": 58.76,
+ "zahlungsrhythmus": "MONATLICH",
+ "plz": 86900,
+ },
+ "beginn": 1512082800000,
+ "lebenslang": "True",
+ "ueberschussverwendung": {
+ "ueberschussverwendung": "2",
+ "indexoption": "3",
+ },
+ "deckung": [
+ {
+ "typ": "2",
+ "art": "1",
+ "leistung": {"value": 7500242424.0, "einheit": "2"},
+ "leistungsRhythmus": "1",
+ }
+ ],
+ "zuschlagNachlass": [],
+ },
+ {
+ "typ": "1",
+ "beitragsDaten": {
+ "endalter": 85,
+ "brutto": 0.6,
+ "netto": 0.6,
+ "zahlungsrhythmus": "1",
+ },
+ "zuschlagNachlass": [],
+ },
+ ],
+ }
+
+ # add +1 to all plz
+ def callback(data):
+ return data + 1
+
+ self.maxDiff = None
+ self.assertEqual(result, nested_alter(self.sample_data4, "plz", callback))
diff --git a/tests/test_parse_value.py b/tests/test_parse_value.py
index 81db472..7956a06 100644
--- a/tests/test_parse_value.py
+++ b/tests/test_parse_value.py
@@ -1,6 +1,15 @@
+from datetime import datetime
+
import pytest
-from config_file.parsers.parse_value import can_be_parsed_as_bool, parse_value
+from config_file.parse_value import (
+ can_be_parsed_as_bool,
+ can_be_parsed_as_dict,
+ can_be_parsed_as_float,
+ can_be_parsed_as_int,
+ can_be_parsed_as_list,
+ parse_value,
+)
@pytest.mark.parametrize(
@@ -8,34 +17,192 @@ from config_file.parsers.parse_value import can_be_parsed_as_bool, parse_value
[
("5", 5),
("-5", -5),
+ ("0", 0),
("-234.5", -234.5),
("35.5", 35.5),
("TRUE", True),
("true", True),
("false", False),
- ("blah", "blah"),
- (343, 343),
- (3.2, 3.2),
- (True, True),
+ ],
+)
+def test_parse_value_parses_ints_floats_and_bools(test_input, expected):
+ """
+ config_file.parse_value.parse_value
+
+ Parses string values that contain ints, floats, and booleans into
+ their native representation.
+ """
+ assert parse_value(test_input) == expected
+
+
+@pytest.mark.parametrize(
+ "test_input,expected",
+ [
({"blah": "5"}, {"blah": 5}),
(
- {"blah": {"blah2": {"blah3": "false"}, "abc": "5.25", "boo": "tRuE"}},
+ {"blah": {"blah2": {"blah3": "fAlSe"}, "abc": "5.25", "boo": "tRuE"}},
{"blah": {"blah2": {"blah3": False}, "abc": 5.25, "boo": True}},
),
+ ("{ 'key': '5', 'key2': 'fAlSE' }", {"key": 5, "key2": False}),
(
["5", "4.4", "faLSe", "trUE", "foo", "-5", "-5.2"],
[5, 4.4, False, True, "foo", -5, -5.2],
),
+ (" [1, 2, 3] ", [1, 2, 3]),
+ (" [True, [1, 5], {}, 5.5]", [True, [1, 5], {}, 5.5]),
+ (" [ [ [ [] ]] ] ", [[[[]]]]),
],
)
-def test_parse_value(test_input, expected):
+def test_parse_value_parses_dicts_and_lists(test_input, expected):
+ """
+ config_file.parse_value.parse_value
+
+ Parses string values that contain dictionaries or lists into
+ their native representation.
+ """
assert parse_value(test_input) == expected
-def test_can_be_parsed_as_bool():
+@pytest.mark.parametrize("test_input", ["blah", datetime(2020, 1, 1)])
+def test_parse_value_returns_values_that_cannot_be_parsed(test_input):
+ """
+ config_file.parse_value.parse_value
+
+ If a value is given that cannot be parsed by parse_value,
+ it should simply return that value back.
+ """
+ assert parse_value(test_input) == test_input
+
+
+@pytest.mark.parametrize(
+ "test_input",
+ [(343, 343), (3.2, 3.2), (True, True), (False, False), ({}, {}), ([], [])],
+)
+def test_parse_value_returns_values_that_are_already_in_their_native_type(test_input):
+ """
+ config_file.parse_value.parse_value
+
+ Returns back the inputted value if it is already in its native type.
+ """
+ assert parse_value(test_input) == test_input
+
+
+@pytest.mark.parametrize("value", [-1, 0, 1, "1", "-1", " 0 "])
+def test_values_that_can_be_parsed_as_int(value):
+ """
+ config_file.parse_value.can_be_parsed_as_int
+
+ Returns True for values that can be parsed as an int.
+ """
+ assert can_be_parsed_as_int(value)
+
+
+@pytest.mark.parametrize(
+ "value", [True, False, 5.5, "5.5", [], {}, "ruff", datetime.now()]
+)
+def test_values_that_cannot_be_parsed_as_int(value):
+ """
+ config_file.parse_value.can_be_parsed_as_int
+
+ Returns False for values that cannot be parsed as an int.
+ """
+ assert not can_be_parsed_as_int(value)
+
+
+@pytest.mark.parametrize("value", [5.5, -1.2, ".1", "5.5", " 1.1 ", "-0.0", "0.0"])
+def test_values_that_can_be_parsed_as_float(value):
+ """
+ config_file.parse_value.can_be_parsed_as_float
+
+ Returns True for values that can be parsed as an float.
"""
- This is the section not being covered in the parse_value.py
- file from test_parse_value, but I don't think it's reachable
- from using it.
+ assert can_be_parsed_as_float(value)
+
+
+@pytest.mark.parametrize(
+ "value",
+ [
+ 545,
+ 0,
+ -3,
+ "1",
+ "-1",
+ True,
+ False,
+ " 0 ",
+ "0..0",
+ [],
+ {},
+ "ruff",
+ datetime.now(),
+ ],
+)
+def test_values_that_cannot_be_parsed_as_float(value):
+ """
+ config_file.parse_value.can_be_parsed_as_float
+
+ Returns False for values that cannot be parsed as an float.
+ """
+ assert not can_be_parsed_as_float(value)
+
+
+@pytest.mark.parametrize(
+ "value", [True, False, "false", "true", "TRUE", "FALSE", " FALSE ", " TRUE "]
+)
+def test_values_that_can_be_parsed_as_bool(value):
+ """
+ config_file.parse_value.can_be_parsed_as_bool
+
+ Returns True for values that can be parsed as a bool.
+ """
+ assert can_be_parsed_as_bool(value)
+
+
+@pytest.mark.parametrize("value", [0, 1, -1, 5.3, "ruff", {}, [], datetime.now()])
+def test_values_that_cannot_be_parsed_as_bool(value):
+ """
+ config_file.parse_value.can_be_parsed_as_bool
+
+ Returns False for values that cannot be parsed as a bool.
+ """
+ assert not can_be_parsed_as_bool(value)
+
+
+@pytest.mark.parametrize("value", [{}, {"hello": 5}, "{}", " { } ", "{'test': 5}"])
+def test_values_that_can_be_parsed_as_dict(value):
+ """
+ config_file.parse_value.can_be_parsed_as_dict
+
+ Returns True for values that can be parsed as a dict.
+ """
+ assert can_be_parsed_as_dict(value)
+
+
+@pytest.mark.parametrize("value", [0, 5, -1, 5.5, [], "ruff", " { invalid } "])
+def test_values_that_cannot_be_parsed_as_dict(value):
+ """
+ config_file.parse_value.can_be_parsed_as_dict
+
+ Returns False for values that cannot be parsed as a dict.
+ """
+ assert not can_be_parsed_as_dict(value)
+
+
+@pytest.mark.parametrize("value", [[], [1, 2, True, 5.5], "[]", " [] ", " [1, 2, 3]"])
+def test_values_that_can_be_parsed_as_list(value):
+ """
+ config_file.parse_value.can_be_parsed_as_list
+
+ Returns True for values that can be parsed as a list.
+ """
+ assert can_be_parsed_as_list(value)
+
+
+@pytest.mark.parametrize("value", [0, 5, -1, 5.5, {}, "ruff", " [ invalid ] "])
+def test_values_that_cannot_be_parsed_as_list(value):
+ """
+ config_file.parse_value.can_be_parsed_as_list
+
+ Returns False for values that cannot be parsed as a list.
"""
- assert can_be_parsed_as_bool(5) is False
+ assert not can_be_parsed_as_list(value)
diff --git a/tests/test_toml_parser.py b/tests/test_toml_parser.py
new file mode 100644
index 0000000..845e78e
--- /dev/null
+++ b/tests/test_toml_parser.py
@@ -0,0 +1,24 @@
+from unittest.mock import patch
+
+import pytest
+
+from config_file.toml_parser import TomlParser
+
+
+def test_that_import_error_is_raised_if_no_tomlkit():
+ """
+ config_file.toml_parser.TomlParser
+
+ Ensure an import error is raised if tomlkit is not
+ installed.
+ """
+ with pytest.raises(ImportError) as error:
+
+ with patch("builtins.__import__") as mock_import:
+ mock_import.side_effect = ImportError
+ TomlParser("")
+
+ assert (
+ "Install the `toml` extra first with `pip install config-file[toml]`."
+ in str(error)
+ )
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 6779d18..663aaba 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -1,19 +1,73 @@
+from pathlib import Path
+
import pytest
-from config_file.utils import split_on_dot
+from config_file.utils import Default, split_on_dot
+
+
+def test_that_split_on_dot_splits_the_line_correctly():
+ """
+ config_file.utils.split_on_dot
+
+ Ensure splitting a string with dots in it returns an
+ array of strings split on those dots.
+ """
+ assert split_on_dot("section.key.blah") == ["section", "key", "blah"]
-@pytest.mark.parametrize(
- "test_input, only_last_dot, expected_result",
- [("section.key.blah", False, ["section", "key", "blah"])],
-)
-def test_that_split_on_dot_splits_the_line_correctly(
- test_input, only_last_dot, expected_result
-):
- assert split_on_dot(test_input, only_last_dot=only_last_dot) == expected_result
+def test_that_split_on_dot_can_only_split_on_the_last_one():
+ """
+ config_file.utils.split_on_dot
+ Ensure that the only_last_dot parameter only splits the input
+ on the last dot.
+ """
+ assert split_on_dot("test.input.should.only.split.on.last", only_last_dot=True) == [
+ "test.input.should.only.split.on",
+ "last",
+ ]
-@pytest.mark.parametrize("test_input", ["this line has no dots in it"])
-def test_that_split_on_dot_raises_error_when_there_is_no_dot(test_input):
+
+def test_that_split_on_dot_raises_error_when_there_is_no_dot():
+ """
+ config_file.utils.split_on_dot
+
+ Ensure that a ValueError is raised if the input to split_on_dot
+ has no dot (.) in it.
+ """
with pytest.raises(ValueError):
- split_on_dot(test_input)
+ split_on_dot("this line has no dots in it")
+
+
+def test_that_split_on_dot_can_accept_path_objects():
+ """
+ config_file.utils.split_on_dot
+
+ Ensure that a pathlib.Path object is able to be
+ given to split_on_dot.
+ """
+ split = split_on_dot(Path("some.file.path.with.dots"))
+
+ assert split == ["some", "file", "path", "with", "dots"]
+
+
+def test_that_default_is_initialized_correctly():
+ """
+ config_file.utils.Default
+
+ Ensure that the Default class's value attribute
+ is the same value that it was constructed with.
+ """
+ default = Default(5)
+ assert default.value == 5
+
+
+def test_that_default_has_the_correct_repr_format():
+ """
+ config_file.utils.Default
+
+ Ensure that when the Default class is coerced to
+ a string, it has the correct format and output.
+ """
+ default = Default("test")
+ assert str(default) == "Default Value: test (<class 'str'>)"
diff --git a/tests/test_yaml_parser.py b/tests/test_yaml_parser.py
new file mode 100644
index 0000000..1f46692
--- /dev/null
+++ b/tests/test_yaml_parser.py
@@ -0,0 +1,24 @@
+from unittest.mock import patch
+
+import pytest
+
+from config_file.yaml_parser import YamlParser
+
+
+def test_that_import_error_is_raised_if_no_ruamelyaml():
+ """
+ config_file.yaml_parser.YamlParser
+
+ Ensure an import error is raised if ruamel.yaml is not
+ installed.
+ """
+ with pytest.raises(ImportError) as error:
+
+ with patch("builtins.__import__") as mock_import:
+ mock_import.side_effect = ImportError
+ YamlParser("")
+
+ assert (
+ "Install the `yaml` extra first with `pip install config-file[yaml]`."
+ in str(error)
+ )
diff --git a/tox.ini b/tox.ini
deleted file mode 100644
index 1098700..0000000
--- a/tox.ini
+++ /dev/null
@@ -1,14 +0,0 @@
-[tox]
-isolated_build = true
-envlist = py{36, 37, 38}
-recreate = True
-
-[testenv]
-passenv = TOXENV CI TRAVIS TRAVIS_* CODECOV_*
-deps = codecov>=1.4.0
-whitelist_externals = poetry
-commands =
- poetry install -v --no-dev -E toml -E yaml
- pip install pytest pytest-cov requests taskipy
- poetry run task test
- codecov -e TOXENV