Browse Source

update for lint and flake

main
Charles Reid 3 years ago
parent
commit
90072edcf9
Signed by: charlesreid1
GPG Key ID: 078B7759B68B353A
  1. 3
      .flake8
  2. 23
      Makefile
  3. 5
      common.mk
  4. 4
      requirements-test.txt
  5. 2004
      tests/test_operations.py
  6. 26
      tests/testmode.py
  7. 16
      tests/util.py

3
.flake8

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
extend-ignore = E203, E501, F401, E402

23
Makefile

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
include common.mk
MODULES=tests
all: test
lint:
flake8 $(MODULES)
# Vars
#
tests:=$(wildcard tests/test_*.py)
# Run standalone tests
#
test:
$(MAKE) -j1 $(tests)
# A pattern rule that runs a single test script
#
$(tests): %.py : lint
coverage run -p --source=src $*.py
.PHONY: all lint test safe_test serial_test all_test $(tests)

5
common.mk

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
SHELL=/bin/bash
ifeq ($(shell which flake8),)
$(error Please install flake8 or activate your virtual environment)
endif

4
requirements-test.txt

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
flake8 >= 3.4.1
coverage >= 4.4.1
httpie >= 1.0.3
yq >= 2.3.3

2004
tests/test_operations.py

File diff suppressed because it is too large Load Diff

26
tests/testmode.py

@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
import os
import unittest
def standalone(f):
return unittest.skipUnless(is_standalone(), "Skipping standalone test")(f)
def is_standalone():
return "standalone" in _test_mode()
def integration(f):
return unittest.skipUnless(is_integration(), "Skipping integration test")(f)
def is_integration():
return "integration" in _test_mode()
def always(f):
return f
def _test_mode():
return os.environ.get('CLINT_EASTWOOD_TEST_MODE', "standalone")

16
tests/util.py

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
import os
import sys
import random
import string
from io import StringIO
@ -10,6 +11,7 @@ class CaptureStdout(list): @@ -10,6 +11,7 @@ class CaptureStdout(list):
of Python code. Subclass of list so that you can access stdout lines like a
list.
"""
def __init__(self, *args, **kwargs):
super().__init__()
@ -42,13 +44,17 @@ class CaptureStdout(list): @@ -42,13 +44,17 @@ class CaptureStdout(list):
# up this context
sys.stdout = self._stdout
class SwapStdin(object):
"""Utility object using a context manager to swap out stdin with user-provided data."""
def __init__(self, swap_with):
if swap_with is None:
raise RuntimeError("Error: SwapStdin constructor must be provided with a value to substitute for stdin!")
raise RuntimeError(
"Error: SwapStdin constructor must be provided with a value to substitute for stdin!"
)
elif isinstance(swap_with, type("")):
swap_with = bytes(swap_with, 'utf-8')
swap_with = bytes(swap_with, "utf-8")
self.swap_with = swap_with
def __enter__(self, *args, **kwargs):
@ -70,12 +76,10 @@ class SwapStdin(object): @@ -70,12 +76,10 @@ class SwapStdin(object):
def random_alphanumeric_string(N=10):
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=N))
return "".join(random.choices(string.ascii_uppercase + string.digits, k=N))
def get_env(varname):
if varname not in os.environ:
raise RuntimeError(
"Please set the {} environment variable".format(varname))
raise RuntimeError("Please set the {} environment variable".format(varname))
return os.environ[varname]

Loading…
Cancel
Save