Пример #1
0
 def test__closenode_update_dict(self):
     nm.newfile('fileref', 2)
     nm.newnode('message')
     nm.nodes[-1].add_sentence("frase_test", ismultiline=False, 
             lineno=5, lineno_sub=1, override="override",
             addition=["addition1", "addition2"])
     my_dict = {'sono daruan': PoCommentedString("sono daruan", 
                              ismultiline=False, orderid=(1,1,0),
                              wmlinfos=["#. [message]: speaker = Daruan"],
                              finfos=["#: path/to/file1:1"],
                              addedinfos=[]) }
     nm._closenode_update_dict(my_dict)
     self.assertEqual(len(my_dict), 2)
     i = 0
     for val in sorted(my_dict.values(), 
                       key=lambda x: x.orderid):
         i+=1
         if i == 2:
             self.assertEqual(val.sentence, 'frase_test')
             self.assertFalse(val.ismultiline)
             self.assertEqual(val.orderid, (2,5,1))
     nm.newnode('[message]')
     nm.nodes[-1].add_sentence("sono daruan", ismultiline=False,
             lineno=9, lineno_sub=1)
     nm.nodes[-1].wmlinfos = [ "speaker = Daruan" ]
     nm._closenode_update_dict(my_dict)
     self.assertEqual(len(my_dict), 2)
     
     posentence = my_dict['sono daruan']
     self.assertIn("#: path/to/file1:1", posentence.finfos)
     self.assertIn("#: fileref:9", posentence.finfos)
     self.assertEqual(len(posentence.wmlinfos), 1)
     self.assertEqual(posentence.orderid, (1,1,0))
Пример #2
0
 def check_closenode(self, autowml):
     wmlerr_debug()
     nm.newfile("path/to/file2", 2)
     my_dict = {'sono daruan': PoCommentedString("sono daruan", 
                              ismultiline=False, orderid=(1,1,0),
                              wmlinfos=["#. [message] speaker = Daruan"],
                              finfos=["#: path/to/file1:1"],
                              addedinfos=[]) }
     nm.newnode("[message]")
     nm.closenode("[/message]", my_dict, 1)
     self.assertEqual(len(nm.nodes), 1)
     
     node1 = WmlNode(fileref="path/to/file2", fileno=2, 
                     tagname="[message]", autowml=autowml)
     node1.wmlinfos = [ "speaker = Daruan2" ]
     # empty override
     node1.add_sentence("sono daruan", ismultiline=False, lineno=15, 
                        override="")
     # standard
     node1.add_sentence("sono daruan", ismultiline=False, lineno=18)
     # addition
     node1.add_sentence("sono darUan", ismultiline=False, lineno=21, 
                        lineno_sub=3, addition=["#. added1"])
     # new sentence: (override + addition)
     node1.add_sentence("dax", ismultiline=True, lineno=30, 
                        override=["override"], addition=["add1"])
     # sent2: empty override + addition)
     node1.add_sentence("dax", ismultiline=False, lineno=31,
                        override= "", addition=["add2"])
     
     # sent2: override only
     node1.add_sentence("dax", ismultiline=False, lineno=31,
                        override= "override2")
     
     nm.nodes.append(node1)
     nm.closenode('[/message]', my_dict, 10)
     strl = list(my_dict.values())
     strl0 = None
     strl1 = None
     if strl[0].sentence == "sono daruan":
         strl0 = strl[0]
         strl1 = strl[1]
     else:
         strl0 = strl[1]
         strl1 = strl[0]
     self.assertEqual(len(my_dict), 2)
     self.assertEqual(len(strl0.finfos), 4)
     self.assertEqual(len(strl0.addedinfos), 1)
     if autowml is True:
         self.assertEqual(len(strl0.wmlinfos), 2)
         self.assertEqual(strl0.wmlinfos[1], 
                          '#. [message]: speaker = Daruan2')
     else:
         self.assertEqual(len(strl0.wmlinfos), 1)
Пример #3
0
 def test_newnode(self):
     nm.newfile('fileref', 'fileno')
     nm.newnode('message')
     self.assertEqual(len(nm.nodes), 2)
     root = nm.nodes[0]
     nod = nm.nodes[1]
     self.assertEqual(root.fileref, "#: fileref:")
     self.assertEqual(root.fileno, "fileno")
     self.assertEqual(root.tagname, "")
     self.assertFalse(root.autowml)
     self.assertEqual(nod.tagname, "message")
     self.assertTrue(nod.autowml)
Пример #4
0
 def test_newnode(self):
     nm.newfile('fileref', 'fileno')
     nm.newnode('message')
     self.assertEqual(len(nm.nodes), 2)
     root = nm.nodes[0]
     nod = nm.nodes[1]
     self.assertEqual(root.fileref, "#: fileref:")
     self.assertEqual(root.fileno, "fileno")
     self.assertEqual(root.tagname, "")
     self.assertFalse(root.autowml)
     self.assertEqual(nod.tagname, "message")
     self.assertTrue(nod.autowml)
Пример #5
0
 def test_closenode_errors(self):
     wmlerr_debug()
     ansi_setEnabled(False)
     my_dict = { }
     nm.newfile("path/to/file2", 2)
     rx0 = re.compile(r'[^[]*\[\/tag].*?outside any scope', re.I)
     rx1 = re.compile(r'[^[]*\[\/tag][^[]*\[\/message]', re.I)
     with self.assertRaisesRegex(WmlError, rx0):
         nm.closenode("[/tag]", my_dict, 5)
     nm.newnode("[tag]")
     with self.assertRaisesRegex(WmlError, rx1):
         nm.closenode("[/message]", my_dict, 5)
     nm.closenode("[/tag]", my_dict, 5)
     with self.assertRaisesRegex(WmlError, rx0):
         nm.closenode("[/tag]", my_dict, 5)
     self.assertEqual(len(nm.nodes), 1)
