示例#1
0
def test_optional():
    foo = xmlfied('foo', bar=Element().if_(lambda x: '123' not in x))

    assert_that(etree.tostring(foo(bar=' 123 ').toxml()),
                string_contains_in_order('<foo/>'))
    assert_that(etree.tostring(foo(bar=' 12 3').toxml()),
                string_contains_in_order('<foo>', '<bar>'))
示例#2
0
def test_missing_fixture(report_for):
    report = report_for("""
    def test_X(FOO):
        assert True
    """)

    assert_that(report, has_error(message=string_contains_in_order('FixtureLookupError'),
                                  trace=string_contains_in_order("fixture 'FOO' not found",
                                                                            'available fixtures',)))
示例#3
0
def test_missing_fixture(report_for):
    report = report_for("""
    def test_X(FOO):
        assert True
    """)

    assert_that(report, has_error(message=string_contains_in_order('FixtureLookupError'),
                                  status=Status.BROKEN,
                                  trace=string_contains_in_order("fixture 'FOO' not found",
                                                                 'available fixtures',)))
示例#4
0
def test_many_elements():
    Box = xmlfied('box', foos=WrappedMany(Element(name='foo')))

    box = Box(foos=['a', 'b', 'c'])

    assert_that(get_xml_string(box.toxml()), all_of(
        string_contains_in_order('<box>', '<foos>', '<foo>', 'a', '</foo>', '</foos>', '</box>'),
        string_contains_in_order('<box>', '<foos>', '<foo>', 'b', '</foo>', '</foos>', '</box>'),
        string_contains_in_order('<box>', '<foos>', '<foo>', 'c', '</foo>', '</foos>', '</box>')
    ))
示例#5
0
def test_many_elements():
    Box = xmlfied('box', foos=Many(Element(name='foo')))

    box = Box(foos=['a', 'b', 'c'])

    assert_that(etree.tostring(box.toxml()), all_of(
                                                    string_contains_in_order('<box>', '<foos>', '<foo>', 'a', '</foo>', '</foos>', '</box>'),
                                                    string_contains_in_order('<box>', '<foos>', '<foo>', 'b', '</foo>', '</foos>', '</box>'),
                                                    string_contains_in_order('<box>', '<foos>', '<foo>', 'c', '</foo>', '</foos>', '</box>'),
                                                    ))
示例#6
0
def test_element_name():
    foo = xmlfied('foo', bar=Element(name='foo-bar'))

    assert_that(
        etree.tostring(foo(bar='123').toxml()),
        string_contains_in_order('<foo>', '<foo-bar>', '123', '</foo-bar>',
                                 '</foo>'))
示例#7
0
def test_bad_symbols_replacement():
    foo = xmlfied('foo', bar=Element(name='bar'))

    assert_that(
        etree.tostring(foo(bar=u'abОЛОЛОcd'.encode('cp1251')).toxml()),
        string_contains_in_order('<bar>', 'ab', '&#65533;' * 4, 'cd',
                                 '</bar>'))
示例#8
0
def test_attribute():
    AttrTest = xmlfied('attr_test', foo=Attribute())

    a = AttrTest(foo='bar')

    assert_that(etree.tostring(a.toxml()),
                string_contains_in_order('<attr_test', 'foo=', '"bar"', ">"))
示例#9
0
def test_element():
    ElementTest = xmlfied('element_test', ab=Element())

    a = ElementTest(ab='foo')
    assert_that(get_xml_string(a.toxml()), string_contains_in_order('<element_test>',
                                                                    '<ab>foo</ab>',
                                                                    '</element_test>'))
示例#10
0
def test_collect_error(report_for):
    report = report_for("""
    def test_Y():
        foo(
    """)

    assert_that(report, has_error(message='failed',
                                  trace=string_contains_in_order('import',
                                                                            'SyntaxError')))
示例#11
0
def test_smoke(report_for):
    report = report_for("""
    def test_X():
        raise RuntimeError("Foo bar baz")
    """)

    assert_that(report, has_error(message='RuntimeError: Foo bar baz',
                                  trace=string_contains_in_order('raise',
                                                                 'RuntimeError("Foo bar baz")',
                                                                 "RuntimeError: Foo bar baz")))
示例#12
0
def test_smoke(report_for):
    report = report_for("""
    def test_X():
        raise RuntimeError("Foo bar baz")
    """)

    assert_that(report, has_error(message='RuntimeError: Foo bar baz',
                                  trace=string_contains_in_order('raise',
                                                                            'RuntimeError("Foo bar baz")',
                                                                            "RuntimeError: Foo bar baz")))
示例#13
0
def test_collect_error(report_for):
    report = report_for("""
    def test_Y():
        foo(
    """)

    assert_that(
        report,
        has_error(message='failed',
                  trace=string_contains_in_order('import', 'SyntaxError')))
示例#14
0
def test_nested():
    Top = xmlfied('top', foo=Nested())
    Down = xmlfied('down', bar=Element(), baz=Attribute())

    d = Down(bar='123', baz='456')
    t = Top(foo=d)

    assert_that(
        etree.tostring(t.toxml()),
        string_contains_in_order('<top>', '<down', 'baz=', '"456"', '<bar>',
                                 '123', '</bar>', '</down>', '</top>'))
