Пример #1
0
    def test_newline(self):
        zbr = zebra.trim(
            """
            hello, world!

            this test is good \\
            if there is no break here
            i want a newline after this<tag/>
            the end
            """)

        goal = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            hello, world!<nl/>
            <nl/>
            this test is good if there is no break here<nl/>
            i want a newline after this&lt;tag/&gt;<nl/>
            the end<nl/>
            </zebra>
            """)

        actual = zebra.zbr2xml.Z2X().translate(zbr)
        assert actual==goal, \
               "zbr2xml doesn't handle newlines correctly:\n%s" % actual
Пример #2
0
    def test_notBlocks(self):
        zbr = zebra.trim(
            """
            * if x==1:
                * include page_one;
            * ef x==2:
                * include page_two;
            """)
        
        goal = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            <if condition="x==1">
            <include file="page_one"/>
            </if>
            <ef condition="x==2">
            <include file="page_two"/>
            </ef>
            </zebra>
            """)

        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "Doesn't handle ; blocks right:\n%s" % actual
Пример #3
0
    def test_indent(self):

        ## the blank line before the * checks for a
        ## whitespace error!
        zbr = zebra.trim(
            """
            This is normal text.
            * if 1==2:
                This should never show up.
            * el:
            This line isn't part of the else.
            """)

        goal = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            This is normal text.<nl/>
            <if condition="1==2">
            This should never show up.<nl/>
            </if>
            <el>
            </el>
            This line isn't part of the else.<nl/>
            </zebra>
            """)
        
        actual = zebra.zbr2xml.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't indent correctly:\n%s" % actual
Пример #4
0
    def test_exec(self):
        zbr = zebra.trim(
            """
            * exec:
                name = 'fred'
                xml = '<xml>woohoo!</xml>'
                dict = {}
                dict['a'] = 'b'

                hope(there_was_no_nl_tag_there)
            """)

        goal = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            <exec>
            name = 'fred'
            xml = '&lt;xml&gt;woohoo!&lt;/xml&gt;'
            dict = {}
            dict['a'] = 'b'

            hope(there_was_no_nl_tag_there)
            </exec>
            </zebra>
            """)
        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't cope well with exec:\n%s" % actual
Пример #5
0
 def handle_for(self, model, attrs):
     loopvar = self.gensym("loopvar")
     self.loopvars.append(loopvar)
     data = {"loopvar":loopvar}
     data.update(attrs)
     res = zebra.trim(
         '''
         _%(loopvar)s_max_ = len(scope["%(series)s"])
         for %(loopvar)s in range(_%(loopvar)s_max_):
             # handle scope inside the loop in case we have
             # recursive names (eg, children->children->children)
             scope_stack.append(copy.copy(scope))
             
             # can't do .update if it's a UserDict:
             mdl = scope["%(series)s"][%(loopvar)s]
             for item in mdl.keys():
                 scope[item]=mdl[item]
         ''' % data)
     res = res + zebra.indent(self.walk(model), 1)            
     res = res + zebra.trim(
         '''
         #   ## close for-%(series)s loop ##########
             globals().update(scope_stack.pop())
         ''' % attrs)
     self.lastLoopvar = self.loopvars.pop()
     return res
Пример #6
0
    def test_exec(self):
        zbr = zebra.trim("""
            * exec:
                name = 'fred'
                xml = '<xml>woohoo!</xml>'
                dict = {}
                dict['a'] = 'b'

                hope(there_was_no_nl_tag_there)
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <exec>
            name = 'fred'
            xml = '&lt;xml&gt;woohoo!&lt;/xml&gt;'
            dict = {}
            dict['a'] = 'b'

            hope(there_was_no_nl_tag_there)
            </exec>
            </zebra>
            """)
        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't cope well with exec:\n%s" % actual
Пример #7
0
    def test_indent(self):

        ## the blank line before the * checks for a
        ## whitespace error!
        zbr = zebra.trim("""
            This is normal text.
            * if 1==2:
                This should never show up.
            * el:
            This line isn't part of the else.
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            This is normal text.<nl/>
            <if condition="1==2">
            This should never show up.<nl/>
            </if>
            <el>
            </el>
            This line isn't part of the else.<nl/>
            </zebra>
            """)

        actual = zebra.zbr2xml.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't indent correctly:\n%s" % actual
