Skip to content

Commit 37631e8

Browse files
authored
Merge pull request #10 from rkdarst/add-gh-actions-tests
Add Github Actions to run tests
2 parents 90ba986 + cf800da commit 37631e8

7 files changed

Lines changed: 157 additions & 95 deletions

File tree

.github/workflows/test.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
default:
7+
runs-on: ${{ matrix.os }}-latest
8+
strategy:
9+
matrix:
10+
os: [ubuntu]
11+
python-version: [3.10]
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install flake8 pytest
24+
pip install -r requirements.txt -r requirements.dev.txt
25+
26+
- name: Lint
27+
run: pre-commit run --all-files --show-diff-on-failure --color always
28+
29+
- name: Test
30+
run: |
31+
PYTHONPATH=. pytest

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Install pre-commit hooks via
2+
# pre-commit install
3+
4+
repos:
5+
- repo: https://github.com/psf/black
6+
rev: 21.5b1
7+
hooks:
8+
- id: black
9+
- repo: https://gitlab.com/pycqa/flake8
10+
rev: 3.8.4
11+
hooks:
12+
- id: flake8
13+
pass_filenames: true
14+
- repo: https://github.com/pycqa/isort
15+
rev: 5.10.1
16+
hooks:
17+
- id: isort

requirements.dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
black==21.5b1
2+
pre-commit>=2.12

tests/test_calendar.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,44 @@
22
import io
33
import textwrap
44

5-
from util import parse_yaml
6-
75
from yaml2ics import events_to_calendar, files_to_calendar
86

97

108
def test_calendar_structure():
119
cal = events_to_calendar([])
1210
cal_str = cal.serialize()
13-
assert cal_str.startswith('BEGIN:VCALENDAR')
14-
assert cal_str.endswith('END:VCALENDAR')
11+
assert cal_str.startswith("BEGIN:VCALENDAR")
12+
assert cal_str.endswith("END:VCALENDAR")
13+
1514

1615
def test_calendar_event():
1716
cal = files_to_calendar(
18-
[io.StringIO(textwrap.dedent(
19-
'''
17+
[
18+
io.StringIO(
19+
textwrap.dedent(
20+
"""
2021
events:
2122
- summary: Earth Day
2223
begin: 2021-04-22
2324
url: https://earthday.org
2425
location: Earth
25-
'''
26-
))]
26+
"""
27+
)
28+
)
29+
]
2730
)
2831
cal_str = cal.serialize()
29-
assert cal_str.startswith('BEGIN:VCALENDAR')
30-
assert 'SUMMARY:Earth Day' in cal_str
31-
assert cal_str.endswith('END:VCALENDAR')
32+
assert cal_str.startswith("BEGIN:VCALENDAR")
33+
assert "SUMMARY:Earth Day" in cal_str
34+
assert cal_str.endswith("END:VCALENDAR")
35+
3236

3337
def test_calendar_default_timezone():
3438
cal = files_to_calendar(
35-
[io.StringIO(textwrap.dedent(
36-
'''
39+
[
40+
io.StringIO(
41+
textwrap.dedent(
42+
"""
3743
meta:
3844
tz: Europe/Helsinki
3945
@@ -48,23 +54,25 @@ def test_calendar_default_timezone():
4854
4955
- summary: Earth day (all day)
5056
begin: 2022-04-22
51-
'''
52-
))]
57+
"""
58+
)
59+
)
60+
]
5361
)
5462
cal_str = cal.serialize()
55-
assert cal_str.startswith('BEGIN:VCALENDAR')
56-
assert 'SUMMARY:New year' in cal_str
63+
assert cal_str.startswith("BEGIN:VCALENDAR")
64+
assert "SUMMARY:New year" in cal_str
5765
# It is possible that the ics-py TZID string changes, but hopefully this
5866
# substring is fairly safe to test against.
59-
assert 'Europe/Helsinki:20220101T000000' in cal_str
67+
assert "Europe/Helsinki:20220101T000000" in cal_str
6068
# Second event: explicit UTC offset specified.
6169
assert '"UTC+02:00":20220201T000000' in cal_str
62-
assert cal_str.endswith('END:VCALENDAR')
70+
assert cal_str.endswith("END:VCALENDAR")
6371

6472
# Test again by normalizing to UTC. Helsinki is two hours ahead, so the
6573
# times should be 22:00:00.
6674
cal.normalize(datetime.timezone.utc)
67-
cal_norm_str = cal.serialize()
75+
cal_norm_str = cal.serialize() # noqa: F841
6876
# 1 Feb midnight
69-
assert 'DTSTART:20211231T220000Z' # 1 jan
70-
assert 'DTSTART:20220131T220000Z' # 1 feb
77+
assert "DTSTART:20211231T220000Z" # 1 jan
78+
assert "DTSTART:20220131T220000Z" # 1 feb

tests/test_events.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,97 +6,96 @@
66
def test_basic_structure():
77
event = event_from_yaml(
88
parse_yaml(
9-
'''
9+
"""
1010
summary: Earth Day
1111
begin: 2021-04-22
1212
url: https://earthday.org
1313
location: Earth
14-
'''
14+
"""
1515
)
1616
)
1717

