Skip to content

Commit

Permalink
add pydantic tests (#127)
Browse files Browse the repository at this point in the history
* add pydantic tests

* update changelog

* update readme
  • Loading branch information
ap-- authored Aug 2, 2023
1 parent 1c5cd91 commit 7bf8d04
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- improved azure test separation (#123).

### Added
- tests to confirm pydantic `BaseSettings` behavior (#127).

## [0.0.24] - 2023-06-19
### Added
- started a changelog to keep track of significant changes (#118).
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ For more examples, see the [example notebook here](notebooks/examples.ipynb)
Other fsspec-compatible filesystems may also work, but are not supported and tested.
Contributions for new filesystems are welcome!

### Class inheritance diagram
### Class hierarchy

The individual `UPath` subclasses relate in the following way with `pathlib` classes:

Expand Down Expand Up @@ -116,10 +116,15 @@ flowchart TB
style s1 fill:none,stroke:#ca0020,stroke-width:3px,stroke-dasharray: 3 3,color:#ca0020
```

`PosixUPath` and `WindowsUPath` subclasses are 100% compatible with the `PosixPath` and `WindowsPath` classes of their
When instantiating `UPath` the returned instance type depends on the path that was provided to the constructor.
For "URI"-style paths, `UPath` returns a subclass instance corresponding to the supported `fsppec` protocol, defined
by the URI-scheme. If there is no specialized subclass implementation available, `UPath` with return a `UPath` instance
and raise a warning that the protocol is currently not being tested in the test-suite, and correct behavior is not
guaranteed.
If a local path is provided, `UPath` will return a `PosixUPath` or `WindowsUPath` instance.
These two subclasses are 100% compatible with the `PosixPath` and `WindowsPath` classes of their
specific Python version, and are tested against all relevant tests of the CPython pathlib test-suite.


## Contributing

Contributions are very welcome.
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ dev =
cheroot
hadoop-test-cluster
pyarrow
pydantic
pydantic-settings

[options.package_data]
upath =
Expand Down
Empty file.
17 changes: 17 additions & 0 deletions upath/tests/third_party/test_pydantic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

try:
from pydantic import BaseConfig
from pydantic_settings import BaseSettings
except ImportError:
BaseConfig = BaseSettings = None
pytestmark = pytest.mark.skip(reason="requires pydantic")

from upath.core import UPath


def test_pydantic_settings_local_upath():
class MySettings(BaseSettings):
example_path: UPath = UPath(__file__)

assert isinstance(MySettings().example_path, UPath)

0 comments on commit 7bf8d04

Please sign in to comment.