Пример #8
0
    def test_forHeadBodyFoot(self):
        zbr = zebra.trim("""
            * for people:
                * head:
                    PEOPLE
                    -------
                * body:
                    {?name?} is a nice person.
                * foot:
                    -------
                    THE END
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <for series="people">
            <head>
            PEOPLE<nl/>
            -------<nl/>
            </head>
            <body>
            <var>name</var> is a nice person.<nl/>
            </body>
            <foot>
            -------<nl/>
            THE END<nl/>
            </foot>
            </for>
            </zebra>
            """)

        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "Doesn't do for/head/body/foot right:\n%s" % actual
Пример #9
0
    def test_forNone(self):
        zbr = zebra.trim(
            """
            * for people:
                {?name?} is a nice person.
            * none:
                No people here!
            """)
        
        goal = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            <for series="people">
            <var>name</var> is a nice person.<nl/>
            </for>
            <none>
            No people here!<nl/>
            </none>
            </zebra>
            """)

        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "Doesn't do for..none right:\n%s" % actual
Пример #10
0
    def test_xmlchars(self):
        zbr = zebra.trim("""
            <P>Hello&nbsp;World!!! ><
            """)
        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            &lt;P&gt;Hello&amp;nbsp;World!!! &gt;&lt;<nl/>
            </zebra>
            """)

        actual = zebra.zbr2xml.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't cope with xmlchars correctly:\n%s" % actual
Пример #11
0
    def test_expr(self):
        zbr = zebra.trim("""
            I will be {:age + 4:} next year.
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            I will be <xpr>age + 4</xpr> next year.<nl/>
            </zebra>
            """)
        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't cope well with {:exprs:}:\n%s" % actual
Пример #12
0
    def check_for(self):

        model = {
            "a":
            "alaska",
            "stuff": [
                {
                    "a": "apple",
                    "b": "banana",
                    "c": "cherry"
                },
                {
                    "a": "aardvark",
                    "b": "bull weevil",
                    "c": "catepillar"
                },
                {
                    "a": "alice",
                    "b": "betty",
                    "c": "carol"
                },
            ],
        }

        zbx = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <rem>test scope</rem>
            <xpr>a</xpr><nl/>
            <for series="stuff">
            <xpr>a</xpr>, <xpr>b</xpr>, <xpr>c</xpr>
            <nl/>
            </for>
            <xpr>a</xpr><nl/>
            </zebra>
            """)

        goal = zebra.trim("""
            alaska
            apple, banana, cherry
            aardvark, bull weevil, catepillar
            alice, betty, carol
            alaska
            """)

        actual = zebra.Bootstrap().toObject(zbx).fetch(model)
        assert actual == goal, \
               "for() loops don't work:\n---\n%s---" % actual
Пример #13
0
    def handle_zebra(self, model, attrs):
        res = zebra.trim(
            """
            class Report:
            
                def show(self, model={}):
                    print self.fetch(model)

                def fetch(self, model={}):
                    import copy   # used for pushing scope onto stack

                    scope = globals()
                    # This scope thing is so that we can generate
                    # code that says:
                    #
                    #         zres = zres + x
                    # *OR*
                    #         zres = zres + scope.get(x, '')
                    #
                    # It also actually does variable scoping,
                    # when combined with scope_stack, below.
                    #
                    # I wanted to use scope=locals(), but
                    # then the 'zres + x' wouldn't work.
                    # @TODO: is this scope scheme threadsafe?
                    
                    scope_stack = []

                    # scope.update(model), but model might be a UserDict:
                    for item in model.keys():
                        scope[item] = model[item]

                    # zres is the result (the output we're building)
                    zres = ""
            """)
        res = res + zebra.indent(self.walk(model), 2)
        res = res + zebra.trim(
            ''' 
            # end of Report.fetch()
                    return zres

            def fetch(model={}):
                return Report().fetch(model)
                
            def show(model={}):
                return Report().show(model)
            ''')
        return res
Пример #14
0
    def check_none(self):
        model = {"emptylist": [], "fulllist": [{"a": "b"}]}
        zbx = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <for series="emptylist">
            THIS SHOULD NOT SHOW UP
            </for>
            <none>
            Nothin's empty. 
            </none>
            <for series="fulllist">
            Somethin's full.
            </for>
            <none>
            THIS SHOULD NOT SHOW UP
            </none>
            </zebra>
            """)

        goal = "Nothin's empty. Somethin's full."

        actual = zebra.Bootstrap().toObject(zbx).fetch(model)
        assert actual == goal, \
               "none doesn't work:\n%s" % actual
