Skip to content

Commit

Permalink
Add pylint run; new approach to coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ptlm authored and mbj4668 committed Feb 3, 2020
1 parent b7c7683 commit b1090bb
Show file tree
Hide file tree
Showing 64 changed files with 144 additions and 124 deletions.
11 changes: 11 additions & 0 deletions .pylintrc
@@ -0,0 +1,11 @@
[MASTER]
ignore-patterns = .*yacc
extension-pkg-whitelist = lxml.etree

[SIMILARITIES]
ignore-imports = yes

[MESSAGES-CONTROL]
disable =
invalid-name,
missing-docstring
8 changes: 2 additions & 6 deletions .travis.yml
Expand Up @@ -8,6 +8,7 @@ python:
# - "3.5" # error: coverage doesn't work
- "3.6"
- "3.7"
- "3.8"
addons:
apt:
packages:
Expand All @@ -18,17 +19,12 @@ addons:
install:
- pip install -r requirements.txt
- pip install -r dev-requirements.txt
- SITEPACKAGES=$(pip --version | sed -n 's@.*from \([^ ]\+\) .*@\1@p')
- echo 'import coverage; coverage.process_startup()' > $SITEPACKAGES/sitecustomize.py
- printf '[run]\nparallel=True\n' > ~/coverage.cfg
script:
- source env.sh
- export COVERAGE_PROCESS_START=~/coverage.cfg
- export USE_VIRTUALENV=true
- make test
- find . -name '.coverage*' -exec mv -t . {} +
# tmp ignore no coverage files
- coverage combine || true
- coverage combine
# Test .gitignore for tests:
- TMP=$(tempfile)
- git ls-files . --exclude-standard --others | tee "$TMP"
Expand Down
6 changes: 6 additions & 0 deletions Makefile
@@ -1,3 +1,5 @@
export W := $(shell pwd)

# create a full source package
sdist: build
python setup.py sdist
Expand All @@ -21,6 +23,9 @@ test: lint

lint:
flake8 .
touch bin/__init__.py # makes pylint tell pyang script apart from pyang package
pylint bin/pyang bin/json2xml bin/yang2html pyang $(shell find test -name '*.py') || true
rm -f bin/__init__.py

clean:
rm -f pyang/parser.out pyang/xpath_parsetab.py
Expand All @@ -29,6 +34,7 @@ clean:
python setup.py clean --all
rm -rf build dist MANIFEST
find . -name "*.pyc" -exec rm {} \;
find . -name "__pycache__" -exec rm -rf {} \;

tags:
find . -name "*.py" | etags -
2 changes: 1 addition & 1 deletion bin/yang2dsdl
Expand Up @@ -251,7 +251,7 @@ if [ "$noschema" = "0" ] ; then
pyang_opts="${pyang_opts} --hello"
printf "\n"
fi
pyang -f dsdl -o $hybs $pyang_opts $infiles
${PYANG:-pyang} -f dsdl -o $hybs $pyang_opts $infiles
[ $? -eq 0 ] || exit 2
if [ "$basename" = "" ] ; then
basename=$(xsltproc $xslt_dir/basename.xsl $hybs)
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Expand Up @@ -3,3 +3,4 @@ virtualenv
pycodestyle
pyflakes
flake8
pylint
15 changes: 7 additions & 8 deletions env.sh
Expand Up @@ -3,11 +3,10 @@
# source this file to get environment setup for the
# pyang below here

p=`pwd`
export PATH="$p/bin:$PATH"
export MANPATH="$p/man:$MANPATH"
export PYTHONPATH="$p:$PYTHONPATH"
export YANG_MODPATH="$p/modules:$YANG_MODPATH"
export PYANG_XSLT_DIR="$p/xslt"
export PYANG_RNG_LIBDIR="$p/schema"
export W="$p"
export PATH="$PWD/bin:$PATH"
export MANPATH="$PWD/man:$MANPATH"
export PYTHONPATH="$PWD:$PYTHONPATH"
export YANG_MODPATH="$PWD/modules:$YANG_MODPATH"
export PYANG_XSLT_DIR="$PWD/xslt"
export PYANG_RNG_LIBDIR="$PWD/schema"
export W="$PWD"
10 changes: 8 additions & 2 deletions test/Makefile
@@ -1,5 +1,10 @@
DIRS = $(shell for d in test_* ; \
do [ -d $$d -a -f $$d/Makefile ] && echo $$d ; done)
COVERAGE := python -mcoverage run --branch --parallel-mode --source $(W)/pyang,$(W)/bin --omit $(W)/pyang/yacc.py
export PYANG := $(COVERAGE) $(W)/bin/pyang
export JSON2XML := $(COVERAGE) $(W)/bin/json2xml
export YANG2HTML := $(COVERAGE) $(W)/bin/yang2html
export YANG2DSDL := env PYANG='$(PYANG)' $(W)/bin/yang2dsdl

