Пример #1
0
 def test_to_xml_defaults(self):
     root = TemplateNode()
     node = TemplateDateNode()
     root.append(node)
     node.append(TemplateWordNode("Mon Sep 30 07:06:05 2013"))
     xml = root.xml_tree(self._client_context)
     self.assertIsNotNone(xml)
     xml_str = ET.tostring(xml, "utf-8").decode("utf-8")
     self.assertEqual('<template><date format="%c">Mon Sep 30 07:06:05 2013</date></template>', xml_str)
Пример #2
0
 def test_to_xml_defaults(self):
     root = TemplateNode()
     node = TemplateDateNode()
     root.append(node)
     node.append(TemplateWordNode("Mon Sep 30 07:06:05 2013"))
     xml = root.xml_tree(self.bot, self.clientid)
     self.assertIsNotNone(xml)
     xml_str = ET.tostring(xml, "utf-8").decode("utf-8")
     self.assertEqual('<template><date format="%c">Mon Sep 30 07:06:05 2013</date></template>', xml_str)
Пример #3
0
    def test_node_customformat_set_attrib_invalid(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateDateNode()
        self.assertIsNotNone(node)
        with self.assertRaises(ParserException):
            node.set_attrib("unknown", "%c")
Пример #4
0
    def test_node_customformat_set_attrib_invalid(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateDateNode()
        self.assertIsNotNone(node)
        with self.assertRaises(ParserException):
            node.set_attrib("unknown", "%c")
Пример #5
0
    def test_node_customformat_set_attrib(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateDateNode()
        self.assertIsNotNone(node)
        node.set_attrib("format", "%c")

        root.append(node)
        self.assertEqual(len(root.children), 1)
        self.assertRegex(root.resolve(self._client_context), TemplateDateNodeTests.DEFAULT_DATETIME_REGEX)
Пример #6
0
    def test_node_customformat_set_attrib(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateDateNode()
        self.assertIsNotNone(node)
        node.set_attrib("format", "%c")

        root.append(node)
        self.assertEqual(len(root.children), 1)
        self.assertRegex(root.resolve(self._client_context), TemplateDateNodeTests.DEFAULT_DATETIME_REGEX)
Пример #7
0
    def test_node_customformat_parameter(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateDateNode()
        self.assertIsNotNone(node)
        node.date_format = "%c"
        root.append(node)

        self.assertEqual(len(root.children), 1)
        self.assertEqual("%c", node.date_format.word)
        self.assertRegex(root.resolve(self._client_context), TemplateDateNodeTests.DEFAULT_DATETIME_REGEX)
Пример #8
0
    def test_node_customformat_parameter(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateDateNode()
        self.assertIsNotNone(node)
        node.format = "%c"
        root.append(node)

        self.assertEqual(len(root.children), 1)
        self.assertEquals("%c", node.format)
        self.assertRegex(root.resolve(self._client_context), TemplateDateNodeTests.DEFAULT_DATETIME_REGEX)
Пример #9
0
    def test_node_defaultformat_with_userinfo_None(self):

        userInfo = UserInfo(None, None)
        self._client_context.userInfo = userInfo

        root = TemplateNode()
        node = TemplateDateNode()
        root.append(node)

        dateTime = root.resolve(self._client_context)
        self.assertRegex(dateTime,
                         TemplateDateNodeTests.DEFAULT_DATETIME_REGEX)
Пример #10
0
    def test_node_with_locale(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateDateNode(locale="en_US")
        self.assertIsNotNone(node)

        root.append(node)
        self.assertEqual(len(root.children), 1)
        self.assertRegex(root.resolve(self._client_context), TemplateDateNodeTests.DEFAULT_DATETIME_REGEX)
Пример #11
0
    def test_node_customformat(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateDateNode()
        self.assertIsNotNone(node)

        root.append(node)
        self.assertEqual(len(root.children), 1)
        self.assertRegex(root.resolve(self.bot, self.clientid),
                         TemplateDateNodeTests.DEFAULT_DATETIME_REGEX)
Пример #12
0
    def test_node_defaultformat_with_userinfo_locale_US(self):

        userInfo = UserInfo(None, None)
        userInfo.set('__USER_LOCALE__', "en-US")
        userInfo.set('__USER_TIME__', "2019-01-01T00:00:00+0900")
        self._client_context.userInfo = userInfo

        root = TemplateNode()
        node = TemplateDateNode()
        root.append(node)

        dateTime = root.resolve(self._client_context)
        self.assertEqual(dateTime, "Mon Dec 31 10:00:00 2018")
Пример #13
0
    def test_node_defaultformat_with_userinfo_invalid_timeform(self):

        userInfo = UserInfo(None, None)
        userInfo.set('__USER_LOCALE__', "ja-jp")
        userInfo.set('__USER_TIME__', "2019-01-01T00:00:00+09:00")
        self._client_context.userInfo = userInfo

        root = TemplateNode()
        node = TemplateDateNode()
        root.append(node)

        dateTime = root.resolve(self._client_context)
        self.assertRegex(dateTime,
                         TemplateDateNodeTests.DEFAULT_DATETIME_REGEX)
Пример #14
0
    def test_node_defaultformat_with_userinfo_invalid_locale(self):

        userInfo = UserInfo(None, None)
        userInfo.set('__USER_LOCALE__', "x-x")
        userInfo.set('__USER_TIME__', "2019-01-01T00:00:00+0900")
        self._client_context.userInfo = userInfo

        root = TemplateNode()
        node = TemplateDateNode()
        root.append(node)

        dateTime = root.resolve(self._client_context)
        self.assertEqual(dateTime, "Tue Jan 1 00:00:00 2019")

        userInfo.set('__USER_LOCALE__', "JP")
        dateTime = root.resolve(self._client_context)
        self.assertEqual(dateTime, "Tue Jan 1 00:00:00 2019")
Пример #15
0
    def test_get_set(self):
        node = TemplateDateNode()
        self.assertIsNotNone(node.date_format)
        self.assertIsInstance(node.date_format, TemplateNode)
        self.assertEquals("%c", node.date_format.word)
        self.assertIsNone(node.locale)

        node.date_format = "%c"
        node.locale = "en_US"

        self.assertIsInstance(node.date_format, TemplateNode)
        self.assertEquals("%c", node.date_format.word)
        self.assertIsInstance(node.locale, TemplateNode)
        self.assertEquals("en_US", node.locale.word)

        node.date_format = TemplateWordNode("%B")
        node.locale = TemplateWordNode("de_DE")

        self.assertIsInstance(node.date_format, TemplateNode)
        self.assertEquals("%B", node.date_format.word)
        self.assertIsInstance(node.locale, TemplateNode)
        self.assertEquals("de_DE", node.locale.word)
Пример #16
0
 def __init__(self, date_format=None):
     TemplateDateNode.__init__(self)
Пример #17
0
 def __init__(self, date_format=None):
     TemplateDateNode.__init__(self, locale="en_US")
Пример #18
0
 def test_to_xml_with_format_and_locale(self):
     node = TemplateDateNode(date_format="%c", locale="en_US")
     xml = node.to_xml(self._client_context)
     self.assertIsNotNone(xml)
     self.assertEquals('<date format="%c" locale="en_US"></date>', xml)
Пример #19
0
 def test_set_attrib_unknown(self):
     node = TemplateDateNode()
     self.assertIsNotNone(node)
     with self.assertRaises(ParserException):
         node.set_attrib("unknown", TemplateWordNode("en_US"))
Пример #20
0
 def test_set_attrib_locate_as_node(self):
     node = TemplateDateNode()
     self.assertIsNotNone(node)
     node.set_attrib("locale", TemplateWordNode("en_US"))
     self.assertEquals("en_US", node.locale.word)
Пример #21
0
 def __init__(self, date_format=None):
     TemplateDateNode.__init__(self)