Пример #15
0
 def check_nested_for(self):
     model = {
         "all": [{
             "subs": [{
                 "value": "a"
             }]
         }, {
             "subs": [{
                 "value": "b"
             }]
         }]
     }
     zbx = zebra.trim("""
         <?xml version="1.0"?>
         <zebra>
         <for series="all">
         <head>[</head>
         <for series="subs">
         <head>{</head>
         <var>value</var>
         <foot>}</foot>
         </for>
         <foot>]</foot>
         </for>
         </zebra>
         """)
     goal = "[{a}{b}]"
     actual = zebra.Bootstrap().toObject(zbx).fetch(model)
     self.assertEquals(actual, goal)
Пример #16
0
    def check_none(self):
        model = {"emptylist": [], "fulllist": [{"a": "b"}]}
        zbx = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            <for series="emptylist">
            THIS SHOULD NOT SHOW UP
            </for>
            <none>
            Nothin's empty. 
            </none>
            <for series="fulllist">
            Somethin's full.
            </for>
            <none>
            THIS SHOULD NOT SHOW UP
            </none>
            </zebra>
            """
        )

        goal = "Nothin's empty. Somethin's full."

        actual = zebra.Bootstrap().toObject(zbx).fetch(model)
        assert actual == goal, "none doesn't work:\n%s" % actual
Пример #17
0
    def test_xmlchars(self):
        zbr = zebra.trim(
            """
            <P>Hello&nbsp;World!!! ><
            """)
        goal = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            &lt;P&gt;Hello&amp;nbsp;World!!! &gt;&lt;<nl/>
            </zebra>
            """)

        actual = zebra.zbr2xml.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't cope with xmlchars correctly:\n%s" % actual
Пример #18
0
    def test_expr(self):
        zbr = zebra.trim(
            """
            I will be {:age + 4:} next year.
            """)

        goal = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            I will be <xpr>age + 4</xpr> next year.<nl/>
            </zebra>
            """)
        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't cope well with {:exprs:}:\n%s" % actual
Пример #19
0
    def check_headFootSimple(self):

        # check the simple case, not the grouped version.

        model = {"list": [{"toy": "ball"}, {"toy": "yoyo"}]}

        zbx = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            <for series="list">
            <head>Some toys: [</head>
            <var>toy</var>
            <glue>, </glue>
            <foot>]</foot>
            </for>
            </zebra>
            """
        )

        goal = "Some toys: [ball, yoyo]"

        ##         print '--------'
        ##         print zebra.Bootstrap().compile(zbx)
        ##         print '--------'

        actual = zebra.Bootstrap().toObject(zbx).fetch(model)
        assert actual == goal, "head/tails don't work:\n%s" % actual
Пример #20
0
    def test_include(self):
        #@TODO: drop trailing : from include syntax
        zbr = zebra.trim("""
            * include includefile:
            """)

        #@TODO: it should realy be <include file="includefile"/>
        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <include file="includefile">
            </include>
            </zebra>
            """)
        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't handle includes right:\n%s" % actual
Пример #21
0
 def test_comment(self):
     zbr = zebra.trim("""
         *# this is a comment
         this isn't
         *     # this is
         """)
     goal = zebra.trim("""
         <?xml version="1.0"?>
         <zebra>
         <rem>this is a comment</rem>
         this isn't<nl/>
         <rem>this is</rem>
         </zebra>
         """)
     actual = zebra.Z2X().translate(zbr)
     assert actual==goal, \
            "doesn't handle comments right:\n%s" % actual
Пример #22
0
    def handle_zebra(self, model, attrs):
        res = zebra.trim("""
            class Report:
            
                def show(self, model={}):
                    print self.fetch(model)

                def fetch(self, model={}):
                    import copy   # used for pushing scope onto stack

                    scope = globals()
                    # This scope thing is so that we can generate
                    # code that says:
                    #
                    #         zres = zres + x
                    # *OR*
                    #         zres = zres + scope.get(x, '')
                    #
                    # It also actually does variable scoping,
                    # when combined with scope_stack, below.
                    #
                    # I wanted to use scope=locals(), but
                    # then the 'zres + x' wouldn't work.
                    # @TODO: is this scope scheme threadsafe?
                    
                    scope_stack = []

                    # scope.update(model), but model might be a UserDict:
                    for item in model.keys():
                        scope[item] = model[item]

                    # zres is the result (the output we're building)
                    zres = ""
            """)
        res = res + zebra.indent(self.walk(model), 2)
        res = res + zebra.trim(''' 
            # end of Report.fetch()
                    return zres

            def fetch(model={}):
                return Report().fetch(model)
                
            def show(model={}):
                return Report().show(model)
            ''')
        return res
Пример #23
0
    def test_var(self):
        zbr = zebra.trim("""
            {
            My name is {?name?}.
            }
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            {<nl/>
            My name is <var>name</var>.<nl/>
            }<nl/>
            </zebra>
            """)
        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't cope well with {?vars?}:\n%s" % actual
Пример #24
0
 def test_comment(self):
     zbr = zebra.trim(
         """
         *# this is a comment
         this isn't
         *     # this is
         """)
     goal = zebra.trim(
         """
         <?xml version="1.0"?>
         <zebra>
         <rem>this is a comment</rem>
         this isn't<nl/>
         <rem>this is</rem>
         </zebra>
         """)
     actual = zebra.Z2X().translate(zbr)
     assert actual==goal, \
            "doesn't handle comments right:\n%s" % actual
Пример #25
0
    def test_include(self):
        #@TODO: drop trailing : from include syntax
        zbr = zebra.trim(
            """
            * include includefile:
            """)

        #@TODO: it should realy be <include file="includefile"/>
        goal = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            <include file="includefile">
            </include>
            </zebra>
            """)
        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't handle includes right:\n%s" % actual
