Skip to content

Commit

Permalink
activate github actions (comsysto#45)
Browse files Browse the repository at this point in the history
* activate github actions
  • Loading branch information
pernpas authored Aug 4, 2023
1 parent f5ffb19 commit 417c962
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Run tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

env:
DB_NAME: gis
DB_HOST: localhost
DB_PORT: 54322
DB_USER: docker
DB_PASSWORD: docker

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install -r requirements.txt
pip install -r test/requirements.txt
- name: Test with pytest
run: |
python -m unittest discover test
6 changes: 4 additions & 2 deletions test/pipelines/de/test_bna_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from unittest import TestCase

from charging_stations_pipelines.pipelines.de.bna_crawler import get_bna_data
from test.shared import skip_if_github


class Test(TestCase):

@skip_if_github
def test_get_bna_data(self):
path_to_temp_file = Path(__file__).parent.parent.parent.parent.joinpath("data/bna_temp.xlsx")
get_bna_data(str(path_to_temp_file))
actual_file_size = os.path.getsize(path_to_temp_file)
os.remove(path_to_temp_file)
self.assertTrue(actual_file_size > 6000000) # 6MB

self.assertTrue(actual_file_size > 6000000) # 6MB
3 changes: 3 additions & 0 deletions test/pipelines/fr/test_france.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
from unittest import TestCase

from charging_stations_pipelines.pipelines.fr.france import FraPipeline
from test.shared import skip_if_github


class TestFraPipeline(TestCase):

@skip_if_github
def test_download_france_gov_file(self):
temp_target = Path(__file__).parent.parent.parent.parent.joinpath("data/fra_temp.csv")
FraPipeline.download_france_gov_file(temp_target)
Expand Down
12 changes: 12 additions & 0 deletions test/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def get_config() -> configparser.RawConfigParser:
config.read(os.path.join(os.path.join(current_dir, "config", "config.ini")))
return config


def create_station() -> Station:
station = Station()
station.country_code = "DE"
Expand All @@ -50,6 +51,7 @@ def create_station() -> Station:
station.charging = create_charging()
return station


def create_address() -> Address:
state_old: str
country: str
Expand All @@ -62,6 +64,7 @@ def create_address() -> Address:
address.country = ("DE",)
return address


def create_charging() -> Charging:
charging = Charging()
charging.station_id = 1
Expand All @@ -75,3 +78,12 @@ def create_charging() -> Charging:
charging.max_kw = None
return charging


def skip_if_github(func):
def wrapper(*args, **kwargs):
if os.getenv("GITHUB_WORKFLOW") is not None:
print(f"Skipped test {func.__name__} because it is running on Github Actions")
return
return func(*args, **kwargs)

return wrapper

0 comments on commit 417c962

Please sign in to comment.