Esempio n. 1
0
    def _test__cmp__(self, __cmp__, expected, op):
        CASES = (
            (ctds.Parameter(b'1234'), ctds.Parameter(b'123')),
            (ctds.Parameter(b'123'), ctds.Parameter(b'123')),
            (ctds.Parameter(b'123'), ctds.Parameter(b'123', output=True)),
            (ctds.Parameter(b'123'), ctds.Parameter(b'1234')),
            (ctds.Parameter(b'123'), b'123'),
            (ctds.Parameter(b'123'), ctds.Parameter(123)),
            (ctds.Parameter(b'123'), unicode_('123')),
            (ctds.Parameter(b'123'), ctds.SqlBinary(None)),
            (ctds.Parameter(b'123'), 123),
            (ctds.Parameter(b'123'), None),
        )

        for ix, args in enumerate(CASES):
            operation = '[{0}]: {1} {2} {3}'.format(ix, repr(args[0]), op,
                                                    repr(args[1]))
            if expected[ix] == TypeError:
                try:
                    result = __cmp__(*args)
                except TypeError as ex:
                    regex = (
                        r"'{0}' not supported between instances of '[^']+' and '[^']+'"
                        .format(op) if not PY3 or PY36 else
                        r'unorderable types: \S+ {0} \S+'.format(op))
                    self.assertTrue(re.match(regex, str(ex)), ex)
                else:
                    self.fail('{0} did not fail as expected'.format(
                        operation))  # pragma: nocover
            else:
                self.assertEqual(__cmp__(*args), expected[ix], operation)
Esempio n. 2
0
    def test_binary(self):
        python = b'1234567890'
        binary = ctds.SqlBinary(python)
        self.assertEqual(id(binary.value), id(python))
        self.assertEqual(binary.size, len(python))
        self.assertEqual(binary.tdstype, ctds.BINARY)

        # The BINARY mimimum size is 1
        python = b''
        binary = ctds.SqlBinary(python)
        self.assertEqual(id(binary.value), id(python))
        self.assertEqual(binary.size, 1)
        self.assertEqual(binary.tdstype, ctds.BINARY)

        binary = ctds.SqlBinary(None)
        self.assertEqual(binary.value, None)
        self.assertEqual(binary.size, 1)
        self.assertEqual(binary.tdstype, ctds.BINARY)
Esempio n. 3
0
 def test_wrapper(self):
     with self.connect() as connection:
         with connection.cursor() as cursor:
             for value in (b'1234', unicode_('1234'), None):
                 wrapper = ctds.SqlBinary(value)
                 self.assertEqual(id(value), id(wrapper.value))
                 self.assertEqual(wrapper.size,
                                  len(value) if value is not None else 1)
                 row = self.parameter_type(cursor, wrapper)
                 self.assertEqual(row.Type,
                                  'binary' if value is not None else None)
                 expected = wrapper.value.encode() if isinstance(
                     value, unicode_) else wrapper.value
                 self.assertEqual(row.Value, expected)