test:
$(MAKE) itest
Expand Down Expand Up @@ -28,7 +33,7 @@ selftest:
( cd $$d; \
for m in *.yang; do \
echo " $${m}... " | tr -d '\012'; \
pyang -Werror $$m || exit 1; \
$(PYANG) -Werror $$m || exit 1; \
echo "ok"; \
done ) || exit 1; \
done || exit 1;
Expand All @@ -46,7 +51,8 @@ python3:
mkdir $@

clean:
@for d in $(DIRS); do \
@find -name '.coverage*' -delete; \
for d in $(DIRS); do \
(cd $$d && $(MAKE) $@) \
done; \
rm -rf python2 python3
2 changes: 1 addition & 1 deletion test/test_bad/Makefile
@@ -1,7 +1,7 @@
DIRS = $(shell for d in test_* ; \
do [ -d $$d -a -f $$d/Makefile ] && echo $$d ; done)

PYANG = pyang --print-error-code --strict
PYANG := $(PYANG) --print-error-code --strict

MODULES = $(wildcard *.yang)

Expand Down
2 changes: 1 addition & 1 deletion test/test_bad/test_date/Makefile
@@ -1,2 +1,2 @@
test:
pyang test.yang --print-error-code 2>&1 | grep BAD_VALUE
$(PYANG) test.yang --print-error-code 2>&1 | grep BAD_VALUE
2 changes: 1 addition & 1 deletion test/test_bad/test_i190/Makefile
@@ -1,3 +1,3 @@
test:
pyang tst-m.yang --lint --print-error-code 2>&1 | \
$(PYANG) tst-m.yang --lint --print-error-code 2>&1 | \
grep LINT_TOP_MANDATORY
2 changes: 1 addition & 1 deletion test/test_bad/test_i201/Makefile
@@ -1,2 +1,2 @@
test:
pyang tst-m.yang --lint --print-error-code 2>&1 | grep LINT_BAD_REVISION
$(PYANG) tst-m.yang --lint --print-error-code 2>&1 | grep LINT_BAD_REVISION
2 changes: 1 addition & 1 deletion test/test_bad/test_i206/Makefile
@@ -1,2 +1,2 @@
test:
pyang test.yang --print-error-code 2>&1 | grep NODE_NOT_FOUND
$(PYANG) test.yang --print-error-code 2>&1 | grep NODE_NOT_FOUND
2 changes: 1 addition & 1 deletion test/test_canonical/Makefile
@@ -1,4 +1,4 @@
PYANG = pyang -Wnone
PYANG := $(PYANG) -Wnone

MODULES = $(wildcard *.yang)

Expand Down
2 changes: 1 addition & 1 deletion test/test_dsdl/Makefile
@@ -1,6 +1,6 @@
PYANG_RNG_LIBDIR = ../../schema
PYANG_XSLT_DIR = ../../xslt
YANG2DSDL := ../../bin/yang2dsdl
YANG2DSDL ?= ../../bin/yang2dsdl

results := $(patsubst %.xml,%.log,$(wildcard *.xml))

Expand Down
27 changes: 14 additions & 13 deletions test/test_good/Makefile
@@ -1,39 +1,40 @@
PYANG = pyang -Werror -WWBAD_MODULE_NAME
PYANGE := $(PYANG) -Werror -WWBAD_MODULE_NAME

