def test_help(capsys):
    """Checks for help output"""
    from schvalidator.cli import __doc__
    with pytest.raises(SystemExit):
        schvalidator.main(["", "--help"])
    out, _ = capsys.readouterr()
    assert out == __doc__.lstrip()
def test_use_wrong_schematron(tmpdir):
    schemafile = tmpdir / "schema.sch"
    xmlfile = tmpdir / "article.xml"
    schemafile.write(SCHEMATRON)
    xmlfile.write(XML)

    result = schvalidator.main(['--schema', str(schemafile), str(xmlfile)])
    assert result == ERROR_CODES.get(repr(XSLTParseError))
def test_main_with_exception(monkeypatch, schema, xmlfile):
    # Patching etree.parse
    monkeypatch.setattr('schvalidator.cli.parsecli', {
        '--schema': schema,
        'XMLFILE': xmlfile
    })
    result = schvalidator.main(["", "--schema", "schema.sch"])
    assert result == ERROR_CODES[FileNotFoundError]
示例#4
0
def test_main_mock_parsecli(monkeypatch):
    """ """
    def mock_parsecli(cliargs=None):
        return {'--schema': None,
                'XMLFILE':  None,
                }

    monkeypatch.setattr(schvalidator,
                        'parsecli',
                        mock_parsecli)

    result = schvalidator.main()
    assert result == ERROR_CODES[ProjectFilesNotFoundError]
示例#5
0
def test_main_mock_parsecli_process(monkeypatch):
    """ """
    def mock_parsecli(cliargs=None):
        return {'--schema': "s.sch",
                '--phase': None,
                'XMLFILE':  "a.xml",
                }
    def mock_process(args):
        # Use a return code that is never be used in schvalidator:
        return -1

    monkeypatch.setattr(schvalidator,
                        'parsecli',
                        mock_parsecli)
    monkeypatch.setattr(schvalidator,
                        'process',
                        mock_process)
    assert schvalidator.main() == -1
示例#6
0
def test_main_raise_OSError(monkeypatch, excpt):
    def mock_parsecli(cliargs=None):
        return {'--schema': "s.sch",
                '--phase': None,
                'XMLFILE':  "a.xml",
                }
    def mock_process(args):
        raise excpt()

    monkeypatch.setattr(schvalidator,
                        'parsecli',
                        mock_parsecli)
    monkeypatch.setattr(schvalidator,
                        'process',
                        mock_process)

    result = schvalidator.main()
    assert result == ERROR_CODES[excpt]
示例#7
0
#
# Copyright (c) 2016 SUSE Linux GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 3 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact SUSE LLC.
#
# To contact SUSE about this file by physical or electronic mail,
# you may find current contact information at www.suse.com

"""Support 'python -m schvalidator' call with __main__.py"""

import sys
from schvalidator import main


if __name__ == "__main__":
    sys.exit(main(sys.argv))
def test_invalid():
    """Checks for invalid option"""
    with pytest.raises(docopt.DocoptExit):
        schvalidator.main(["", "--asdf"])
def test_version(capsys):
    """Checks for correct version"""
    with pytest.raises(SystemExit):
        schvalidator.main(["", "--version"])
    out, _ = capsys.readouterr()
    assert out == "schvalidator {0}\n".format(schvalidator.__version__)