mock-alchemy
A module for asserting SQLAlchemy expressions for unittests.
mock_alchemy.unittests.
AlchemyUnittestMixin
Bases: object
object
A 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
Assert an SQLAlchemy expression to be equal.
Assert that two given sqlalchemy expressions are equal as determined by SQLAlchemyExpressionMatcher
left (Any) – The left expression to comapre for equality.
Any
right (Any) – The right expression to comapre for equality.
msg (Optional[str]) – The error message to dispaly.
Optional
str
failureException – An exception if the two SQLAlchemy statements are not equal. The msg is the displayed error meassage if provided, otherwise, the left and right expressions are displayed.
msg
None