def test_validate_correct_namespace():
    """
    validate_wrapper.py: Test validate() on a correct namespace object
    """
    a = WrapSpace(w="{ }")
    assert v.validate(a)

    b = WrapSpace(w="[-->       <--]")
    assert v.validate(b)

    c = WrapSpace(w="$$$$ $$$$")
    assert v.validate(c)
def test_validate_correct():
    """
    validate_wrapper.py: Test validate() on correct wrapper strings
    """
    a = "{ }"
    assert v.validate(a)

    b = "[-->       <--]"
    assert v.validate(b)

    c = "$$$$ $$$$"
    assert v.validate(c)
Esempio n. 3
0
def _validate(opts):
    """
    Perform validation operations on opts, a namespace created from
    command-line arguments. Returns True if all validation tests are successful.

    Runs validation() methods in validate_input.py, validate_extensions.py,
    validate_overwrite.py, and validate_wrapper.py

    Required attributes on opts:
    * input: String giving the path to input files
    * output: String giving the path to output destination
    * wrapper: String specifying the wrapper format
    * extensions: List of strings specifying the file extensions to look for
    * overwrite: Boolean specifying whether the original input files should
                 be overridden

    :param opts: namespace containing necessary parameters
    :raises ValidationException: if one or more of the tests are unsuccessful
    :raises ValueError: if opts is not a namespace with the correct parameters
    :return: True, if all tests are successful
    """
    if all([
            vi.validate(opts),
            ve.validate(opts),
            vw.validate(opts),
            vo.validate(opts)
    ]):
        return True
    else:
        raise ValidationException("Arguments did not pass validation. Check "
                                  "your inputs.")
Esempio n. 4
0
def _validate(opts):
    """
    Perform validation operations on opts, a namespace created from
    command-line arguments. Returns True if all validation tests are successful.

    Runs validation() methods in validate_input.py, validate_extensions.py,
    validate_overwrite.py, and validate_wrapper.py

    Required attributes on opts:
    * input: String giving the path to input files
    * output: String giving the path to output destination
    * wrapper: String specifying the wrapper format
    * extensions: List of strings specifying the file extensions to look for
    * overwrite: Boolean specifying whether the original input files should
                 be overridden

    :param opts: namespace containing necessary parameters
    :raises ValidationException: if one or more of the tests are unsuccessful
    :raises ValueError: if opts is not a namespace with the correct parameters
    :return: True, if all tests are successful
    """
    if all([vi.validate(opts),
            ve.validate(opts),
            vw.validate(opts),
            vo.validate(opts)]):
        return True
    else:
        raise ValidationException("Arguments did not pass validation. Check "
                                  "your inputs.")
def test_validate_incorrect_too_many_strings():
    """
    validate_wrapper.py: Test validate() using a string with too many 'words'

    :raises ValidationException: always, if the test is working
    """
    assert v.validate("TOO MANY WORDS")
def test_validate_incorrect_empty_string():
    """
    validate_wrapper.py: Test validate() with an empty string

    :raises ValidationException: always, if the test is working
    """
    assert v.validate("")
def test_validate_no_wrapper_attr():
    """
    validate_wrapper.py: Test validate() with an object lacking attr 'wrapper'

    :raises ValueError: always, if the test is working
    """
    assert v.validate(object())
def test_validate_wrapper_attr_not_string():
    """
    validate_wrapper.py: Test validate() on namespace with non-string 'wrapper'

    :raises ValueError: always, if the test is working
    """
    a = WrapSpace(w=3)
    assert v.validate(a)
def test_validate_incorrect_too_many_strings_namespace():
    """
    validate_wrapper.py: Test validate() on a namespace with too many 'words'

    :raises ValidationException: always, if the test is working
    """
    a = WrapSpace(w="TOO MANY WORDS")
    assert v.validate(a)
def test_validate_incorrect_empty_string_namespace():
    """
    validate_wrapper.py: Test validate() on a namespace with an empty string

    :raises ValidationException: always, if the test is working
    """
    a = WrapSpace(w="")
    assert v.validate(a)