Exemple #1
0
def _load_up_the_tests():
    "reads the files from the samples directory and parametrizes the test"
    tests = []
    for i in os.scandir(
            os.path.abspath(os.curdir) + '/tests/integration/sqcmds/samples'):
        if not i.path.endswith('.yml'):
            continue
        with open(i, 'r') as f:
            out = yaml.load(f.read(), Loader=yaml.BaseLoader)
            # The format of the YAML file assumed is as follows:
            # description: <string>
            # tests:
            #   - command: <sqcmd to execute in non-modal format
            #     data-directory: <where the data is present>, not used yet
            #     marks: <space separated string of marks to mark the test>
            #     output: |
            #       <json_output>
            #
            #   - command:
            #     ....
            if out and 'tests' in out:
                for t in out['tests']:
                    # We use tags to dynamically mark the parametrized test
                    # the marks MUST be registered in pytest.ini
                    markers = []
                    if 'marks' in t:
                        markers = [
                            MarkDecorator(Mark(x, [], {}))
                            for x in t['marks'].split()
                        ]
                    if 'xfail' in t:
                        except_err = None
                        if 'raises' in t['xfail']:
                            except_err = globals()['__builtins__'].get(
                                t['xfail']['raises'], None)

                        if except_err:
                            markers += [
                                pytest.mark.xfail(reason=t['xfail']['reason'],
                                                  raises=except_err)
                            ]
                        else:
                            if 'reason' in t['xfail']:
                                markers += [
                                    pytest.mark.xfail(
                                        reason=t['xfail']['reason'])
                                ]
                            else:
                                markers += [pytest.mark.xfail()]
                    if markers:
                        tests += [
                            pytest.param(t, marks=markers, id=t['command'])
                        ]
                    else:
                        tests += [pytest.param(t, id=t['command'])]

    return tests
Exemple #2
0
import pytest
from _pytest.mark.structures import Mark, MarkDecorator

from tests.conftest import DATADIR
from suzieq.sqobjects import get_tables, get_sqobject


@pytest.mark.schema
@pytest.mark.parametrize('table', [
    pytest.param(x, marks=MarkDecorator(Mark(x, [], {})))
    for x in get_tables()
])
@pytest.mark.parametrize('datadir', DATADIR)
@pytest.mark.parametrize('columns', [['*'], ['default']])
def test_schema_data_consistency(table, datadir, columns, get_table_data_cols):
    '''Test that all fields in dataframe and schema are consistent
        Only applies to show command for now
        It tests show columns=* is consistent with all fields in schema
        and that columns='default' matches all display fields in schema
    '''

    if table in [
            'path', 'tables', 'ospfIf', 'ospfNbr', 'topcpu', 'topmem',
            'ifCounters', 'time'
    ]:
        return

    df = get_table_data_cols

    # We have to get rid of false assertions. A bunch of data sets don't
    # have valid values for one or more tables.
Exemple #3
0
from tests.conftest import (load_up_the_tests, tables, DATADIR, setup_sqcmds,
                            cli_commands, create_dummy_config_file)
from suzieq.sqobjects import get_sqobject, get_tables
from suzieq.cli.sqcmds import *  # noqa
from suzieq.version import SUZIEQ_VERSION
from suzieq.shared.utils import get_sq_install_dir

from tests.integration.utils import assert_df_equal

verbs = ['show', 'summarize', 'describe', 'help']


@pytest.mark.sqcmds
@pytest.mark.slow
@pytest.mark.parametrize("command", [
    pytest.param(cmd, marks=MarkDecorator(Mark(cmd, [], {})))
    for cmd in cli_commands
])
@pytest.mark.parametrize("verb", [
    pytest.param(verb, marks=MarkDecorator(Mark(verb, [], {})))
    for verb in verbs
])
def test_commands(setup_nubia, get_cmd_object_dict, command, verb):
    """ runs through all of the commands for each of the sqcmds
    command: one of the sqcmds
    verbs: for each command, the list of verbs
    args: arguments
    """

    _test_command(get_cmd_object_dict[command], verb, None)