Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Update jinja and socketio dependencies, add basic CI testing (#5)
Browse files Browse the repository at this point in the history
- Set flask secret
- Update socketio dependencies and add very basic tests
- Github actions workflow
  • Loading branch information
Mark90 authored Apr 9, 2021
1 parent 3bc476f commit 1629e6c
Show file tree
Hide file tree
Showing 9 changed files with 428 additions and 76 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Linting and testing

on: [push, pull_request]

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install pipenv
run: |
python -m pip install --upgrade pip
pip install pipenv
- id: cache-pipenv
uses: actions/cache@v1
with:
path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
- name: Install dependencies
if: steps.cache-pipenv.outputs.cache-hit != 'true'
run: |
pipenv install --deploy --dev
- run: pipenv run isort --recursive --diff .
- run: pipenv run black --check .
- run: pipenv run flake8
- run: pipenv run pytest
10 changes: 8 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pytest = "*"
black = "*"
flake8 = "*"
isort = "*"

[packages]
flask = "==1.1.*"
textfsm = "==1.1.*"
eventlet = "==0.25.*"
Flask-SocketIO = "==4.2.*"
flask-socketio = "*"
eventlet = "*"

[requires]
python_version = "3.8"

[pipenv]
allow_prereleases = true
400 changes: 339 additions & 61 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# pytest root
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import platform
import secrets
from datetime import datetime
from io import StringIO

Expand All @@ -10,7 +11,7 @@
BIND, HOST, PORT = "127.0.0.1", "127.0.0.1", 5001

app = Flask(__name__)
app.config["SECRET_KEY"] = "secret!"
app.config["SECRET_KEY"] = secrets.token_bytes(16)
socketio = SocketIO(app)


Expand Down
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[tool.black]
line-length = 90
[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 88
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
extend-ignore = E203, W503
12 changes: 2 additions & 10 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@
<script src="https://unpkg.com/split.js/dist/split.min.js"></script>

<!-- socket.io -->
<script
src="//code.jquery.com/jquery-1.12.4.min.js"
integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
crossorigin="anonymous"
></script>
<script
src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"
integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I="
crossorigin="anonymous"
></script>
<script src="//code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script src="https://cdn.socket.io/3.1.3/socket.io.min.js" integrity="sha384-cPwlPLvBTa3sKAgddT6krw0cJat7egBga3DJepJyrLl4Q9/5WLra3rrnMcyTyOnh" crossorigin="anonymous"></script>

<link rel="stylesheet" href="../static/style.css" />
<script src="../static/app.js"></script>
Expand Down
34 changes: 34 additions & 0 deletions test/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from textwrap import dedent

import pytest
import textfsm

from main import parse_textfsm


def test_parse_textfsm_ok():
template = dedent(
r"""
Value FirstName ([\w]+)
Value LastName ([\w]+)
Start
^${FirstName}.${LastName}
"""
)
output, _ = parse_textfsm("a b c", template)
assert {"FirstName": "a", "LastName": "b"} in output


def test_parse_textfsm_exc():
template = dedent(
r"""
Value firstName ([\w]+)
Value LastName ([\w]+)
Start
^${FirstName}.${LastName}
"""
)
with pytest.raises(textfsm.Error):
output, _ = parse_textfsm("a b c", template)

0 comments on commit 1629e6c

Please sign in to comment.