Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.4.0 #15

Merged
merged 8 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.4.0] - 2023-09-12

### Added

- `TestCase` - Extends the default Python TestCase with more assertions.
- `test_cases(cases)` - Decorates a test case with parameters.

## [0.3.0] - 2023-09-12

### Added
Expand Down Expand Up @@ -48,6 +55,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Wrong use of the module path
It was generating the error `TypeError: expected str, bytes or os.PathLike object, not list`

## [0.1.1] - 2023-09-05

Expand All @@ -57,7 +65,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Wrong detection of the application path (`__main__` has no attribute)"
- Wrong detection of the application path, in `get_application_path()` (`__main__` has no attribute)
The trick used was not working, the `__main__` module has no attribute.

## [0.1.0] - 2023-09-05

Expand Down
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
- [`toolbox.logging`](./toolbox.logging.md#module-toolboxlogging): The `logging` package provides several utilities for logging purpose.
- [`toolbox.logging.config`](./toolbox.logging.config.md#module-toolboxloggingconfig): A collection of utilities for logging purpose.
- [`toolbox.logging.log_file`](./toolbox.logging.log_file.md#module-toolboxlogginglog_file): A custom logger that writes directly to a file.
- [`toolbox.testing`](./toolbox.testing.md#module-toolboxtesting): The `testing` package provides utilities for testing purpose.
- [`toolbox.testing.decorators`](./toolbox.testing.decorators.md#module-toolboxtestingdecorators): A collection of decorators for testing purpose.
- [`toolbox.testing.test_case`](./toolbox.testing.test_case.md#module-toolboxtestingtest_case): Extends the default Python TestCase with more assertions.

## Classes

Expand All @@ -23,6 +26,7 @@
- [`json_file.JSONFile`](./toolbox.files.json_file.md#class-jsonfile): Offers a simple API for reading and writing JSON files.
- [`pickle_file.PickleFile`](./toolbox.files.pickle_file.md#class-picklefile): Offers a simple API for reading and writing pickle files.
- [`log_file.LogFile`](./toolbox.logging.log_file.md#class-logfile): Offers a similar API to the Python builtin loggers for logging to a custom file.
- [`test_case.TestCase`](./toolbox.testing.test_case.md#class-testcase): Test class with additional assertions.

## Functions

Expand All @@ -44,6 +48,7 @@
- [`pickle_file.write_pickle_file`](./toolbox.files.pickle_file.md#function-write_pickle_file): Writes a list of objects to a file.
- [`config.handle_uncaught_exceptions`](./toolbox.logging.config.md#function-handle_uncaught_exceptions): Installs a collector for logging uncaught exceptions.
- [`config.setup_file_logging`](./toolbox.logging.config.md#function-setup_file_logging): Setup the application log to a file logger.
- [`decorators.test_cases`](./toolbox.testing.decorators.md#function-test_cases): Creates a decorator for parametric test cases.


---
Expand Down
81 changes: 81 additions & 0 deletions docs/toolbox.testing.decorators.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!-- markdownlint-disable -->

<a href="../toolbox/testing/decorators.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `toolbox.testing.decorators`
A collection of decorators for testing purpose.



**Examples:**
```python
from toolbox import testing

# Parameters can be given either as list of arguments or either as dictionaries.
# In both cases, the parameters must be present in the signature of the test method.
@testing.test_cases([
["adding numbers", [10, 20, 12], 42],
{
"title": "returning numbers",
"params": [100],
"expected": 100,
},
])
def test_addition(self, title, params, expected):
self.assertEqual(addition(*params), expected)
```


---

<a href="../toolbox/testing/decorators.py#L25"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `test_cases`

```python
test_cases(cases: list[dict | list]) → Callable
```

Creates a decorator for parametric test cases.



**Args:**

- <b>`cases`</b> (list[dict | dict]): The list of parameters for each test case. The parameters can be given either as a list of positioned arguments, or either as a dictionary of named arguments. In both cases, the parameters must be present in the signature of the test method. The name of the case will be either the first arguments, when a list is given, or the named argument from ('title', 'message', '_') when a dictionary is given.



**Returns:**

- <b>`Callable`</b>: The decorator that binds the list of test cases with the test method.



**Raises:**

- <b>`ValueError`</b>: If there no test cases supplied.



**Examples:**
```python
from toolbox.testing import test_cases
@test_cases([
["adding numbers", [10, 20, 12], 42],
{
"title": "returning numbers",
"params": [100],
"expected": 100,
},
])
def test_addition(self, title, params, expected):
self.assertEqual(addition(*params), expected)
```




---

_This file was automatically generated via [lazydocs](https://github.com/ml-tooling/lazydocs)._
47 changes: 47 additions & 0 deletions docs/toolbox.testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!-- markdownlint-disable -->

<a href="../toolbox/testing/__init__.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `toolbox.testing`
The `testing` package provides utilities for testing purpose.

It contains:
- `test_cases(cases)` - Decorates a test case with parameters.
- `TestCase` - Extends the default Python TestCase with more assertions.



**Examples:**
```python
from toolbox import testing

class TestMyStuff(testing.TestCase)

# Parameters can be given either as list of arguments or either as dictionary.
# In both cases, the parameters must be present in the signature of the test method.
@testing.test_cases([
["adding numbers", [10, 20, 12], 42],
{
"title": "returning numbers",
"params": [100],
"expected": 100,
},
])
def test_addition(self, title, params, expected):
self.assertEqual(addition(*params), expected)

def test_list(self):
self.assertListsAlmostEqual(generator(), [1.23, 3.14, 1.61])
```

**Global Variables**
---------------
- **decorators**
- **test_case**




---

_This file was automatically generated via [lazydocs](https://github.com/ml-tooling/lazydocs)._
121 changes: 121 additions & 0 deletions docs/toolbox.testing.test_case.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<!-- markdownlint-disable -->

<a href="../toolbox/testing/test_case.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `toolbox.testing.test_case`
Extends the default Python TestCase with more assertions.



**Examples:**
```python
from toolbox import testing

class TestMyStuff(testing.TestCase)
def test_list(self):
self.assertListsAlmostEqual(generator(), [1.23, 3.14, 1.61])

def test_dict(self):
self.assertListsAlmostEqual(create_dict(), {"value": 42.4242, "PI": 3.1415})
```



---

<a href="../toolbox/testing/test_case.py#L19"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `TestCase`
Test class with additional assertions.




---

<a href="../toolbox/testing/test_case.py#L22"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `assertListsAlmostEqual`

```python
assertListsAlmostEqual(
first: Iterable[float],
second: Iterable[float],
places: int = 7
)
```

Asserts that 2 lists of float numbers are almost equal by the number of places.



**Args:**

- <b>`first`</b> (Iterable[float]): The first list to compare.
- <b>`second`</b> (Iterable[float]): The second list to compare.
- <b>`places`</b> (int, optional): The number of decimal places under what the numbers must be equal. Defaults to 7.



**Raises:**

- <b>`AssertionError`</b>: If the 2 lists are not almost equals by the number of places.



**Examples:**
```python
from toolbox import testing

class TestMyStuff(testing.TestCase)
def test_almost_equal(self):
self.assertListsAlmostEqual(generator(), [1.23, 3.14, 1.61])
```

---

<a href="../toolbox/testing/test_case.py#L79"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `assertListsNotAlmostEqual`

```python
assertListsNotAlmostEqual(
first: Iterable[float],
second: Iterable[float],
places: int = 7
)
```

Asserts that 2 lists of float numbers are not almost equal by the number of places.



**Args:**

- <b>`first`</b> (Iterable[float]): The first list to compare.
- <b>`second`</b> (Iterable[float]): The second list to compare.
- <b>`places`</b> (int, optional): The number of decimal places under what the numbers must be equal. Defaults to 7.



**Raises:**

- <b>`AssertionError`</b>: If the 2 lists are almost equals by the number of places.



**Examples:**
```python
from toolbox import testing

class TestMyStuff(testing.TestCase)
def test_almost_equal(self):
self.assertListsNotAlmostEqual(generator(), [1.23, 3.14, 1.61])
```




---

_This file was automatically generated via [lazydocs](https://github.com/ml-tooling/lazydocs)._
1 change: 1 addition & 0 deletions pydoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ rm -rf docs
lazydocs \
--ignored-modules toolbox.files.test \
--ignored-modules toolbox.logging.test \
--ignored-modules toolbox.testing.test \
--overview-file=README.md \
--validate .
rm docs/.pages
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "py-toolbox"
version = "0.3.0"
version = "0.4.0"
authors = [{ name = "Jean-Sébastien CONAN", email = "jsconan@gmail.com" }]
description = "A set of utilities for Python projects"
readme = "README.md"
Expand Down
Loading