1. Antoine Millet
  2. Dotconf

Commits

Antoine Millet  committed 48a46ff

Moved tests in a separated sub-package

  • Participants
  • Parent commits ed96d7d
  • Branches master

Comments (0)

Files changed (3)

File dotconf/parser.py

View file
             raise AttributeError("'%s' object has no attribute '%s'" % (self, name))
         else:
             return attr
-
-#
-# Tests
-#
-
-from nose.tools import eq_
-
-
-def test_lexer():
-    #          Test string            Expected tok     Expected tok value
-    tokens = (('name',                'NAME',          'name'),
-              ('"test"',              'TEXT',          'test'),
-              ("'test'",              'TEXT',          'test'),
-              (r"'te\'st'",           'TEXT',          "te'st"),
-              ('42',                  'NUMBER',        42),
-              ('42.1',                'NUMBER',        42.1),
-              ('+42',                 'NUMBER',        42),
-              ('+42.1',               'NUMBER',        42.1),
-              ('-42',                 'NUMBER',        -42),
-              ('-42.1',               'NUMBER',        -42.1),
-              ('{',                   'LBRACE',        '{'),
-              ('}',                   'RBRACE',        '}'),
-              ('=',                   'ASSIGN',        '='))
-    for test, expected_type, expected_value in tokens:
-        yield check_token, test, expected_type, expected_value
-
-
-def check_token(test, expected_type, expected_value):
-    lexer = DotconfLexer()
-    lexer.input(test)
-    token = lexer.next()
-    eq_(token.type, expected_type)
-    eq_(token.value, expected_value)
-
-def test_parser_basic():
-    test = '''
-    daemon = yes  # This is a comment after an assignation
-    # This is comment
-    '''
-    lexer = DotconfLexer()
-    parser = DotconfParser(debug=True, write_tables=False, errorlog=yacc.NullLogger())
-    output = parser.parse(test, lexer=lexer, tracking=True)
-    eq_(output.get('daemon'), True)
-
-def test_parser_list():
-    test = '''
-    list1 = 1, 2, 3
-    list2 = 1, 2, 3,
-    list3 = 1,
-    list4 = 1,
-            2,
-            3
-    list5 = 1,
-            2,
-            3,
-    '''
-    lexer = DotconfLexer()
-    parser = DotconfParser(debug=True, write_tables=False, errorlog=yacc.NullLogger())
-    output = parser.parse(test, lexer=lexer, tracking=True)
-    eq_(output.get('list1'), [1, 2, 3])
-    eq_(output.get('list2'), [1, 2, 3])
-    eq_(output.get('list3'), [1])
-    eq_(output.get('list4'), [1, 2, 3])
-    eq_(output.get('list5'), [1, 2, 3])
-
-def test_parser_section():
-    test = '''
-    section1 {
-        key = 'test'
-    }
-    section2 'arg' {}
-    section3 'arg1', 'arg2' {}
-    '''
-    lexer = DotconfLexer()
-    parser = DotconfParser(debug=True, write_tables=False, errorlog=yacc.NullLogger())
-    output = parser.parse(test, lexer=lexer, tracking=True)
-    eq_(tuple(output.subsections('section1'))[0].get('key'), 'test')
-    eq_(tuple(output.subsections('section2'))[0].args, ['arg'])
-    eq_(tuple(output.subsections('section3'))[0].args, ['arg1', 'arg2'])
-
-def test_parser_empty():
-    test = ''''''
-    lexer = DotconfLexer()
-    parser = DotconfParser(debug=True, write_tables=False, errorlog=yacc.NullLogger())
-    output = parser.parse(test, lexer=lexer, tracking=True)

File dotconf/tests/__init__.py

Empty file added.

File dotconf/tests/test_parser.py

View file
+""" Dotconf's parser tests.
+"""
+
+from dotconf.parser import DotconfLexer, DotconfParser
+
+import ply.yacc as yacc
+
+from nose.tools import eq_
+
+
+def test_lexer():
+    #          Test string            Expected tok     Expected tok value
+    tokens = (('name',                'NAME',          'name'),
+              ('"test"',              'TEXT',          'test'),
+              ("'test'",              'TEXT',          'test'),
+              (r"'te\'st'",           'TEXT',          "te'st"),
+              ('42',                  'NUMBER',        42),
+              ('42.1',                'NUMBER',        42.1),
+              ('+42',                 'NUMBER',        42),
+              ('+42.1',               'NUMBER',        42.1),
+              ('-42',                 'NUMBER',        -42),
+              ('-42.1',               'NUMBER',        -42.1),
+              ('{',                   'LBRACE',        '{'),
+              ('}',                   'RBRACE',        '}'),
+              ('=',                   'ASSIGN',        '='))
+    for test, expected_type, expected_value in tokens:
+        yield check_token, test, expected_type, expected_value
+
+
+def check_token(test, expected_type, expected_value):
+    lexer = DotconfLexer()
+    lexer.input(test)
+    token = lexer.next()
+    eq_(token.type, expected_type)
+    eq_(token.value, expected_value)
+
+def test_parser_basic():
+    test = '''
+    daemon = yes  # This is a comment after an assignation
+    # This is comment
+    '''
+    lexer = DotconfLexer()
+    parser = DotconfParser(debug=True, write_tables=False, errorlog=yacc.NullLogger())
+    output = parser.parse(test, lexer=lexer, tracking=True)
+    eq_(output.get('daemon'), True)
+
+def test_parser_list():
+    test = '''
+    list1 = 1, 2, 3
+    list2 = 1, 2, 3,
+    list3 = 1,
+    list4 = 1,
+            2,
+            3
+    list5 = 1,
+            2,
+            3,
+    '''
+    lexer = DotconfLexer()
+    parser = DotconfParser(debug=True, write_tables=False, errorlog=yacc.NullLogger())
+    output = parser.parse(test, lexer=lexer, tracking=True)
+    eq_(output.get('list1'), [1, 2, 3])
+    eq_(output.get('list2'), [1, 2, 3])
+    eq_(output.get('list3'), [1])
+    eq_(output.get('list4'), [1, 2, 3])
+    eq_(output.get('list5'), [1, 2, 3])
+
+def test_parser_section():
+    test = '''
+    section1 {
+        key = 'test'
+    }
+    section2 'arg' {}
+    section3 'arg1', 'arg2' {}
+    '''
+    lexer = DotconfLexer()
+    parser = DotconfParser(debug=True, write_tables=False, errorlog=yacc.NullLogger())
+    output = parser.parse(test, lexer=lexer, tracking=True)
+    eq_(tuple(output.subsections('section1'))[0].get('key'), 'test')
+    eq_(tuple(output.subsections('section2'))[0].args, ['arg'])
+    eq_(tuple(output.subsections('section3'))[0].args, ['arg1', 'arg2'])
+
+def test_parser_empty():
+    test = ''''''
+    lexer = DotconfLexer()
+    parser = DotconfParser(debug=True, write_tables=False, errorlog=yacc.NullLogger())
+    output = parser.parse(test, lexer=lexer, tracking=True)