summaryrefslogtreecommitdiff
path: root/tests/test_cli.py
blob: 33da6982e12e26813cacc48693e543bee195c52e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-

# python std lib
import os
import sys

# pykwalify package imports
from pykwalify import cli


class TestCLI(object):

    def test_cli(self, tmpdir):
        """
        Test that when passing in certain arguments from commandline they
        are handled correctly by docopt and correct args structure is returned.
        """
        input = tmpdir.join("cli/1a.yaml")
        schema_file = tmpdir.join("cli/1b.yaml")

        sys.argv = [
            'scripts/pykwalify',
            '-d', str(input),
            '-s', str(schema_file),
            '-v'
        ]

        expected = {
            '--data-file': str(input),
            '--schema-file': [str(schema_file)],
            '--quiet': False,
            '--verbose': 1,
        }

        cli_args = cli.parse_cli()

        for k, v in expected.items():
            assert k in cli_args
            assert cli_args[k] == expected[k]

    def f(self, *args):
        """
        Returns abs path to test files inside tests/files/
        """
        return os.path.join(os.path.dirname(os.path.realpath(__file__)), "files", *args)

    def test_run_cli(self):
        """
        This should test that running the cli still works as expected
        """
        input = self.f("cli/1a.yaml")
        schema_file = self.f("cli/1b.yaml")

        sys.argv = [
            'scripts/pykwalify',
            '-d', str(input),
            '-s', str(schema_file),
        ]

        cli_args = cli.parse_cli()
        c = cli.run(cli_args)
        assert c.validation_errors == []