示例#15
0
def test_elements_order():
    Foo = xmlfied('foo',
                  fields=[('bar', Element()), ('baz', Element()),
                          ('gaz', Element()), ('daz', Element())])

    foo = Foo(bar=3, baz=4, gaz=5, daz=6)

    assert_that(
        etree.tostring(foo.toxml()),
        string_contains_in_order('<bar>', '3', '</bar>', '<baz>', '4',
                                 '</baz>', '<gaz>', '5', '</gaz>', '<daz>',
                                 '6', '</daz>'))
示例#16
0
def test_xfail(report_for):
    report = report_for("""
    import pytest

    @pytest.mark.xfail(reason='ololo')
    def test_Y():
        assert False
    """)

    assert_that(report, has_error(message='ololo',
                                  status=Status.PENDING,
                                  trace=string_contains_in_order('assert False',
                                                                 'AssertionError')))
示例#17
0
def test_elements_order():
    Foo = xmlfied('foo', fields=[
                                  ('bar', Element()),
                                  ('baz', Element()),
                                  ('gaz', Element()),
                                  ('daz', Element())])

    foo = Foo(bar=3, baz=4, gaz=5, daz=6)

    assert_that(etree.tostring(foo.toxml()), string_contains_in_order(
                                                                      '<bar>', '3', '</bar>',
                                                                      '<baz>', '4', '</baz>',
                                                                      '<gaz>', '5', '</gaz>',
                                                                      '<daz>', '6', '</daz>'
                                                                      ))
示例#18
0
def test_many_nested():
    Item = xmlfied('item', value=Element())
    Box = xmlfied('box', items=WrappedMany(Nested()))

    box = Box(items=[])
    box.items.append(Item('a'))
    box.items.append(Item('a'))
    box.items.append(Item('a'))

    assert_that(
        etree.tostring(box.toxml()),
        all_of(
            string_contains_in_order('<box>', '<items>', '<item>', 'a',
                                     '</item>', '<item>', 'a', '</item>',
                                     '<item>', 'a', '</item>', '</items>',
                                     '</box>'), ))
示例#19
0
def test_setup_error(report_for):
    report = report_for("""
    import pytest

    @pytest.fixture
    def FOO():
        raise RuntimeError("ololo")

    def test_X(FOO):
        assert True
    """)

    assert_that(report, has_error(message='RuntimeError: ololo',
                                  trace=string_contains_in_order('FOO',
                                                                            'raise',
                                                                            'RuntimeError("ololo")',
                                                                            "RuntimeError: ololo")))
示例#20
0
def test_nested():
    Top = xmlfied('top', foo=Nested())
    Down = xmlfied('down', bar=Element(), baz=Attribute())

    d = Down(bar='123', baz='456')
    t = Top(foo=d)

    assert_that(etree.tostring(t.toxml()), string_contains_in_order(
                                                           '<top>',
                                                           '<down',
                                                           'baz=', '"456"',
                                                           '<bar>',
                                                           '123',
                                                           '</bar>',
                                                           '</down>',
                                                           '</top>'
                                                           ))
示例#21
0
def test_setup_error(report_for):
    report = report_for("""
    import pytest

    @pytest.fixture
    def FOO():
        raise RuntimeError("ololo")

    def test_X(FOO):
        assert True
    """)

    assert_that(
        report,
        has_error(message='RuntimeError: ololo',
                  trace=string_contains_in_order('FOO', 'raise',
                                                 'RuntimeError("ololo")',
                                                 "RuntimeError: ololo")))
示例#22
0
def test_many_nested():
    Item = xmlfied('item', value=Element())
    Box = xmlfied('box', items=Many(Nested()))

    box = Box(items=[])
    box.items.append(Item('a'))
    box.items.append(Item('a'))
    box.items.append(Item('a'))

    assert_that(etree.tostring(box.toxml()), all_of(
                                                    string_contains_in_order('<box>',
                                                                             '<items>',
                                                                             '<item>', 'a', '</item>',
                                                                             '<item>', 'a', '</item>',
                                                                             '<item>', 'a', '</item>',
                                                                             '</items>',
                                                                             '</box>'),
                                                    ))
示例#23
0
def test_optional():
    foo = xmlfied('foo', bar=Element().if_(lambda x: '123' not in x))

    assert_that(etree.tostring(foo(bar=' 123 ').toxml()), string_contains_in_order('<foo/>'))
    assert_that(etree.tostring(foo(bar=' 12 3').toxml()), string_contains_in_order('<foo>', '<bar>'))
示例#24
0
def test_element_name():
    foo = xmlfied('foo', bar=Element(name='foo-bar'))

    assert_that(etree.tostring(foo(bar='123').toxml()), string_contains_in_order('<foo>', '<foo-bar>', '123', '</foo-bar>', '</foo>'))
示例#25
0
def test_bad_symbols_replacement():
    foo = xmlfied('foo', bar=Element(name='bar'))

    assert_that(etree.tostring(foo(bar=u'abОЛОЛОcd'.encode('cp1251')).toxml()), string_contains_in_order('<bar>', 'ab', '&#65533;' * 4, 'cd', '</bar>'))
示例#26
0
def test_attribute():
    AttrTest = xmlfied('attr_test', foo=Attribute())

    a = AttrTest(foo='bar')

    assert_that(etree.tostring(a.toxml()), string_contains_in_order('<attr_test', 'foo=', '"bar"', ">"))