mock_alchemy.unittests¶
A module for asserting SQLAlchemy expressions for unittests.
- class mock_alchemy.unittests.AlchemyUnittestMixin(*args, **kwargs)[source]¶
Bases:
objectA unittest class for asserting SQLAlchemy expressions.
Unittest class mixin for asserting that different SQLAlchemy expressions are the same.
Uses SQLAlchemyExpressionMatcher to do the comparison.
For example:
>>> from sqlalchemy.sql.expression import column >>> import unittest >>> class FooTest(AlchemyUnittestMixin, unittest.TestCase): ... def test_true(self): ... c = column('column') ... self.assertEqual(c == 5, c == 5) ... def test_false(self): ... c = column('column') ... self.assertEqual(c == 5, c == 10) >>> FooTest('test_true').test_true() >>> FooTest('test_false').test_false() Traceback (most recent call last): ... AssertionError: BinaryExpression(sql='"column" = :column_1', params={'column_1': 5}) != BinaryExpression(sql='"column" = :column_1', params={'column_1': 10})
- assert_alchemy_expression_equal(left, right, msg=None)[source]¶
Assert an SQLAlchemy expression to be equal.
Assert that two given sqlalchemy expressions are equal as determined by SQLAlchemyExpressionMatcher
- Parameters
left (
Any) – The left expression to comapre for equality.right (
Any) – The right expression to comapre for equality.msg (
Optional[str]) – The error message to dispaly.
- Raises
failureException – An exception if the two SQLAlchemy statements are not equal. The
msgis the displayed error meassage if provided, otherwise, the left and right expressions are displayed.- Return type
None