Browse Source

Move pytest fixtures into conftest.py

pull/129/head
Christoph Buchner 9 years ago
parent
commit
84fa92a160
4 changed files with 67 additions and 75 deletions
  1. 60
      gooey/tests/argparse_to_json_unittest.py
  2. 7
      gooey/tests/config_generator_unittest.py
  3. 67
      gooey/tests/conftest.py
  4. 8
      gooey/tests/image_repositoy_unittest.py

60
gooey/tests/argparse_to_json_unittest.py

@ -2,66 +2,6 @@ import pytest
from gooey.python_bindings.argparse_to_json import *
@pytest.fixture
def empty_parser():
return argparse.ArgumentParser(description='description')
@pytest.fixture
def complete_parser():
parser = argparse.ArgumentParser(description='description')
parser.add_argument("req1", help='filename help msg') # positional
parser.add_argument("req2", help="Name of the file where you'll save the output") # positional
parser.add_argument('-r', dest="req3", default=10, type=int, help='sets the time to count down from', required=True)
parser.add_argument('--req4', dest="req4", default=10, type=int, help='sets the time to count down from', required=True)
parser.add_argument("-a", "--aa", action="store_true", help="aaa")
parser.add_argument("-b", "--bb", action="store_true", help="bbb")
parser.add_argument('-c', '--cc', action='count')
parser.add_argument("-d", "--dd", action="store_true", help="ddd")
parser.add_argument('-e', '--ee', choices=['yes', 'no'], help='eee')
parser.add_argument("-f", "--ff", default="0000", help="fff")
parser.add_argument("-g", "--gg", action="store_true", help="ggg")
verbosity = parser.add_mutually_exclusive_group()
verbosity.add_argument('-i', '--ii', action="store_true", help="iii")
verbosity.add_argument('-j', '--jj', action="store_true", help="hhh")
return parser
@pytest.fixture
def subparser():
parser = argparse.ArgumentParser(description='qidev')
parser.add_argument('--verbose', help='be verbose', dest='verbose', action='store_true', default=False)
subs = parser.add_subparsers(help='commands', dest='command')
config_parser = subs.add_parser('config', help='configure defaults for qidev')
config_parser.add_argument('field', help='the field to configure', type=str)
config_parser.add_argument('value', help='set field to value', type=str)
# ########################################################
connect_parser = subs.add_parser('connect', help='connect to a robot (ip/hostname)')
connect_parser.add_argument('hostname', help='hostname or IP address of the robot', type=str)
# ########################################################
install_parser = subs.add_parser('install', help='package and install a project directory on a robot')
install_parser.add_argument('path', help='path to the project directory (containing manifest.xml', type=str)
install_parser.add_argument('--ip', nargs='*', type=str, dest='ip', help='specify hostname(es)/IP address(es)')
return parser
@pytest.fixture
def exclusive_group():
parser = argparse.ArgumentParser(description='description')
verbosity = parser.add_mutually_exclusive_group()
verbosity.add_argument('-i', dest="option1", action="store_true", help="iii")
verbosity.add_argument('-j', dest="option2", action="store_true", help="hhh")
mutually_exclusive_group = [mutex_action
for group_actions in parser._mutually_exclusive_groups
for mutex_action in group_actions._group_actions]
return mutually_exclusive_group
def test_parser_converts_to_correct_type(empty_parser, complete_parser, subparser):
assert convert(subparser)['layout_type'] == 'column'
assert convert(empty_parser)['layout_type'] == 'standard'

7
gooey/tests/config_generator_unittest.py

@ -1,12 +1,5 @@
import argparse
import pytest
from gooey.python_bindings.config_generator import *
# TODO: duplicated from argparse_to_json_unittest, should go into conftest.py
@pytest.fixture
def empty_parser():
return argparse.ArgumentParser(description='description')
def test_create_from_parser(empty_parser):
build_spec = create_from_parser(empty_parser,'.')

67
gooey/tests/conftest.py

@ -0,0 +1,67 @@
import argparse
import pytest
@pytest.fixture
def empty_parser():
return argparse.ArgumentParser(description='description')
@pytest.fixture
def complete_parser():
parser = argparse.ArgumentParser(description='description')
parser.add_argument("req1", help='filename help msg') # positional
parser.add_argument("req2", help="Name of the file where you'll save the output") # positional
parser.add_argument('-r', dest="req3", default=10, type=int, help='sets the time to count down from', required=True)
parser.add_argument('--req4', dest="req4", default=10, type=int, help='sets the time to count down from', required=True)
parser.add_argument("-a", "--aa", action="store_true", help="aaa")
parser.add_argument("-b", "--bb", action="store_true", help="bbb")
parser.add_argument('-c', '--cc', action='count')
parser.add_argument("-d", "--dd", action="store_true", help="ddd")
parser.add_argument('-e', '--ee', choices=['yes', 'no'], help='eee')
parser.add_argument("-f", "--ff", default="0000", help="fff")
parser.add_argument("-g", "--gg", action="store_true", help="ggg")
verbosity = parser.add_mutually_exclusive_group()
verbosity.add_argument('-i', '--ii', action="store_true", help="iii")
verbosity.add_argument('-j', '--jj', action="store_true", help="hhh")
return parser
@pytest.fixture
def subparser():
parser = argparse.ArgumentParser(description='qidev')
parser.add_argument('--verbose', help='be verbose', dest='verbose', action='store_true', default=False)
subs = parser.add_subparsers(help='commands', dest='command')
config_parser = subs.add_parser('config', help='configure defaults for qidev')
config_parser.add_argument('field', help='the field to configure', type=str)
config_parser.add_argument('value', help='set field to value', type=str)
# ########################################################
connect_parser = subs.add_parser('connect', help='connect to a robot (ip/hostname)')
connect_parser.add_argument('hostname', help='hostname or IP address of the robot', type=str)
# ########################################################
install_parser = subs.add_parser('install', help='package and install a project directory on a robot')
install_parser.add_argument('path', help='path to the project directory (containing manifest.xml', type=str)
install_parser.add_argument('--ip', nargs='*', type=str, dest='ip', help='specify hostname(es)/IP address(es)')
return parser
@pytest.fixture
def exclusive_group():
parser = argparse.ArgumentParser(description='description')
verbosity = parser.add_mutually_exclusive_group()
verbosity.add_argument('-i', dest="option1", action="store_true", help="iii")
verbosity.add_argument('-j', dest="option2", action="store_true", help="hhh")
mutually_exclusive_group = [mutex_action
for group_actions in parser._mutually_exclusive_groups
for mutex_action in group_actions._group_actions]
return mutually_exclusive_group
@pytest.fixture
def expected_attrs():
return ('program_icon', 'success_icon', 'running_icon',
'loading_icon', 'config_icon', 'error_icon')

8
gooey/tests/image_repositoy_unittest.py

@ -6,12 +6,6 @@ import pytest
import tempfile
@pytest.fixture
def expected_attrs():
return ('program_icon', 'success_icon', 'running_icon',
'loading_icon', 'config_icon', 'error_icon')
def test_variable_names_are_pushed_to_module_scope(expected_attrs):
'''
The dynamically initialized Globals() should contain the expected images at runtime
@ -62,5 +56,3 @@ def make_user_files(*filenames):
def cleanup_temp(*filenames):
for filename in filenames:
os.remove(os.path.join(tempfile.gettempdir(), filename))
Loading…
Cancel
Save