def test_value_ending_with_padding(self): bytestring = b'Value ending with spaces ' assert 'Value ending with spaces' == convert_single_string(bytestring) assert 'Value ending with spaces' == convert_text(bytestring) bytestring = b'Values \\with spaces ' assert ['Values', 'with spaces'] == convert_text(bytestring) bytestring = b'Value ending with zeros\0\0\0' assert 'Value ending with zeros' == convert_single_string(bytestring) assert 'Value ending with zeros' == convert_text(bytestring) bytestring = b'Values\0\0\\with zeros\0' assert ['Values', 'with zeros'] == convert_text(bytestring)
def test_single_value_with_backslash(self): bytestring = (b'Buc^J\xe9r\xf4me\\\x1b\x2d\x46' b'\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2\\' b'\x1b\x2d\x4C' b'\xbb\xee\xda\x63\x65\xdc\xd1\x79\x70\xd3') encodings = ('latin_1', 'iso_ir_144', 'iso_ir_126') assert u'Buc^Jérôme\\Διονυσιος\\Люкceмбypг' == convert_single_string( bytestring, encodings)
def test_single_value_with_backslash(self): """Test that backslash is handled as character""" bytestring = (b'Buc^J\xe9r\xf4me\\\x1b\x2d\x46' b'\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2\\' b'\x1b\x2d\x4C' b'\xbb\xee\xda\x63\x65\xdc\xd1\x79\x70\xd3') encodings = ('latin_1', 'iso_ir_144', 'iso_ir_126') assert u'Buc^Jérôme\\Διονυσιος\\Люкceмбypг' == convert_single_string( bytestring, encodings)
def test_single_value_with_delimiters(self): """Test that delimiters reset the encoding""" bytestring = (b'\x1b\x2d\x46' b'\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2' b'\r\nJ\xe9r\xf4me/' b'\x1b\x2d\x4C' b'\xbb\xee\xda\x63\x65\xdc\xd1\x79\x70\xd3' b'\tJ\xe9r\xf4me') encodings = ('latin_1', 'iso_ir_144', 'iso_ir_126') expected = 'Διονυσιος\r\nJérôme/Люкceмбypг\tJérôme' assert expected == convert_single_string(bytestring, encodings)
def test_single_value_with_delimiters(self): """Test that delimiters reset the encoding""" bytestring = (b'\x1b\x2d\x46' b'\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2' b'\r\nJ\xe9r\xf4me/' b'\x1b\x2d\x4C' b'\xbb\xee\xda\x63\x65\xdc\xd1\x79\x70\xd3' b'\tJ\xe9r\xf4me') encodings = ('latin_1', 'iso_ir_144', 'iso_ir_126') expected = u'Διονυσιος\r\nJérôme/Люкceмбypг\tJérôme' assert expected == convert_single_string(bytestring, encodings)
def test_single_value_with_unknown_encoding_raises(self, enforce_valid_values): bytestring = b'Buc^J\xe9r\xf4me' encodings = ['unknown'] with pytest.raises(LookupError, match="unknown encoding: unknown"): convert_single_string(bytestring, encodings)
def test_single_value_with_unknown_encoding(self): bytestring = b'Buc^J\xe9r\xf4me' encodings = ['unknown'] msg = "Unknown encoding 'unknown' - using default encoding instead" with pytest.warns(UserWarning, match=msg): assert convert_single_string(bytestring, encodings) == 'Buc^Jérôme'