-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Automate test runs #70
Open
mikeholler
wants to merge
2
commits into
Esterni:master
Choose a base branch
from
mikeholler:automate-test-runs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Integration Test | ||
|
||
on: | ||
push: | ||
branches: master | ||
tags: | ||
- "*" | ||
schedule: | ||
# 4 AM Central Daylight Time | ||
- cron: '0 9 * * *' | ||
|
||
jobs: | ||
flake8_py3: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v2 | ||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8.0 | ||
architecture: x64 | ||
- name: Install Dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Run Integration Tests | ||
env: | ||
IRACING_USERNAME: ${{ secrets.IRACING_USERNAME }} | ||
IRACING_PASSWORD: ${{ secrets.IRACING_PASSWORD }} | ||
run: | | ||
python -m unittest discover integration_tests/ -p "*_test.py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,32 @@ The goal of this project is to provide access to iRacing stats in a manner that | |
The contributors of this project use Discord as the primary means of communication; The [iRacing Open Wheel server](https://discord.gg/UwnhM7w) was created by the author of this project and hosts the channels for discussion there. When joining, please ask Jacob Anderson for the role to see the appropriate channels. | ||
|
||
# Documentation & Discussion | ||
|
||
All documentation for this project is available through the [Github Pages project site](https://esterni.github.io/pyracing/). | ||
|
||
# Dependencies | ||
|
||
* [httpx](https://www.python-httpx.org/) = 0.13.x | ||
|
||
# Running Tests | ||
|
||
Before running tests, you have to prepare the environment variables. | ||
This is different for windows and linux. | ||
|
||
**Windows** | ||
``` | ||
set "[email protected]" | ||
set "IRACING_PASSWORD=hunter2" | ||
``` | ||
|
||
**Linux** | ||
``` | ||
set IRACING_USERNAME="[email protected]" | ||
set IRACING_PASSWORD="hunter2" | ||
``` | ||
|
||
Running the tests is the same on both systems: | ||
|
||
# Dependancies | ||
[httpx](https://www.python-httpx.org/) = 0.13.x | ||
``` | ||
python -m unitttest discover integration_tests/ -p "*_test.py" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import asyncio | ||
import logging | ||
import os | ||
import sys | ||
import unittest | ||
|
||
from pyracing.client import Client | ||
|
||
|
||
__all__ = [ | ||
"IRacingIntegrationTest", | ||
"async_test", | ||
] | ||
|
||
logging.basicConfig( | ||
stream=sys.stdout, | ||
level=logging.INFO, | ||
datefmt="%Y-%m-%dT%H:%M:%S%Z", | ||
format="%(asctime)s [%(levelname)s] -- %(message)s" | ||
) | ||
|
||
|
||
def get_required_env(key: str) -> str: | ||
""" | ||
Get an environment variable's value, raising an exception if it isn't set. | ||
""" | ||
value = os.getenv(key) | ||
if value is None: | ||
raise EnvironmentError( | ||
f"Must set {key} environment variable to to run integration tests." | ||
) | ||
return value | ||
|
||
|
||
IRACING_USERNAME = get_required_env("IRACING_USERNAME") | ||
IRACING_PASSWORD = get_required_env("IRACING_PASSWORD") | ||
|
||
# We create a singleton client that we use for all tests to avoid constantly | ||
# re-authenticating. iRacing may see constant re-authentication as suspicious | ||
# activity, we see the disadvantages of 1) using a singleton and 2) sharing | ||
# state between tests are outweighed by being good citizens to the iRacing | ||
# platform. | ||
client = Client( | ||
username=IRACING_USERNAME, | ||
password=IRACING_PASSWORD, | ||
) | ||
|
||
|
||
def async_test(f): | ||
""" | ||
Function that can be used as a decorator for tests of async functions. | ||
|
||
For example, | ||
|
||
class MyTest(unittests.TestCase): | ||
@async_test | ||
async def test_example(self): | ||
self.assertTrue(True) | ||
|
||
:param f: the function to wrap | ||
:return: the wrapped function | ||
|
||
>>> class MyTest(unittest.TestCase): | ||
... @async_test | ||
... async def test_example(self): | ||
... self.assertTrue(True) | ||
""" | ||
def wrapper(*args, **kwargs): | ||
coro = asyncio.coroutine(f) | ||
future = coro(*args, **kwargs) | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(future) | ||
|
||
return wrapper | ||
|
||
|
||
class IRacingIntegrationTest(unittest.TestCase): | ||
""" | ||
Test service that runs against iRacing's server. | ||
""" | ||
|
||
def setUp(self) -> None: | ||
self.client = Client( | ||
username=IRACING_USERNAME, | ||
password=IRACING_PASSWORD, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the client we instantiate above if we re-instantiate here? Should we be using the singleton we created as you mentioned in the comment so we don't auth multiple times when we run more suites?