Skip to content
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

Fixing issue #22 by adding GIthub action for unit tests #114

Merged
merged 24 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: python-unit-tests
on:
push:
pull_request:
types:
- opened
- edited
- reopened
- ready_for_review

jobs:
python-unit-tests:
name: Python Unit Tests
runs-on: ubuntu-20.04

steps:
- name: Clone repo
uses: actions/checkout@v3

- name: Setup SSH Keys and known_hosts
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}"
mkdir ~/.ssh/
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
- name: Setup git
run: |
git config --global user.email "[email protected]"
git config --global user.name "Github Actions"
- name: Install up Python 3.8
uses: actions/setup-python@v3
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r dnas/requirements.txt
- name: Run the Python unit tests
working-directory: /home/runner/work/dfz_name_and_shame/dfz_name_and_shame/
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
sudo mkdir /media/usb0
sudo chmod 777 /media/usb0
python3 dnas/tests/test_git.py -v
python3 dnas/tests/test_bogon_asn.py -v
python3 dnas/tests/test_bogon_ip.py -v
python3 dnas/tests/test_mrt_archive.py -v
python3 dnas/tests/test_mrt_entry.py -v
python3 dnas/tests/test_mrt_getter.py -v
python3 dnas/tests/test_mrt_parser.py -v
python3 dnas/tests/test_mrt_splitter.py -v
python3 dnas/tests/test_mrt_stats.py -v
18 changes: 10 additions & 8 deletions dnas/dnas/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,16 @@ def commit(msg: str = None):
)
if ret.returncode != 0:
if "Your branch is up to date with" in ret.stdout.decode():
logging.debug(f"Nothing committed, no changed with remote")
return
raise ChildProcessError(
f"Couldn't commit staged changes to git in {cfg.GIT_BASE}\n"
f"args: {ret.args}\n"
f"stdout: {ret.stdout.decode()}\n"
f"stderr: {ret.stderr.decode()}"
)
raise ChildProcessError(
"Nothing committed, no changes with remote"
)
else:
raise ChildProcessError(
f"Couldn't commit staged changes to git in {cfg.GIT_BASE}\n"
f"args: {ret.args}\n"
f"stdout: {ret.stdout.decode()}\n"
f"stderr: {ret.stderr.decode()}"
)
logging.debug(f"Committed to git in {cfg.GIT_BASE}: {msg}")

@staticmethod
Expand Down
8 changes: 4 additions & 4 deletions dnas/dnas/mrt_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ def valid_ym(ym: str = None):
running in 2030, I'm a realist :(
"""
if not re.match(
"^(1999|20[0-2][0-9])(0[1-9]|1[0-2])$", ym
r"^(1999|20[0-2][0-9])(0[1-9]|1[0-2])$", ym
):
raise ValueError(
f"Invalid year and month format: {ym}. "
Expand Down Expand Up @@ -981,7 +981,7 @@ def valid_ymd(ymd: str = None):
running in 2030, I'm a realist :(
"""
if not re.match(
"^(1999|20[0-2][0-9])(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])$",
r"^(1999|20[0-2][0-9])(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])$",
ymd
):
raise ValueError(
Expand Down Expand Up @@ -1012,8 +1012,8 @@ def valid_ymd_hm(ymd_hm: str = None):
"""

if not re.match(
("^(1999|20[0-2][0-9])(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\."
"([0-1][0-9]|2[0-3])([0-5][0-9])$"), ymd_hm
(r"^(1999|20[0-2][0-9])(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\."
r"([0-1][0-9]|2[0-3])([0-5][0-9])$"), ymd_hm
):
raise ValueError(
f"Invalid year, month, day, hour, minute format: {ymd_hm}. "
Expand Down
Loading