Skip to content

Commit

Permalink
Better tests. (#307)
Browse files Browse the repository at this point in the history
* Better tests.

* Seperate tests under classes.
  • Loading branch information
nxtlo authored Dec 9, 2023
1 parent 8d619aa commit 011e24c
Show file tree
Hide file tree
Showing 4 changed files with 421 additions and 369 deletions.
57 changes: 32 additions & 25 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Branches should look something like this.
* This should be for any type of PR thats not mentioned under.

* `meta/small-branch-info`
* This should be for typos, documentation, markdowns, typing issues, etc.
* This should be for typos, documentation, markdowns, minor issues.

* `feature/a-small-feature-info`
* This should be for feature implementation and requires more tasks and reviews only.
Expand All @@ -18,27 +18,25 @@ Branches should look something like this.


## Nox
nox is a helper to run all the tests for you. We have 8 tests

* format
* Formats and sorts the source files using ruff and isort.
* lint
* Flake8 linting.
* type_check
* Used for type checking the source files using mypy.
* gen_stubs
* Used for generating stub files.
* pdoc
* Docs generator.
* pytest
* for testing and mocking aiobungie itself.
* spell
* Source file text spell checks.
* client
* Which are real tests for the base client.
For this you'll need to export your token in an env variable like this `export CLIENT_TOKEN='TOKEN'` for unix based systems.

If you're on windows, I recommend making a `.env` file in the root directory and write this `CLIENT_TOKEN='YOUR_TOKEN'`
nox is a helper to run all the tests for you. We currently have 8 tests.

* **format**: Formats and sorts the source files using `ruff` and `isort`.

* **lint**: `flake8` linting.

* **type_check**: Used for type checking the source files using `mypy`.

* **gen_stubs**: Used for generating stub files.

* **pdoc**: Docs generator.

* **pytest**: for testing and mocking aiobungie's `objects`.

* **spell**: Checks and fixes spelling mistakes in source files using `codespell`.

* **client**:
Which are real HTTP tests for the base client, You need to configure something before you start.
Check `Raw Client tests` section below.

You can list all available session by typing `nox -l`

Expand All @@ -61,7 +59,7 @@ if typing.TYPE_CHECKING:
Foo: tuple[str, ...] | str | None = None

# We annotate immutable sequence like objects with `collections.abc.Sequence[T]`
def get(components: collections.Sequence[aiobungie.Object]) -> str:
def get(components: collections.Sequence[Object]) -> str:
components[0] = ... # Error.
return ",".join(str(c) for c in components)

Expand All @@ -79,10 +77,19 @@ Foo: Union[Tuple[Optional[str], ...], int] = 0
```

## [Type checking](https://www.python.org/dev/peps/pep-0484/)
This project is statically typed and uses mypy for the type checking, So everything must be type annotated.
This project is statically typed and uses `mypy` for the type checking, So everything must be type annotated.

## Raw Client tests
You may write tests for your new changes in `tests/aiobungie/test_client.py`.
You may write tests for your new changes in `tests/aiobungie/test_client.py` under the specified class.

* Export your token as an env variable like this `export CLIENT_TOKEN='TOKEN'` for unix based systems.

If you're on windows, I recommend making a `.env` file in the root directory and write this `CLIENT_TOKEN='YOUR_TOKEN'`

`python-dotenv` will be used to parse the token from the `.env` file so you don't have to export it manually.
* Go to `tests/config.py` and set your account details there.
This is optional unless if you want to test your own data.


## Opening your first PR

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ client = aiobungie.RESTClient("...")
async def main() -> None:
async with client:
# Download and open the JSON manifest.
manifest = await client.download_json_manifest(name="latest_manifest", path='/home/.../')
manifest = await client.download_json_manifest(name="latest_manifest")
with manifest.open("r") as file:
data = file.read()

Expand Down Expand Up @@ -125,3 +125,6 @@ If you have used aiobungie and want to show your work, Feel free to Open a PR in
* BungieAPI Discord: [Here](https://discord.gg/vP7VC7TKUG)
* Official Bungie Documentation: [Here](https://bungie-net.github.io/multi/index.html)
* Bungie Developer Portal: [Here](https://www.bungie.net/en/Application)

### Additional information
If you have any question you can either open a blank issue, open a new github discussion, or just tag me in BungieAPI discord server.
Loading

0 comments on commit 011e24c

Please sign in to comment.