Пример #6
0
 def test_closenode_errors(self):
     wmlerr_debug()
     ansi_setEnabled(False)
     my_dict = {}
     nm.newfile("path/to/file2", 2)
     rx0 = re.compile(r'[^[]*\[\/tag].*?outside any scope', re.I)
     rx1 = re.compile(r'[^[]*\[\/tag][^[]*\[\/message]', re.I)
     with self.assertRaisesRegex(WmlError, rx0):
         nm.closenode("[/tag]", my_dict, 5)
     nm.newnode("[tag]")
     with self.assertRaisesRegex(WmlError, rx1):
         nm.closenode("[/message]", my_dict, 5)
     nm.closenode("[/tag]", my_dict, 5)
     with self.assertRaisesRegex(WmlError, rx0):
         nm.closenode("[/tag]", my_dict, 5)
     self.assertEqual(len(nm.nodes), 1)
Пример #7
0
    def test__closenode_update_dict(self):
        nm.newfile('fileref', 2)
        nm.newnode('message')
        nm.nodes[-1].add_sentence("frase_test",
                                  ismultiline=False,
                                  lineno=5,
                                  lineno_sub=1,
                                  override="override",
                                  addition=["addition1", "addition2"])
        my_dict = {
            'sono daruan':
            PoCommentedString("sono daruan",
                              ismultiline=False,
                              orderid=(1, 1, 0),
                              wmlinfos=["#. [message]: speaker = Daruan"],
                              finfos=["#: path/to/file1:1"],
                              addedinfos=[])
        }
        nm._closenode_update_dict(my_dict)
        self.assertEqual(len(my_dict), 2)
        i = 0
        for val in sorted(my_dict.values(), key=lambda x: x.orderid):
            i += 1
            if i == 2:
                self.assertEqual(val.sentence, 'frase_test')
                self.assertFalse(val.ismultiline)
                self.assertEqual(val.orderid, (2, 5, 1))
        nm.newnode('[message]')
        nm.nodes[-1].add_sentence("sono daruan",
                                  ismultiline=False,
                                  lineno=9,
                                  lineno_sub=1)
        nm.nodes[-1].wmlinfos = ["speaker = Daruan"]
        nm._closenode_update_dict(my_dict)
        self.assertEqual(len(my_dict), 2)

        posentence = my_dict['sono daruan']
        self.assertIn("#: path/to/file1:1", posentence.finfos)
        self.assertIn("#: fileref:9", posentence.finfos)
        self.assertEqual(len(posentence.wmlinfos), 1)
        self.assertEqual(posentence.orderid, (1, 1, 0))
Пример #8
0
 def test_newfile(self):
     nm.newfile('fileref', 'fileno')
     self.assertEqual(nm.fileref, "fileref")
     self.assertEqual(nm.fileno, "fileno")
     self.assertIs(nm.nodes, None)
Пример #9
0
 def test_newfile(self):
     nm.newfile('fileref', 'fileno')
     self.assertEqual(nm.fileref, "fileref")
     self.assertEqual(nm.fileno, "fileno")
     self.assertIs(nm.nodes, None)
Пример #10
0
    def check_closenode(self, autowml):
        wmlerr_debug()
        nm.newfile("path/to/file2", 2)
        my_dict = {
            'sono daruan':
            PoCommentedString("sono daruan",
                              ismultiline=False,
                              orderid=(1, 1, 0),
                              wmlinfos=["#. [message] speaker = Daruan"],
                              finfos=["#: path/to/file1:1"],
                              addedinfos=[])
        }
        nm.newnode("[message]")
        nm.closenode("[/message]", my_dict, 1)
        self.assertEqual(len(nm.nodes), 1)

        node1 = WmlNode(fileref="path/to/file2",
                        fileno=2,
                        tagname="[message]",
                        autowml=autowml)
        node1.wmlinfos = ["speaker = Daruan2"]
        # empty override
        node1.add_sentence("sono daruan",
                           ismultiline=False,
                           lineno=15,
                           override="")
        # standard
        node1.add_sentence("sono daruan", ismultiline=False, lineno=18)
        # addition
        node1.add_sentence("sono darUan",
                           ismultiline=False,
                           lineno=21,
                           lineno_sub=3,
                           addition=["#. added1"])
        # new sentence: (override + addition)
        node1.add_sentence("dax",
                           ismultiline=True,
                           lineno=30,
                           override=["override"],
                           addition=["add1"])
        # sent2: empty override + addition)
        node1.add_sentence("dax",
                           ismultiline=False,
                           lineno=31,
                           override="",
                           addition=["add2"])

        # sent2: override only
        node1.add_sentence("dax",
                           ismultiline=False,
                           lineno=31,
                           override="override2")

        nm.nodes.append(node1)
        nm.closenode('[/message]', my_dict, 10)
        strl = list(my_dict.values())
        strl0 = None
        strl1 = None
        if strl[0].sentence == "sono daruan":
            strl0 = strl[0]
            strl1 = strl[1]
        else:
            strl0 = strl[1]
            strl1 = strl[0]
        self.assertEqual(len(my_dict), 2)
        self.assertEqual(len(strl0.finfos), 4)
        self.assertEqual(len(strl0.addedinfos), 1)
        if autowml is True:
            self.assertEqual(len(strl0.wmlinfos), 2)
            self.assertEqual(strl0.wmlinfos[1],
                             '#. [message]: speaker = Daruan2')
        else:
            self.assertEqual(len(strl0.wmlinfos), 1)