コード例 #1
0
def test_parser_setup():
    """Test the basic functionality of a parser"""

    # Parser without a path
    parser = devspell.parser.Parser(None)
    assert not parser.path
    assert parser.enchant
    assert not parser.parse()

    # Parser with a path which doesn't exist
    parser = devspell.parser.Parser("._does_not_exist_")
    assert not parser.parse()

    # Parser with a path
    parser = devspell.parser.Parser(get_path("empty.txt"))
    assert parser.path
    assert parser.enchant
    assert parser.parse()

    # Parser with a symlink
    parser = devspell.parser.Parser(get_path("symlink"))
    assert parser.parse()

    # Parser with a dictionary set
    parser = devspell.parser.Parser(get_path("empty.txt"),
                                    dictionary=get_dict("empty"))
    assert parser.path
    assert parser.enchant

    # Add a word
    parser.words.words["bob"] = devspell.parser.Word("bob", "some-path", 30)
    parser.words.words["jim"] = devspell.parser.Word("jim", "some-path", 50)
    parser.words.words["jim"].ok = False
    parser.show()
    parser.show(quiet=True)
コード例 #2
0
ファイル: test_document.py プロジェクト: darless1/devspell
def test_doc_setup():
    """Test the basic functionality of a document"""

    parser = devspell.parser.Parser(get_path("test_dir1"))
    path = get_path("test_file1.txt")

    # Initialize a doc with an extension which is not valid
    doc = devspell.parser.Document(parser, "JIM.JIM")
    assert doc.content is None
    assert doc.exten == '.JIM'

    # Work with a document
    doc = devspell.parser.Document(parser, path)
    assert doc.path == path
    assert doc.content is not None
    assert doc.exten == '.txt'
    print(doc)
    assert doc.parse()
    doc.exten = '_NOT_VALID'
    assert not doc.parse()

    # Parse a known dictonary for this file
    parser = devspell.parser.Parser(get_path("test_dir1"))
    doc = devspell.parser.Document(parser, path)
    doc.parser.dictionary.parse(path=get_dict("simple.yaml"))
    assert doc.parser.dictionary.has_word('wong')
    assert doc.parse()

    # Check a word with a line number
    doc.check_word('testword', 300)
    doc.check_word('anotherword', None)
    doc.check_word('Wvord', 100)
    doc.check_word('wong', 100)
    parser.words.get('testword').show_verbose()
    parser.words.get('anotherword').show_verbose()
コード例 #3
0
def test_parser_create_dict():
    """Create a dictionary based on the current words"""
    parser = devspell.parser.Parser(get_path("test_dir1"))
    assert parser.parse()
    dict_path = "/tmp/.test_parser_create_dict"
    parser.create_dictionary(dict_path)
    assert os.path.exists(dict_path)
コード例 #4
0
def test_parser_dir():
    """Parse a directory"""
    parser = devspell.parser.Parser(get_path("test_dir1"))
    assert parser.parse()

    assert parser.words.has_invalid("wong")
    assert parser.words.has_invalid("vord")
    assert parser.words.has_valid("file")
    assert parser.words.has_valid("which")
コード例 #5
0
def test_parser_file():
    """Parse a file"""
    parser = devspell.parser.Parser(get_path("test_file1.txt"))
    assert parser.parse()
    assert parser.words.has_invalid("wong")
    assert parser.words.has_invalid("wvord")
    assert not parser.words.has_valid("wvord")
    assert parser.words.has_valid("sample")
    assert parser.words.has_valid("file")

    parser.only = ["py"]
    assert not parser.parse()
コード例 #6
0
def test_python_basic():
    """Test the basic operation of the Python parser"""
    parser = PyParser(None)
    assert not parser.path
    assert not parser.content

    parser = PyParser("does.not.exist")
    assert not parser.content

    path = get_path("parsers/python/basic.py")
    parser = PyParser(path)
    assert not parser.sections.has_section("!/usr/bin/python")
    assert parser.sections.has_section("This is a single comment")
    assert parser.sections.has_section("Information about test")
    assert parser.sections.has_section("This is my life")
    assert parser.sections.has_section("Comment about")
    assert parser.sections.has_section("Bob's life")
    assert parser.sections.has_section("Bob's fun life")