test: clean utf8-test mef-ieee-test
@for m in $(wildcard *.yang); do \
echo "checking $$m..." | tr -d '\012'; \
$(PYANG) $$m || exit 1; \
$(PYANGE) $$m || exit 1; \
echo " generating yin..."; \
$(PYANG) -f yin -o $$m.yin $$m || exit 1; \
$(PYANGE) -f yin -o $$m.yin $$m || exit 1; \
echo " " | tr -d '\012'; \
echo " generating yang from the generated yin..."; \
$(PYANG) -f yang -o $$m.gen.yang $$m.yin || exit 1; \
$(PYANGE) -f yang -o $$m.gen.yang $$m.yin || exit 1; \
echo " " | tr -d '\012'; \
echo " generating yang..." | tr -d '\012'; \
$(PYANG) -f yang -o $$m.gen.yang $$m || exit 1; \
$(PYANGE) -f yang -o $$m.gen.yang $$m || exit 1; \
echo " generating yin from the generated yang..."; \
$(PYANG) -f yin -o $$m.gen.yin $$m.gen.yang || exit 1; \
$(PYANGE) -f yin -o $$m.gen.yin $$m.gen.yang || exit 1; \
echo " " | tr -d '\012'; \
echo " comparing the two generated yin..." | tr -d '\012';\
diff $$m.yin $$m.gen.yin > $$m.diff || \
{ cat $$m.diff; exit 1; }; \
rm -f $$m.diff; \
echo " generating DSDL..." | tr -d '\012'; \
(grep '^submodule' $$m > /dev/null || $(PYANG) -f dsdl -o $$m.dsdl $$m || exit 0); \
(grep '^submodule' $$m > /dev/null \
|| $(PYANGE) -f dsdl -o $$m.dsdl $$m || exit 0); \
echo " ok"; \
done

utf8-test:
pyang -f yang q.yang || exit 1; \
pyang -f yang q.yang > x || exit 1; \
pyang -f yang q.yang -o x || exit 1; \
$(PYANG) -f yang q.yang || exit 1; \
$(PYANG) -f yang q.yang > x || exit 1; \
$(PYANG) -f yang q.yang -o x || exit 1; \
rm -f x

mef-ieee-test:
pyang --mef mef-yt10.yang || exit 1; \
pyang --mef mef-yt11.yang || exit 1; \
pyang --ieee ieee-yt12.yang || exit 1;
$(PYANG) --mef mef-yt10.yang || exit 1; \
$(PYANG) --mef mef-yt11.yang || exit 1; \
$(PYANG) --ieee ieee-yt12.yang || exit 1;

clean:
rm -rf *.yang.yin *.gen.* *.dsdl
2 changes: 1 addition & 1 deletion test/test_good/Makefile.DSDL
Expand Up @@ -4,7 +4,7 @@ test: clean
@for m in $(MODULES); do \
for t in $(TARGETS); do \
echo "checking $$m - $$t"; \
yang2dsdl -t $$t $$m; \
$(YANG2DSDL) -t $$t $$m; \
done; \
done

Expand Down
8 changes: 4 additions & 4 deletions test/test_hello/Makefile
Expand Up @@ -11,17 +11,17 @@ Y2DOPTS = -L -t $(TARGET) -b $(BASE)
all: $(SCHEMAS)

$(SCHEMAS): $(HELLO) $(MODULES)
yang2dsdl $(Y2DOPTS) $(FULLEXT) $<
$(YANG2DSDL) $(Y2DOPTS) $(FULLEXT) $<

clean:
rm -f $(SCHEMAS) $BASE.{dsdl,tree} *-gdefs.rng *.rnc

test: $(INSTANCE) $(SCHEMAS)
yang2dsdl -j -s $(Y2DOPTS) -v $<
$(YANG2DSDL) -j -s $(Y2DOPTS) -v $<

$(BASE).dsdl: $(HELLO) $(MODULES)
pyang -f dsdl --dsdl-no-documentation $(FULLEXT) $< \
$(PYANG) -f dsdl --dsdl-no-documentation $(FULLEXT) $< \
| xmllint --format - > $@

$(BASE).tree: $(HELLO) $(MODULES)
pyang -f tree -o $@ $(FULLEXT) $<
$(PYANG) -f tree -o $@ $(FULLEXT) $<
2 changes: 1 addition & 1 deletion test/test_issues/test_i126/Makefile
@@ -1,2 +1,2 @@
test:
pyang -Werror -L hello.xml
$(PYANG) -Werror -L hello.xml
2 changes: 1 addition & 1 deletion test/test_issues/test_i183/Makefile
@@ -1,2 +1,2 @@
test:
pyang a.yang --canonical --print-error-code 2>&1 | diff a.expect -
$(PYANG) a.yang --canonical --print-error-code 2>&1 | diff a.expect -
4 changes: 2 additions & 2 deletions test/test_issues/test_i218/Makefile
@@ -1,7 +1,7 @@
test: test1 test2

