Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
flenter committed Apr 11, 2023
1 parent 1628615 commit 6734323
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 12 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
cache: "poetry"
- name: Install dependencies
run: poetry install --no-interaction --no-root --with dev
- uses: psf/black@stable
- name: Run pyright
- name: Check code formatting
uses: psf/black@stable
- name: Lint code
run: poetry run pyright
- name: run test
run: poetry run pytest
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ This package uses [poetry](https://python-poetry.org) as a package manager, with

By default, poetry will only install required dependencies, if you want to run examples, install using this command:

`poetry install --with examples`
```sh
poetry install --with examples
```

Code in this repository is:

- formatted using [black](https://black.readthedocs.io/en/stable/).
- contains type definitions (which are linted by [pyright](https://microsoft.github.io/pyright/))
- tested using [pytest](https://docs.pytest.org/)

In order to run these tools locally you have to install them, you can install them using poetry:

Code in this repository is formatted using [black](https://black.readthedocs.io/en/stable/) and contains type definitions (which are linted by [pyright](https://microsoft.github.io/pyright/))
```sh
poetry install --with dev
```

After that you can run the tools individually

```sh
# Formatting using black
poetry run black .
# Lint using pyright
poetry run pyright
# Run the tests using pytest
poetry run pytest
```
74 changes: 70 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ optional = true

[tool.poetry.group.dev.dependencies]
pyright = "^1.1.302"
pytest = "^7.3.0"

[tool.poetry.group.examples]
optional = true
Expand Down
10 changes: 6 additions & 4 deletions src/test_prometheus_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

# Defaults to localhost:9090
class TestPrometheusUrlGeneratorDefault(unittest.TestCase):
"""Test the prometheus url generator with default values."""

def setUp(self):
self.generator = Generator("myFunction", "myModule")

def test_create_prometheus_url(self):
"""Test that the prometheus url is created correctly."""
url = self.generator.create_prometheus_url("myQuery")
self.assertTrue(
url.startswith("http://localhost:9090/graph?g0.expr=")
Expand All @@ -17,18 +20,17 @@ def test_create_prometheus_url(self):

# Creates proper urls when given a custom base URL
class TestPrometheusUrlGeneratorCustomUrl(unittest.TestCase):
"""Test the prometheus url generator with a custom base URL."""

def setUp(self):
self.generator = Generator(
"myFunction", "myModule", base_url="http://localhost:9091"
)

def test_create_prometheus_url(self):
"""Test that the prometheus url is created correctly."""
url = self.generator.create_prometheus_url("myQuery")
self.assertTrue(
url.startswith("http://localhost:9091/graph?g0.expr=")
) # Make sure the base URL is correct
self.assertIn("myQuery", url) # Make sure the query is included in the URL


if __name__ == "__main__":
unittest.main()

0 comments on commit 6734323

Please sign in to comment.