1818
# All lines must be separated by CRLF
1919
event_str = event.serialize()
20-
lines = event_str.split('\n')
20+
lines = event_str.split("\n")
2121
for line in lines[:-1]:
22-
assert line.endswith('\r')
23-
assert 'SUMMARY:Earth Day' in event_str
24-
assert 'URL:https://earthday.org' in event_str
25-
assert 'LOCATION:Earth' in event_str
22+
assert line.endswith("\r")
23+
assert "SUMMARY:Earth Day" in event_str
24+
assert "URL:https://earthday.org" in event_str
25+
assert "LOCATION:Earth" in event_str
2626
# All events must have a DTSTAMP
27-
assert 'DTSTAMP' in event_str
27+
assert "DTSTAMP" in event_str
2828

2929

3030
def test_all_day_event():
3131
event = event_from_yaml(
3232
parse_yaml(
33-
'''
33+
"""
3434
summary: Earth Day
3535
begin: 2021-04-22
3636
url: https://earthday.org
37-
'''
37+
"""
3838
)
3939
)
4040
event_str = event.serialize()
41-
assert event_str.startswith('BEGIN:VEVENT')
42-
assert event_str.endswith('END:VEVENT')
43-
assert 'DTSTART;VALUE=DATE:20210422' in event_str
41+
assert event_str.startswith("BEGIN:VEVENT")
42+
assert event_str.endswith("END:VEVENT")
43+
assert "DTSTART;VALUE=DATE:20210422" in event_str
4444
# ics 0.8.0 does have DTEND that is the next day.
45-
#assert 'DTEND' not in event_str
45+
# assert 'DTEND' not in event_str
4646

4747

4848
def test_rrule():
4949
event = event_from_yaml(
5050
parse_yaml(
51-
'''
51+
"""
5252
summary: Earth Day
5353
begin: 2021-04-22
5454
url: https://earthday.org
5555
repeat:
5656
interval:
5757
years: 1
5858
until: 2030-04-22
59-
'''
59+
"""
6060
)
6161
)
6262
event_str = event.serialize()
6363
# DTEND exists and is the next day, calendar tools import this
6464
# correctly as being a one-day event
65-
assert 'RRULE:FREQ=YEARLY;UNTIL=20300422T000000' in event_str
65+
assert "RRULE:FREQ=YEARLY;UNTIL=20300422T000000" in event_str
6666

6767

6868
def test_event_with_time_range():
6969
event = event_from_yaml(
7070
parse_yaml(
71-
'''
71+
"""
7272
summary: Event of the Century
7373
begin: 2021-09-21 15:00:00 -07:00
7474
end: 2021-09-21 15:30:00 -07:00
7575
description: |
7676
Meet the team on the northern side of the field.
77-
'''
77+
"""
7878
)
7979
)
8080
event_str = event.serialize()
81-
assert 'DTSTART' in event_str
82-
assert 'DTEND' in event_str
81+
assert "DTSTART" in event_str
82+
assert "DTEND" in event_str
8383

8484

8585
def test_event_with_duration():
8686
event = event_from_yaml(
8787
parse_yaml(
88-
'''
88+
"""
8989
summary: Event of the Century
9090
begin: 2021-09-21 15:00:00 -07:00
9191
duration:
9292
minutes: 30
9393
description: |
9494
Meet the team on the northern side of the field.
95-
'''
95+
"""
9696
)
9797
)
9898
event_str = event.serialize()
99-
assert 'DURATION:PT30M' in event_str
100-
assert 'DTEND' not in event_str
101-
assert 'DTSTART' in event_str
102-
99+
assert "DURATION:PT30M" in event_str
100+
assert "DTEND" not in event_str
101+
assert "DTSTART" in event_str

tests/util.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import yaml
21
import textwrap
32

3+
import yaml
4+
45

56
def parse_yaml(yaml_str):
6-
return yaml.load(
7-
textwrap.dedent(yaml_str).strip(),
8-
Loader=yaml.FullLoader
9-
)
7+
return yaml.load(textwrap.dedent(yaml_str).strip(), Loader=yaml.FullLoader)

0 commit comments

Comments
 (0)