Пример #26
0
 def check_whitespace(self):
     zbx = zebra.trim("""
         <zebra>
         <xpr>5</xpr> <xpr>2</xpr><nl/>
         </zebra>
         """)
     goal = "5 2\n"
     actual = zebra.Bootstrap().toObject(zbx).fetch()
     assert actual == goal, \
            "whitespace is screwed up:\n%s" % actual
Пример #27
0
 def check_whitespace(self):
     zbx = zebra.trim(
         """
         <zebra>
         <xpr>5</xpr> <xpr>2</xpr><nl/>
         </zebra>
         """
     )
     goal = "5 2\n"
     actual = zebra.Bootstrap().toObject(zbx).fetch()
     assert actual == goal, "whitespace is screwed up:\n%s" % actual
Пример #28
0
    def test_var(self):
        zbr = zebra.trim(
            """
            {
            My name is {?name?}.
            }
            """)

        goal = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            {<nl/>
            My name is <var>name</var>.<nl/>
            }<nl/>
            </zebra>
            """)
        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't cope well with {?vars?}:\n%s" % actual
Пример #29
0
 def setUp(self):
     self.data = zebra.trim(
         """
         <?xml version="1.0"?>
         <top>
           <person name="Michal">
           <skill>Python</skill>
           <skill>ASP</skill>
           </person>
         </top>
         """)
Пример #30
0
    def check_include(self):
        zbx = zebra.trim("""
            <zebra>
            <include file="test/includefile">
            </include>
            </zebra>
            """)

        goal = "This is the include file!\n"
        actual = zebra.Bootstrap().toObject(zbx).fetch()
        assert actual == goal, \
               "includes don't work:\n%s" % actual
Пример #31
0
    def check_include(self):
        zbx = zebra.trim(
            """
            <zebra>
            <include file="test/includefile">
            </include>
            </zebra>
            """
        )

        goal = "This is the include file!\n"
        actual = zebra.Bootstrap().toObject(zbx).fetch()
        assert actual == goal, "includes don't work:\n%s" % actual
Пример #32
0
    def check_for(self):

        model = {
            "a": "alaska",
            "stuff": [
                {"a": "apple", "b": "banana", "c": "cherry"},
                {"a": "aardvark", "b": "bull weevil", "c": "catepillar"},
                {"a": "alice", "b": "betty", "c": "carol"},
            ],
        }

        zbx = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            <rem>test scope</rem>
            <xpr>a</xpr><nl/>
            <for series="stuff">
            <xpr>a</xpr>, <xpr>b</xpr>, <xpr>c</xpr>
            <nl/>
            </for>
            <xpr>a</xpr><nl/>
            </zebra>
            """
        )

        goal = zebra.trim(
            """
            alaska
            apple, banana, cherry
            aardvark, bull weevil, catepillar
            alice, betty, carol
            alaska
            """
        )

        actual = zebra.Bootstrap().toObject(zbx).fetch(model)
        assert actual == goal, "for() loops don't work:\n---\n%s---" % actual
Пример #33
0
    def test_notBlocks(self):
        zbr = zebra.trim("""
            * if x==1:
                * include page_one;
            * ef x==2:
                * include page_two;
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <if condition="x==1">
            <include file="page_one"/>
            </if>
            <ef condition="x==2">
            <include file="page_two"/>
            </ef>
            </zebra>
            """)

        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "Doesn't handle ; blocks right:\n%s" % actual
