<commit_before>import os
import unittest
import tempfile

from robot. errors import DataError
from robot.utils import XmlWriter, ET, ETSource
from robot.utils.asserts import *

PATH = os.path.join(tempfile.gettempdir(), 'test_xmlwriter.xml')


class XmlWriterWithoutPreamble(XmlWriter):

    def _preamble(self):
        pass


class TestXmlWriter(unittest.TestCase):

    def setUp(self):
        self.writer = XmlWriterWithoutPreamble(PATH)

    def tearDown(self):
        self.writer.close()
        os.remove(PATH)

    def test_write_element_in_pieces(self):
        self.writer.start('name', {'attr': 'value'}, newline=False)
        self.writer.content('Some content here!!')
        self.writer.end('name')
        self._verify_node(None, 'name', 'Some content here!!', {'attr': 'value'})

    def test_calling_content_multiple_times(self):
        self.writer.start('element', newline=False)
        self.writer.content('Hello world!\n')
        self.writer.content('Hi again!')
        self.writer.content('\tMy name is John')
        self.writer.end('element')
        self._verify_node(None, 'element', 'Hello world!\nHi again!\tMy name is John')
        self._verify_content('<element>Hello world!\nHi again!\tMy name is John</element>\n')

    def test_write_element(self):
        self.writer.element('elem', 'Node\n content', {'a1': 'attr1', 'a2': 'attr2'})
        self._verify_node(None, 'elem', 'Node\n content', {'a1': 'attr1', 'a2': 'attr2'})
        self._verify_content('<elem a1="attr1" a2="attr2">Node\n content</elem>\n')

    def test_element_with_content_is_self_closing(self):
        self.writer.element('elem')
        self._verify_node(None, 'elem')
        self._verify_content('<elem/>\n')

    def test_element_with_attributes_but_without_content_is_self_closing(self):
        self.writer.element('elem', attrs={'a1': 'attr1', 'a2': 'attr2'})
        self._verify_node(None, 'elem', attrs={'a1': 'attr1', 'a2': 'attr2'})
        self._verify_content('<elem a1="attr1" a2="attr2"/>\n')

    def test_write_many_elements(self):
        self.writer.start('root', {'version': 'test'})
        self.writer.start('child1', {'my-attr': 'my value'})<commit_msg>Fix utests dependent on the dict order<commit_after>from collections import OrderedDict
import os
import unittest
import tempfile

from robot. errors import DataError
from robot.utils import ET, ETSource, XmlWriter
from robot.utils.asserts import assert_equal, assert_raises, assert_true

PATH = os.path.join(tempfile.gettempdir(), 'test_xmlwriter.xml')


class XmlWriterWithoutPreamble(XmlWriter):

    def _preamble(self):
        pass


class TestXmlWriter(unittest.TestCase):

    def setUp(self):
        self.writer = XmlWriterWithoutPreamble(PATH)

    def tearDown(self):
        self.writer.close()
        os.remove(PATH)

    def test_write_element_in_pieces(self):
        self.writer.start('name', {'attr': 'value'}, newline=False)
        self.writer.content('Some content here!!')
        self.writer.end('name')
        self._verify_node(None, 'name', 'Some content here!!', {'attr': 'value'})
        self._verify_content('<name attr="value">Some content here!!</name>\n')

    def test_calling_content_multiple_times(self):
        self.writer.start('element', newline=False)
        self.writer.content('Hello world!\n')
        self.writer.content('Hi again!')
        self.writer.content('\tMy name is John')
        self.writer.end('element')
        self._verify_node(None, 'element', 'Hello world!\nHi again!\tMy name is John')
        self._verify_content('<element>Hello world!\nHi again!\tMy name is John</element>\n')

    def test_write_element(self):
        self.writer.element('elem', 'Node\n content',
                            OrderedDict([('a', '1'), ('b', '2'), ('c', '3')]))
        self._verify_node(None, 'elem', 'Node\n content', {'a': '1', 'b': '2', 'c': '3'})
        self._verify_content('<elem a="1" b="2" c="3">Node\n content</elem>\n')

    def test_element_with_content_is_self_closing(self):
        self.writer.element('elem')
        self._verify_node(None, 'elem')
        self._verify_content('<elem/>\n')

    def test_element_with_attributes_but_without_content_is_self_closing(self):
        self.writer.element('elem', attrs={'attr': 'value'})
        self._verify_node(None, 'elem', attrs={'attr': 'value'})
        self._verify_content('<elem attr="value"/>\n')

    def test_write_many_elements(self):
        self.writer.start('root', {'version': 'test'})
        self.writer.start('child1', {'my-attr': 'my value'})
{'fraction_non_alphanumeric': 0.1600262697022767, 'fraction_numerical': 0.00766199649737303, 'mean_word_length': 3.6717791411042944, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '791942', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1448, 'n_words': 284}