test1:
pyang -f yin x.yang | pyang -f yang | diff x.yang -
$(PYANG) -f yin x.yang | $(PYANG) -f yang | diff x.yang -

test2:
pyang -f tree x.yang | diff x.tree.expect -
$(PYANG) -f tree x.yang | diff x.tree.expect -
6 changes: 3 additions & 3 deletions test/test_issues/test_i230/Makefile
@@ -1,9 +1,9 @@
test:
PYANG_PLUGINPATH=. pyang -f yin example-sports.yang \
PYANG_PLUGINPATH=. $(PYANG) -f yin example-sports.yang \
-o example-sports.yin
pyang -f tree --tree-path=sports/person/name example-sports.yang \
$(PYANG) -f tree --tree-path=sports/person/name example-sports.yang \
-o example-sports.tree
pyang -f omni --omni-path=sports/person/name example-sports.yang \
$(PYANG) -f omni --omni-path=sports/person/name example-sports.yang \
-o example-sports.omni
rm -f *.yin *.tree *.omni

2 changes: 1 addition & 1 deletion test/test_issues/test_i262/Makefile
@@ -1,3 +1,3 @@
# this used to crash
test:
pyang -f jsonxsl example-4-a.yang example-4-b.yang > /dev/null
$(PYANG) -f jsonxsl example-4-a.yang example-4-b.yang > /dev/null
2 changes: 1 addition & 1 deletion test/test_issues/test_i263/Makefile
@@ -1,2 +1,2 @@
test:
pyang --deviation-module test-dev.yang test.yang > /dev/null
$(PYANG) --deviation-module test-dev.yang test.yang > /dev/null
2 changes: 1 addition & 1 deletion test/test_issues/test_i267/Makefile
@@ -1,3 +1,3 @@
test:
pyang --print-error-code test.yang --deviation-module=test-dev.yang \
$(PYANG) --print-error-code test.yang --deviation-module=test-dev.yang \
2>&1 | grep BAD_DEVIATE_ADD > /dev/null
2 changes: 1 addition & 1 deletion test/test_issues/test_i271/Makefile
@@ -1,2 +1,2 @@
test:
pyang --lint my-x.yang > /dev/null
$(PYANG) --lint my-x.yang > /dev/null
2 changes: 1 addition & 1 deletion test/test_issues/test_i275/Makefile
@@ -1,2 +1,2 @@
test:
pyang --print-error-code x.yang 2>&1 | grep NODE_NOT_FOUND > /dev/null
$(PYANG) --print-error-code x.yang 2>&1 | grep NODE_NOT_FOUND > /dev/null
2 changes: 1 addition & 1 deletion test/test_issues/test_i276/Makefile
@@ -1,2 +1,2 @@
test:
pyang x.yang --print-error-code 2>&1 | diff x.expect -
$(PYANG) x.yang --print-error-code 2>&1 | diff x.expect -
2 changes: 1 addition & 1 deletion test/test_issues/test_i277/Makefile
@@ -1,2 +1,2 @@
test:
pyang -f tree x.yang 2>&1 | grep c2 > /dev/null
$(PYANG) -f tree x.yang 2>&1 | grep c2 > /dev/null
2 changes: 1 addition & 1 deletion test/test_issues/test_i278/Makefile
@@ -1,2 +1,2 @@
test:
pyang -f jsonxsl test.yang > /dev/null
$(PYANG) -f jsonxsl test.yang > /dev/null
2 changes: 1 addition & 1 deletion test/test_issues/test_i285/Makefile
@@ -1,3 +1,3 @@
test:
pyang a.yang --print-error-code 2>&1 | diff a.expect -
$(PYANG) a.yang --print-error-code 2>&1 | diff a.expect -

