File: test_charset.py

package info (click to toggle)
pymssql 2.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 972 kB
  • sloc: python: 3,801; sh: 152; makefile: 151; ansic: 1
file content (33 lines) | stat: -rw-r--r-- 768 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding: utf-8 -*-
"""
Test charset usage in queries.
"""

import unittest

import pytest

from .helpers import pymssqlconn


@pytest.mark.mssql_server_required
class TestCharset(unittest.TestCase):

    def setUp(self):
        self.conn = pymssqlconn(charset='WINDOWS-1251')

    def test_charset(self):
        cursor = self.conn.cursor()

        try:
            cursor.execute(
                'select %s, %s',
                ('Здравствуй', 'Мир')  # Russian strings
            )
        except UnicodeDecodeError as e:
            self.fail("cursor.execute() raised %s unexpectedly: %s" % (e.__class__.__name__, e))

        a, b = cursor.fetchone()

        self.assertEqual(a, 'Здравствуй')
        self.assertEqual(b, 'Мир')