commit 968f29eb950133ac85b49a319277b0d666f1f56a
Author: juga0 <juga(a)riseup.net>
Date: Sat Dec 15 08:02:10 2018 +0000
tests: add generate test for round digits argument.
Torflow's scaling now round digits according to Proposal 276,
but for compatibility with Torflow's round digits algorithm,
the argument option has to be available and by default be
Proposal 276.
---
sbws/core/generate.py | 1 +
tests/unit/core/test_generate.py | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/sbws/core/generate.py b/sbws/core/generate.py
index 971ed9e..353bea0 100644
--- a/sbws/core/generate.py
+++ b/sbws/core/generate.py
@@ -66,6 +66,7 @@ def gen_parser(sub):
"other.")
p.add_argument('-n', '--min-num', default=NUM_MIN_RESULTS, type=int,
help="Mininum number of a results to consider them.")
+ return p
def main(args, conf):
diff --git a/tests/unit/core/test_generate.py b/tests/unit/core/test_generate.py
new file mode 100644
index 0000000..aafe271
--- /dev/null
+++ b/tests/unit/core/test_generate.py
@@ -0,0 +1,34 @@
+"""Unit tests for sbws.core.generate module."""
+import argparse
+
+from sbws.globals import TORFLOW_ROUND_DIG, PROP276_ROUND_DIG
+from sbws.core.generate import gen_parser
+
+
+def test_gen_parser_arg_round_digs():
+ """
+ Test that both --torflow-round-digs and --round-digs arguments can be
+ passed and round-digs is PROP276_ROUND_DIG by default.
+
+ """
+ parent_parser = argparse.ArgumentParser(prog='sbws')
+ subparsers = parent_parser.add_subparsers(help='generate help')
+ parser_generate = gen_parser(subparsers)
+ # Explicitely set empty arguments, otherwise pytest will use pytest
+ # arguments
+ args = parser_generate.parse_args([])
+ assert args.round_digs == PROP276_ROUND_DIG
+ # torflow_round_digs is not in the Namespace
+ assert getattr(args, 'torflow_round_digs', None) is None
+ # but it can still be passed as an argument
+ args = parser_generate.parse_args(['--torflow-round-digs',
+ str(TORFLOW_ROUND_DIG)])
+ # though the variable is named round_digs
+ assert args.round_digs == TORFLOW_ROUND_DIG
+ # or use the short version
+ args = parser_generate.parse_args(['-r', str(TORFLOW_ROUND_DIG)])
+ assert args.round_digs == TORFLOW_ROUND_DIG
+ # or use round-digs explicitely
+ args = parser_generate.parse_args(['--round-digs',
+ str(PROP276_ROUND_DIG)])
+ assert args.round_digs == PROP276_ROUND_DIG