mirror of
https://github.com/scito/extract_otp_secret_keys.git
synced 2025-12-06 06:44:57 +01:00
ci: setup testing for linux, macos and windows platforms
- fix ci for windows: remove bash if/fi - exlucde failing test from windows - enable scheduled tests - use --use-pep517 for pip install: avoid deprecation message - exlcude windows-latest and pypy-3.9 since there is a problem with installing (missing zlib.h)
This commit is contained in:
parent
ca4a0bc7d2
commit
7af631ff1e
4 changed files with 62 additions and 14 deletions
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
|
|
@ -1,14 +1,23 @@
|
|||
name: tests
|
||||
|
||||
on: [push]
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '*/15 * * * *'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.7", "pypy-3.7", "3.8", "pypy-3.8", "3.9", "pypy-3.9", "3.10", "3.11", "3.x"]
|
||||
platform: [ubuntu-latest, macos-latest, windows-latest]
|
||||
exclude:
|
||||
- platform: windows-latest
|
||||
- python-version: [pypy-3.9]
|
||||
|
||||
runs-on: ${{ matrix.platform }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
|
@ -20,7 +29,7 @@ jobs:
|
|||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install flake8 pytest
|
||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||
pip install --use-pep517 -r requirements.txt
|
||||
- name: Lint with flake8
|
||||
run: |
|
||||
# stop the build if there are Python syntax errors or undefined names
|
||||
|
|
@ -28,5 +37,4 @@ jobs:
|
|||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
||||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=200 --statistics
|
||||
- name: Test with pytest
|
||||
run: |
|
||||
pytest
|
||||
run: pytest
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@
|
|||
|
||||
from utils import read_csv, read_csv_str, read_json, read_json_str, remove_files, remove_dir_with_files, read_file_to_str, file_exits
|
||||
from os import path
|
||||
from pytest import raises
|
||||
from pytest import raises, mark
|
||||
from io import StringIO
|
||||
from sys import platform
|
||||
|
||||
import extract_otp_secret_keys
|
||||
|
||||
|
|
@ -38,7 +39,7 @@ def test_extract_stdout(capsys):
|
|||
|
||||
|
||||
def test_extract_stdin_stdout(capsys, monkeypatch):
|
||||
# Prepare
|
||||
# Arrange
|
||||
monkeypatch.setattr('sys.stdin', StringIO(read_file_to_str('example_export.txt')))
|
||||
|
||||
# Act
|
||||
|
|
@ -78,7 +79,30 @@ def test_extract_csv_stdout(capsys):
|
|||
cleanup()
|
||||
|
||||
# Act
|
||||
extract_otp_secret_keys.main(['-q', '-c', '-', 'example_export.txt'])
|
||||
extract_otp_secret_keys.main(['-c', '-', 'example_export.txt'])
|
||||
|
||||
# Assert
|
||||
assert not file_exits('test_example_output.csv')
|
||||
|
||||
captured = capsys.readouterr()
|
||||
|
||||
expected_csv = read_csv('example_output.csv')
|
||||
actual_csv = read_csv_str(captured.out)
|
||||
|
||||
assert actual_csv == expected_csv
|
||||
assert captured.err == ''
|
||||
|
||||
# Clean up
|
||||
cleanup()
|
||||
|
||||
|
||||
def test_extract_stdin_and_csv_stdout(capsys, monkeypatch):
|
||||
# Arrange
|
||||
cleanup()
|
||||
monkeypatch.setattr('sys.stdin', StringIO(read_file_to_str('example_export.txt')))
|
||||
|
||||
# Act
|
||||
extract_otp_secret_keys.main(['-c', '-', '-'])
|
||||
|
||||
# Assert
|
||||
assert not file_exits('test_example_output.csv')
|
||||
|
|
@ -128,7 +152,7 @@ def test_keepass_csv_stdout(capsys):
|
|||
cleanup()
|
||||
|
||||
# Act
|
||||
extract_otp_secret_keys.main(['-q', '-k', '-', 'test/example_export_only_totp.txt'])
|
||||
extract_otp_secret_keys.main(['-k', '-', 'test/example_export_only_totp.txt'])
|
||||
|
||||
# Assert
|
||||
expected_totp_csv = read_csv('example_keepass_output.totp.csv')
|
||||
|
|
@ -199,7 +223,7 @@ def test_extract_json_stdout(capsys):
|
|||
cleanup()
|
||||
|
||||
# Act
|
||||
extract_otp_secret_keys.main(['-q', '-j', '-', 'example_export.txt'])
|
||||
extract_otp_secret_keys.main(['-j', '-', 'example_export.txt'])
|
||||
|
||||
# Assert
|
||||
expected_json = read_json('example_output.json')
|
||||
|
|
@ -246,7 +270,7 @@ Type: totp
|
|||
assert captured.out == expected_stdout
|
||||
assert captured.err == ''
|
||||
|
||||
|
||||
@mark.skipif(platform.startswith("win"), reason="This test is not supported on Windows.")
|
||||
def test_extract_printqr(capsys):
|
||||
# Act
|
||||
extract_otp_secret_keys.main(['-p', 'example_export.txt'])
|
||||
|
|
@ -324,6 +348,20 @@ def test_extract_help(capsys):
|
|||
assert pytest_wrapped_e.value.code == 0
|
||||
|
||||
|
||||
def test_extract_no_arguments(capsys):
|
||||
# Act
|
||||
with raises(SystemExit) as pytest_wrapped_e:
|
||||
extract_otp_secret_keys.main([])
|
||||
|
||||
# Assert
|
||||
captured = capsys.readouterr()
|
||||
|
||||
expected_err_msg = 'error: the following arguments are required: infile'
|
||||
|
||||
assert expected_err_msg in captured.err
|
||||
assert captured.out == ''
|
||||
|
||||
|
||||
def test_verbose_and_quiet(capsys):
|
||||
with raises(SystemExit) as pytest_wrapped_e:
|
||||
# Act
|
||||
|
|
@ -333,7 +371,7 @@ def test_verbose_and_quiet(capsys):
|
|||
captured = capsys.readouterr()
|
||||
|
||||
assert len(captured.err) > 0
|
||||
assert 'The arguments --verbose and --quiet are mutually exclusive.' in captured.err
|
||||
assert 'error: argument --quiet/-q: not allowed with argument --verbose/-v' in captured.err
|
||||
assert captured.out == ''
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import io
|
|||
from contextlib import redirect_stdout
|
||||
from utils import read_csv, read_json, remove_file, remove_dir_with_files, Capturing, read_file_to_str
|
||||
from os import path
|
||||
from sys import platform
|
||||
|
||||
import extract_otp_secret_keys
|
||||
|
||||
|
|
@ -139,6 +140,7 @@ Type: totp
|
|||
self.assertEqual(actual_output, expected_output)
|
||||
|
||||
def test_extract_printqr(self):
|
||||
if platform.startswith("win"): self.skipTest("This test is not supported on Windows.")
|
||||
out = io.StringIO()
|
||||
with redirect_stdout(out):
|
||||
extract_otp_secret_keys.main(['-p', 'example_export.txt'])
|
||||
|
|
|
|||
|
|
@ -181,11 +181,11 @@ eval "$cmd"
|
|||
|
||||
$PIP --version
|
||||
|
||||
cmd="$PIP install -U -r requirements.txt"
|
||||
cmd="$PIP install --use-pep517 -U -r requirements.txt"
|
||||
if $interactive ; then askContinueYn "$cmd"; fi
|
||||
eval "$cmd"
|
||||
|
||||
cmd="$PIP install -U -r requirements-dev.txt"
|
||||
cmd="$PIP install --use-pep517 -U -r requirements-dev.txt"
|
||||
if $interactive ; then askContinueYn "$cmd"; fi
|
||||
eval "$cmd"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue