From cba5aa4e82f88deb07192cfd3ad8baea314601e1 Mon Sep 17 00:00:00 2001 From: chang-ning Date: Wed, 21 Mar 2018 22:38:44 +0800 Subject: [PATCH] add pydocstyle check --- Makefile | 7 +++++-- app.py | 11 ++++++----- app_test.py | 12 +++++++++++- requirements.txt | 3 ++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 04f6cc1d..90208f91 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ REQUIREMENT = requirements.txt +SRC = app.py app_test.py + .PHONY: build test build: html @@ -7,5 +9,6 @@ build: html cd docs && make $@ test: clean build - flake8 app.py app_test.py - coverage run app_test.py && coverage report --fail-under=90 -m app.py app_test.py + pycodestyle $(SRC) + pydocstyle $(SRC) + coverage run app_test.py && coverage report --fail-under=90 -m $(SRC) diff --git a/app.py b/app.py index 3e62b123..cbe40e23 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,5 @@ -""" -This is a simple cheatsheet webapp. -""" +"""This is a simple cheatsheet webapp.""" + import os from flask import Flask, abort, send_from_directory @@ -11,6 +10,7 @@ def find_key(token): + """Find the key from the environment variable.""" if token == os.environ.get("ACME_TOKEN"): return os.environ.get("ACME_KEY") for k, v in os.environ.items(): @@ -27,18 +27,19 @@ def find_key(token): @app.route('/') def static_proxy(path): - """Static files proxy""" + """Find static files.""" return send_from_directory(ROOT, path) @app.route('/') def index_redirection(): - """Redirecting index file""" + """Redirecting index file.""" return send_from_directory(ROOT, 'index.html') @app.route("/.well-known/acme-challenge/") def acme(token): + """Find the acme-key from environment variable.""" key = find_key(token) if key is None: abort(404) diff --git a/app_test.py b/app_test.py index 0dab49bf..bc536df8 100644 --- a/app_test.py +++ b/app_test.py @@ -1,3 +1,5 @@ +"""Test app.py.""" + import unittest import requests import os @@ -17,9 +19,10 @@ class PysheeetTest(LiveServerTestCase): + """Test app.""" def create_app(self): - + """Create a app for test.""" # remove env ACME_TOKEN* for k, v in os.environ.items(): if not k.startswith("ACME_TOKEN"): @@ -34,11 +37,13 @@ def create_app(self): return app def test_index_redirection_req(self): + """Test that send a request for the index page.""" url = self.get_server_url() resp = requests.get(url) self.assertEqual(resp.status_code, 200) def test_static_proxy_req(self): + """Test that send a request for notes.""" htmls = os.listdir(os.path.join(ROOT, 'notes')) url = self.get_server_url() for h in htmls: @@ -47,6 +52,7 @@ def test_static_proxy_req(self): self.assertEqual(resp.status_code, 200) def test_acme_req(self): + """Test that send a request for a acme key.""" url = self.get_server_url() u = url + '/.well-known/acme-challenge/token' resp = requests.get(u) @@ -57,6 +63,7 @@ def test_acme_req(self): self.assertEqual(resp.status_code, 404) def test_find_key(self): + """Test that find a acme key from the environment.""" token = self.token key = self.key self.assertEqual(find_key(token), key) @@ -72,6 +79,7 @@ def test_find_key(self): del os.environ['ACME_KEY_ENV'] def test_acme(self): + """Test that send a request for a acme key.""" token = self.token key = self.key self.assertEqual(acme(token), key) @@ -88,11 +96,13 @@ def test_acme(self): self.assertRaises(NotFound, acme, token) def test_index_redirection(self): + """Test index page redirection.""" resp = index_redirection() self.assertEqual(resp.status_code, 200) resp.close() def test_static_proxy(self): + """Test that request static pages.""" htmls = os.listdir(os.path.join(ROOT, 'notes')) for h in htmls: diff --git a/requirements.txt b/requirements.txt index 4d58f62d..6c7e3066 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,8 @@ Flask==0.12.2 Flask-SSLify==0.1.5 Flask-Testing==0.7.1 gunicorn==19.7.1 +pycodestyle==2.3.1 +pydocstyle==2.1.1 requests==2.18.4 Sphinx==1.7.2 -flake8==3.5.0 Werkzeug==0.14.1