This is an automated email from the ASF dual-hosted git repository. gstein pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/steve.git
commit 46b29b5853d61598ad852d1e5157ba8d179cc3fc Author: Greg Stein <[email protected]> AuthorDate: Sun Jun 5 17:15:44 2022 -0500 Add line/branch coverage testing. In Python, one of the major classes of errors (since no compilation step exists) is simple typos of identifiers. Running coverage to verify that each line is touched finds 99% of these typos. This adds a simple test to run coverage over the "steve" package, and achieves 100% for the primary package, but 0% of the "steve.vtypes" subpackage (but will, shortly). --- v3/requirements.txt | 3 ++ v3/test/check_coverage.py | 111 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/v3/requirements.txt b/v3/requirements.txt index ace27a2..7c85e08 100644 --- a/v3/requirements.txt +++ b/v3/requirements.txt @@ -1,3 +1,6 @@ passlib argon2-cffi cryptography + +# strictly speaking, optional: +coverage diff --git a/v3/test/check_coverage.py b/v3/test/check_coverage.py new file mode 100755 index 0000000..7266ac2 --- /dev/null +++ b/v3/test/check_coverage.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# ---- +# +# ### TBD: DOCCO +# + + +import sys +import os.path +import sqlite3 +import json + +import coverage + +# Ensure that we can import the "steve" package. +THIS_DIR = os.path.realpath(os.path.dirname(__file__)) +PARENT_DIR = os.path.dirname(THIS_DIR) +sys.path.insert(0, PARENT_DIR) + +TESTING_DB = os.path.join(THIS_DIR, 'covtest.db') +SCHEMA_FILE = os.path.join(PARENT_DIR, 'schema.sql') + + +def touch_every_line(): + "A minimal test to run each line in the 'steve' package." + + # Do the import *WITHIN* the coverage test. + import steve.election + + eid = steve.election.new_eid() + + # Start the election, and open it. + try: + os.remove(TESTING_DB) + except OSError: + pass + conn = sqlite3.connect(TESTING_DB) + conn.executescript(open(SCHEMA_FILE).read()) + conn.execute('INSERT INTO METADATA' + f' VALUES ("{eid}", "title", NULL, NULL, NULL)') + conn.commit() + e = steve.election.Election(TESTING_DB) + + e.add_person('alice', 'Alice', '[email protected]') + e.add_person('bob', None, '[email protected]') + e.add_person('Carlos', 'Carlos', '[email protected]') + _ = e.list_persons() + e.delete_person('carlos') + _ = e.get_person('alice') + + e.add_issue('a', 'issue A', None, 'yna', None) + e.add_issue('b', 'issue B', None, 'stv', json.dumps({ + 'seats': 3, + 'labelmap': { + 'a': 'Alice', + 'b': 'Bob', + 'c': 'Carlos', + 'd': 'David', + 'e': 'Eve', + }, + })) + _ = e.list_issues() + e.add_issue('c', 'issue C', None, 'yna', None) + e.delete_issue('c') + _ = e.get_issue('a') + + e.open() + e.add_vote('alice', 'a', 'y') + _ = e.has_voted_upon('alice') + _ = e.is_tampered() + + e.close() + _ = e.gather_issue_votes('a') + + +def main(): + cov = coverage.Coverage( + data_file=None, branch=True, config_file=False, + source_pkgs=['steve'], messages=True, + ) + cov.start() + + try: + touch_every_line() + finally: + cov.stop() + + cov.report(file=sys.stdout) + cov.html_report(directory='covreport') + + +if __name__ == '__main__': + main()