Пример #34
0
    def test_forNone(self):
        zbr = zebra.trim("""
            * for people:
                {?name?} is a nice person.
            * none:
                No people here!
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <for series="people">
            <var>name</var> is a nice person.<nl/>
            </for>
            <none>
            No people here!<nl/>
            </none>
            </zebra>
            """)

        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "Doesn't do for..none right:\n%s" % actual
Пример #35
0
    def test_invalid(self):
        "check invalid tags"
        zbr = zebra.trim("""
            * thisIsAnInvalidTag
            """)
        try:
            zebra.Z2X().translate(zbr)
        except:
            gotError = 1
        else:
            gotError = 0

        assert gotError, \
               "Didn't get error on invalid tag."
Пример #36
0
    def test_forHeadBodyFoot(self):
        zbr = zebra.trim(
            """
            * for people:
                * head:
                    PEOPLE
                    -------
                * body:
                    {?name?} is a nice person.
                * foot:
                    -------
                    THE END
            """)
        
        goal = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            <for series="people">
            <head>
            PEOPLE<nl/>
            -------<nl/>
            </head>
            <body>
            <var>name</var> is a nice person.<nl/>
            </body>
            <foot>
            -------<nl/>
            THE END<nl/>
            </foot>
            </for>
            </zebra>
            """)

        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "Doesn't do for/head/body/foot right:\n%s" % actual
Пример #37
0
    def test_newline(self):
        zbr = zebra.trim("""
            hello, world!

            this test is good \\
            if there is no break here
            i want a newline after this<tag/>
            the end
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            hello, world!<nl/>
            <nl/>
            this test is good if there is no break here<nl/>
            i want a newline after this&lt;tag/&gt;<nl/>
            the end<nl/>
            </zebra>
            """)

        actual = zebra.zbr2xml.Z2X().translate(zbr)
        assert actual==goal, \
               "zbr2xml doesn't handle newlines correctly:\n%s" % actual
Пример #38
0
 def handle_for(self, model, attrs):
     loopvar = self.gensym("loopvar")
     self.loopvars.append(loopvar)
     data = {"loopvar": loopvar}
     data.update(attrs)
     res = zebra.trim('''
         _%(loopvar)s_max_ = len(scope["%(series)s"])
         for %(loopvar)s in range(_%(loopvar)s_max_):
             # handle scope inside the loop in case we have
             # recursive names (eg, children->children->children)
             scope_stack.append(copy.copy(scope))
             
             # can't do .update if it's a UserDict:
             mdl = scope["%(series)s"][%(loopvar)s]
             for item in mdl.keys():
                 scope[item]=mdl[item]
         ''' % data)
     res = res + zebra.indent(self.walk(model), 1)
     res = res + zebra.trim('''
         #   ## close for-%(series)s loop ##########
             globals().update(scope_stack.pop())
         ''' % attrs)
     self.lastLoopvar = self.loopvars.pop()
     return res
Пример #39
0
    def test_invalid(self):
        "check invalid tags"
        zbr = zebra.trim(
            """
            * thisIsAnInvalidTag
            """)
        try:
            zebra.Z2X().translate(zbr)
        except:
            gotError = 1
        else:
            gotError = 0

        assert gotError, \
               "Didn't get error on invalid tag."
Пример #40
0
    def setUp(self):
        file = open("test/junk.zb", "w")
        print >> file, "* for each:"
        print >> file, "    {:a:}"
        file.close()

        file = open("test/xmljunk.zbx", "w")
        print >> file, zebra.trim('''
            <?xml version="1.0"?>
            <zebra>
            <for series="each">
            <xpr>a</xpr><nl/>
            </for>
            </zebra>
            ''')
        file.close()
Пример #41
0
    def setUp(self):
        file = open("test/junk.zb","w")
        print >> file, "* for each:"
        print >> file, "    {:a:}"        
        file.close()

        file = open("test/xmljunk.zbx", "w")
        print >> file, zebra.trim(
            '''
            <?xml version="1.0"?>
            <zebra>
            <for series="each">
            <xpr>a</xpr><nl/>
            </for>
            </zebra>
            ''')
        file.close()
Пример #42
0
    def check_exec(self):
        # note: the <>'s mean something!
        zbx = zebra.trim("""
            <zebra>
            <exec>
            ex = '&lt;executive'
            ex = ex + ' decision&gt;'
            </exec>
            <xpr>ex</xpr>
            </zebra>
            """)

        goal = "<executive decision>"

        actual = zebra.Bootstrap().toObject(zbx).fetch()
        assert actual == goal, \
               "expressions don't work:\n%s" % actual
Пример #43
0
    def check_exec(self):
        # note: the <>'s mean something!
        zbx = zebra.trim(
            """
            <zebra>
            <exec>
            ex = '&lt;executive'
            ex = ex + ' decision&gt;'
            </exec>
            <xpr>ex</xpr>
            </zebra>
            """
        )

        goal = "<executive decision>"

        actual = zebra.Bootstrap().toObject(zbx).fetch()
        assert actual == goal, "expressions don't work:\n%s" % actual
Пример #44
0
    def check_basics(self):
        zbx = zebra.trim(
            """
            <zebra>
            <rem> ignore me! </rem>
            hello, world!
            </zebra>
            """
        )

        rpt = zebra.Bootstrap().toObject(zbx)

        for item in ("fetch", "show"):
            assert hasattr(rpt, item), "Report objects don't have .%s()!" % item

        actual = rpt.fetch()
        assert actual == "hello, world!", "basic 'hello, world' doesn't work:\n%s" % actual

        assert actual == rpt.fetch(), "calling fetch() a second time yields different results. :/"
Пример #45
0
    def check_conditionals(self):
        model = {"names": [{"name": "a"}, {"name": "b"}, {"name": "c"}]}

        zbx = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <for series="names">
            <if condition="name=='a'">Argentina</if>
            <ef condition="name=='b'">Bolivia</ef>
            <el>Chile</el>
            <glue>, </glue>
            </for>
            </zebra>
            """)
        goal = "Argentina, Bolivia, Chile"

        actual = zebra.Bootstrap().toObject(zbx).fetch(model)
        assert actual== goal, \
               "if/el/ef don't work:\n---%s---" % actual