2 changes: 1 addition & 1 deletion test/test_issues/test_i300/Makefile
@@ -1,2 +1,2 @@
test:
pyang devext.yang > /dev/null
$(PYANG) devext.yang > /dev/null
2 changes: 1 addition & 1 deletion test/test_issues/test_i301/Makefile
@@ -1,2 +1,2 @@
test:
pyang a.yang > /dev/null
$(PYANG) a.yang > /dev/null
2 changes: 1 addition & 1 deletion test/test_issues/test_i324/Makefile
@@ -1,2 +1,2 @@
test:
pyang a.yang > /dev/null
$(PYANG) a.yang > /dev/null
2 changes: 1 addition & 1 deletion test/test_issues/test_i329/Makefile
@@ -1,2 +1,2 @@
test:
pyang a.yang > /dev/null
$(PYANG) a.yang > /dev/null
4 changes: 2 additions & 2 deletions test/test_issues/test_i374/Makefile
@@ -1,3 +1,3 @@
test:
pyang a.yang > /dev/null
pyang b.yang --print-error-code 2>&1 | diff b.expect -
$(PYANG) a.yang > /dev/null
$(PYANG) b.yang --print-error-code 2>&1 | diff b.expect -
2 changes: 1 addition & 1 deletion test/test_issues/test_i379/Makefile
@@ -1,2 +1,2 @@
test:
pyang a.yang --print-error-code 2>&1 | diff a.expect -
$(PYANG) a.yang --print-error-code 2>&1 | diff a.expect -
2 changes: 1 addition & 1 deletion test/test_issues/test_i380/Makefile
@@ -1,2 +1,2 @@
test:
pyang --lint --lint-ensure-hyphenated-names my-types.yang > /dev/null
$(PYANG) --lint --lint-ensure-hyphenated-names my-types.yang > /dev/null
2 changes: 1 addition & 1 deletion test/test_issues/test_i475/Makefile
@@ -1,3 +1,3 @@
test:
pyang --print-error-code test.yang --deviation-module=test-dev.yang \
$(PYANG) --print-error-code test.yang --deviation-module=test-dev.yang \
2>&1 | diff test-dev.expect -
2 changes: 1 addition & 1 deletion test/test_issues/test_i481/Makefile
@@ -1,2 +1,2 @@
test:
pyang -f tree -F a: b.yang | diff b.expect -
$(PYANG) -f tree -F a: b.yang | diff b.expect -
2 changes: 1 addition & 1 deletion test/test_issues/test_i482/Makefile
@@ -1,3 +1,3 @@
test:
pyang -f tree --tree-print-groupings --tree-no-expand-uses a.yang \
$(PYANG) -f tree --tree-print-groupings --tree-no-expand-uses a.yang \
| diff a.expect -
4 changes: 2 additions & 2 deletions test/test_issues/test_i490/Makefile
Expand Up @@ -2,8 +2,8 @@ test: test1 test2

# ensure that 'qux' is NOT printed when we don't implement any features
test1:
pyang -f tree -F a: a.yang | grep -q qux && exit 1 || exit 0
$(PYANG) -f tree -F a: a.yang | grep -q qux && exit 1 || exit 0

# ensure that 'qux' IS printed when we implement all features
test2:
pyang -f tree a.yang | grep -q qux
$(PYANG) -f tree a.yang | grep -q qux
2 changes: 1 addition & 1 deletion test/test_issues/test_i493/Makefile
@@ -1,3 +1,3 @@
test:
pyang -f yang a.yang > /dev/null
$(PYANG) -f yang a.yang > /dev/null

4 changes: 2 additions & 2 deletions test/test_issues/test_i495/Makefile
Expand Up @@ -2,7 +2,7 @@ test: test-1 test-2


test-1:
pyang -Werror a.yang
$(PYANG) -Werror a.yang

test-2:
pyang b.yang -Werror --print-error-code 2>&1 | diff b.expect -
$(PYANG) b.yang -Werror --print-error-code 2>&1 | diff b.expect -
2 changes: 1 addition & 1 deletion test/test_issues/test_i505/Makefile
@@ -1,4 +1,4 @@
test:
test `pyang -f yang --yang-canonical a.yang | grep require-instance | \
test `$(PYANG) -f yang --yang-canonical a.yang | grep require-instance | \
wc -l` = 1

0 comments on commit b1090bb

Please sign in to comment.