Beispiel #1
0
 def test_custom_globals_with_extra_globals(self):
     context = Context.from_string(
         self.source,
         globals=dict(hour=MyGlobal('-7')),
         extra_globals=dict(my=MyGlobal('someval')),
     )
     self.assertTrue(context('hour'), '-7')
     self.assertTrue(context('my'), 'someval')
Beispiel #2
0
    def test_default_globals_are_accessible(self):
        context = Context.from_string(self.source)

        hour_value = context('hour')
        self.assertTrue(hour_value.isdigit(), hour_value)

        os_value = context('os')
        self.assertTrue(os_value in ('linux', 'mac', 'win', 'unknown'),
                        os_value)
Beispiel #3
0
    def test_extra_globals(self):
        context = Context.from_string(self.source,
                                      extra_globals=dict(
                                          my=MyGlobal('someval'),
                                          os=MyGlobal('bestosever'),
                                      ))

        hour_value = context('hour')
        self.assertTrue(hour_value.isdigit(), hour_value)
        self.assertEqual(context('os'), 'bestosever')
        self.assertEqual(context('my'), 'someval')
Beispiel #4
0
    def setUp(self):
        self.context = Context.from_string("""
            <one 'eins'>

            <types {
                str: "string",
                num: "number",
                bool: "boolean",
                *other: "other"
            }>

            <typesIndexed[$type] {
                str: "string",
                num: "number",
                bool: "boolean",
                *other: "other"
            }>

            <type "{{ types[$type] }}">

            <withAttribs
                'Me have attributes!'
                color:'red'
            >

            <withBadAttribs
                error:'{{ $noSuchVar }}'
                indexError[$noSuchVar]:{k1: "v1", k2: "v2"}
            >

            <withoutContent dummy:"dummy">

            <accessObjKeyProp "{{ $obj.key }}">

            <luckyNum "Your lucky number is {{ $num }}">
        """)
Beispiel #5
0
 def test_custom_globals(self):
     context = Context.from_string(self.source, globals={})
     self.assertEqual(context('hour'), '{{ @hour }}')
Beispiel #6
0
 def test_error_hook_on_missing_entity(self):
     tr = Context.from_string('', error_hook=self.store_error)
     tr('noSuchEntity')
     self.assertTrue(isinstance(self.error, NameError))