Пример #46
0
    def check_basics(self):
        zbx = zebra.trim("""
            <zebra>
            <rem> ignore me! </rem>
            hello, world!
            </zebra>
            """)

        rpt = zebra.Bootstrap().toObject(zbx)

        for item in ("fetch", "show"):
            assert hasattr(rpt, item), \
               "Report objects don't have .%s()!" % item

        actual = rpt.fetch()
        assert actual == "hello, world!", \
               "basic 'hello, world' doesn't work:\n%s" % actual

        assert actual == rpt.fetch(), \
               "calling fetch() a second time yields different results. :/"
Пример #47
0
    def check_conditionals(self):
        model = {"names": [{"name": "a"}, {"name": "b"}, {"name": "c"}]}

        zbx = zebra.trim(
            """
            <?xml version="1.0"?>
            <zebra>
            <for series="names">
            <if condition="name=='a'">Argentina</if>
            <ef condition="name=='b'">Bolivia</ef>
            <el>Chile</el>
            <glue>, </glue>
            </for>
            </zebra>
            """
        )
        goal = "Argentina, Bolivia, Chile"

        actual = zebra.Bootstrap().toObject(zbx).fetch(model)
        assert actual == goal, "if/el/ef don't work:\n---%s---" % actual
Пример #48
0
 def check_nested_for(self):
     model = {"all": [{"subs": [{"value": "a"}]}, {"subs": [{"value": "b"}]}]}
     zbx = zebra.trim(
         """
         <?xml version="1.0"?>
         <zebra>
         <for series="all">
         <head>[</head>
         <for series="subs">
         <head>{</head>
         <var>value</var>
         <foot>}</foot>
         </for>
         <foot>]</foot>
         </for>
         </zebra>
         """
     )
     goal = "[{a}{b}]"
     actual = zebra.Bootstrap().toObject(zbx).fetch(model)
     self.assertEquals(actual, goal)
Пример #49
0
    def check_headFootSimple(self):

        # check the simple case, not the grouped version.

        model = {
            "list": [
                {
                    "toy": "ball"
                },
                {
                    "toy": "yoyo"
                },
            ]
        }

        zbx = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <for series="list">
            <head>Some toys: [</head>
            <var>toy</var>
            <glue>, </glue>
            <foot>]</foot>
            </for>
            </zebra>
            """)

        goal = "Some toys: [ball, yoyo]"

        ##         print '--------'
        ##         print zebra.Bootstrap().compile(zbx)
        ##         print '--------'

        actual = zebra.Bootstrap().toObject(zbx).fetch(model)
        assert actual == goal, \
               "head/tails don't work:\n%s" % actual