Skip to content

Commit

Permalink
wip! setup GitHub Actions to run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dseomn committed Aug 19, 2023
1 parent 901dc37 commit 5a373e0
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 4 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

on:
push: {}
schedule:
- cron: '11 21 * * 2'

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
# TODO(https://github.com/google/pytype/issues/1308): Switch to 3.11 or
# whatever is in Debian stable.
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install absl-py
- name: Run pytype
run: |
pip install pytype
pytype
- name: Test
run: |
pip install pytest pytest-cov
pytest \
--cov=. \
--cov-branch \
--cov-report=term-missing \
--capture=no \
-v \
-o log_cli=true \
--log-cli-level=DEBUG
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[tool.pytype]
inputs = ["."]
exclude = [
"salt/file/network/home_router/update-nftables.py",
]
jobs = "auto"
7 changes: 6 additions & 1 deletion salt/file/todo/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ def __post_init__(self):
except ValueError as e:
raise ValueError(f'Invalid start {self.start!r}') from e
try:
self.recurrence_rule_parsed = ( #
recurrence_rule_parsed = ( #
None if self.recurrence_rule is None else
dateutil.rrule.rrulestr(self.recurrence_rule,
dtstart=self.start_parsed))
except ValueError as e:
raise ValueError(
f'Invalid recurrence_rule {self.recurrence_rule!r}') from e
if isinstance(recurrence_rule_parsed, dateutil.rrule.rruleset):
raise ValueError(
'recurrence_rule should be an rrule, not an rruleset: '
f'{self.recurrence_rule!r}')
self.recurrence_rule_parsed = recurrence_rule_parsed


@dataclasses.dataclass
Expand Down
11 changes: 11 additions & 0 deletions salt/file/todo/todo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ def _assert_messages_sent(self, *expected_messages: _Message):
error_class=ValueError,
error_regex='Invalid recurrence_rule',
),
dict(
testcase_name='config_invalid_recurrence_rule_is_rruleset',
config=dict(some_group=dict(todos=dict(some_todo=dict(
email_headers={},
summary='foo',
start='20010101T000000Z',
recurrence_rule='RRULE:FREQ=DAILY\nRRULE:FREQ=DAILY',
)))),
error_class=ValueError,
error_regex='not an rruleset',
),
dict(
testcase_name='state_unexpected_key',
config={},
Expand Down
6 changes: 3 additions & 3 deletions salt/file/xmpp/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
ejabberd.service.
"""

from collections.abc import Generator, Sequence
import contextlib
import os
import shutil
import subprocess
from typing import ContextManager, Sequence


def _wait_and_check(popen: subprocess.Popen) -> None:
Expand Down Expand Up @@ -68,7 +68,7 @@ def _ejabberd_tempfile(
*,
nsenter: Sequence[str],
copy_to: str,
) -> ContextManager[str]:
) -> Generator[str, None, None]:
with contextlib.ExitStack() as exit_stack:
tempfile_ = subprocess.run(
(*nsenter, 'mktemp'),
Expand Down Expand Up @@ -96,7 +96,7 @@ def _ejabberd_tempdir(
*,
nsenter: Sequence[str],
copy_to: str,
) -> ContextManager[str]:
) -> Generator[str, None, None]:
with contextlib.ExitStack() as exit_stack:
tempdir = subprocess.run(
(*nsenter, 'mktemp', '-d'),
Expand Down

0 comments on commit 5a373e0

Please sign in to comment.