Beispiel #1
0
 def test_contents_encoding_1(self):
     """
     Testing the logic of choosing the encoding and the process of
     encoding contents.
     """
     from aiida.tools.dbexporters.tcod import cif_encode_contents
     self.assertEquals(cif_encode_contents('simple line')[1], None)
     self.assertEquals(cif_encode_contents(' ;\n ;')[1], None)
     self.assertEquals(cif_encode_contents(';\n'),
                       ('=3B\n', 'quoted-printable'))
     self.assertEquals(cif_encode_contents('line\n;line'),
                       ('line\n=3Bline', 'quoted-printable'))
     self.assertEquals(cif_encode_contents('tabbed\ttext'),
                       ('tabbed=09text', 'quoted-printable'))
     self.assertEquals(cif_encode_contents('angstrom Å'),
                       ('angstrom =C3=85', 'quoted-printable'))
     self.assertEquals(cif_encode_contents('.'),
                       ('=2E', 'quoted-printable'))
     self.assertEquals(cif_encode_contents('?'),
                       ('=3F', 'quoted-printable'))
     self.assertEquals(cif_encode_contents('.?'), ('.?', None))
     # This one is particularly tricky: a long line is folded by the QP
     # and the semicolon sign becomes the first character on a new line.
     self.assertEquals(
         cif_encode_contents("Å{};a".format("".join(
             "a" for i in range(0, 69)))),
         ('=C3=85aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
          'aaaaaaaaaaaaaaaaaaaaaaaaaaaaa=\n=3Ba', 'quoted-printable'))
     self.assertEquals(cif_encode_contents('angstrom ÅÅÅ'),
                       ('YW5nc3Ryb20gw4XDhcOF', 'base64'))
     self.assertEquals(
         cif_encode_contents("".join("a" for i in range(0, 2048)))[1], None)
     self.assertEquals(
         cif_encode_contents("".join("a" for i in range(0, 2049)))[1],
         'quoted-printable')
     self.assertEquals(cif_encode_contents('datatest')[1], None)
     self.assertEquals(cif_encode_contents('data_test')[1], 'base64')
Beispiel #2
0
    def test_contents_encoding_1(self):
        """
        Testing the logic of choosing the encoding and the process of
        encoding contents.
        """
        from aiida.tools.dbexporters.tcod import cif_encode_contents
        self.assertEquals(cif_encode_contents(b'simple line')[1], None)
        self.assertEquals(cif_encode_contents(b' ;\n ;')[1], None)
        self.assertEquals(cif_encode_contents(b';\n'),
                          (b'=3B\n', 'quoted-printable'))
        self.assertEquals(cif_encode_contents(b'line\n;line'),
                          (b'line\n=3Bline', 'quoted-printable'))
        self.assertEquals(cif_encode_contents(b'tabbed\ttext'),
                          (b'tabbed=09text', 'quoted-printable'))

        # Angstrom symbol 'Å' will be encoded as two bytes, thus encoding it
        # for CIF will produce two quoted-printable entities, '=C3' and '=85',
        # one for each byte.

        self.assertEquals(cif_encode_contents(u'angstrom Å'.encode('utf-8')),
                          (b'angstrom =C3=85', 'quoted-printable'))
        self.assertEquals(cif_encode_contents(b'.'),
                          (b'=2E', 'quoted-printable'))
        self.assertEquals(cif_encode_contents(b'?'),
                          (b'=3F', 'quoted-printable'))
        self.assertEquals(cif_encode_contents(b'.?'), (b'.?', None))
        # This one is particularly tricky: a long line is folded by the QP
        # and the semicolon sign becomes the first character on a new line.
        self.assertEquals(
            cif_encode_contents(u"Å{};a".format("".join(
                "a" for i in range(0, 69))).encode('utf-8')),
            (b'=C3=85aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
             b'aaaaaaaaaaaaaaaaaaaaaaaaaaaaa=\n=3Ba', 'quoted-printable'))
        self.assertEquals(cif_encode_contents(u'angstrom ÅÅÅ'.encode('utf-8')),
                          (b'YW5nc3Ryb20gw4XDhcOF', 'base64'))
        self.assertEquals(
            cif_encode_contents("".join(
                "a" for i in range(0, 2048)).encode('utf-8'))[1], None)
        self.assertEquals(
            cif_encode_contents("".join(
                "a" for i in range(0, 2049)).encode('utf-8'))[1],
            'quoted-printable')
        self.assertEquals(cif_encode_contents(b'datatest')[1], None)
        self.assertEquals(cif_encode_contents(b'data_test')[1], 'base64')