Skip to content

Instantly share code, notes, and snippets.

View zzzeek's full-sized avatar
💭
SQLAlchemy 2.0 is released!

Michael Bayer zzzeek

💭
SQLAlchemy 2.0 is released!
View GitHub Profile
>>> import mock
>>> sess = mock.Mock()
>>> sess.query().filter(x=2).first.return_value = 5
>>> sess.query().filter(x=2).first()
5
>>> sess.query().filter(x=3).first() # <-- should not return 5, I'd like the "x=2" to be significant
5
import mock
class GeneratorMock(mock.Mock):
def __init__(self, *arg, **kw):
kw['side_effect'] = self._side_effect
super(GeneratorMock, self).__init__(*arg, **kw)
self._lookup = {}
def _side_effect(self, *arg, **kw):
if self._mock_return_value is not mock.sentinel.DEFAULT:
======================================================================
ERROR: test.ext.declarative.test_mixin.DeclarativeMixinPropertyTest.test_relationship_primryjoin
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/classic/dev/sqlalchemy/test/ext/declarative/test_mixin.py", line 1253, in test_relationship_primryjoin
self._test_relationship(True)
File "/Users/classic/dev/sqlalchemy/test/ext/declarative/test_mixin.py", line 1240, in _test_relationship
t1, t2 = Target(), Target()
======================================================================
ERROR: test.ext.declarative.test_mixin.DeclarativeMixinTest.test_col_copy_vs_declared_attr_single_propagation
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/classic/dev/sqlalchemy/test/ext/declarative/test_mixin.py", line 814, in test_col_copy_vs_declared_attr_single_propagation
class B(A):
File "/Users/classic/dev/sqlalchemy/./lib/sqlalchemy/ext/declarative/api.py", line 53, in __init__
_as_declarative(cls, classname, cls.__dict__)
Error: Cannot destroy container 551fbb94ec0a: Driver devicemapper failed to remove init filesystem 551fbb94ec0a78f1dab71309d838a2cc10621e9a043d1dca644683dbd4c87601-init: Error running removeDevice
Error: Cannot destroy container 085474f390de: Driver devicemapper failed to remove init filesystem 085474f390de71feb29c08718c0b7eefda40bd1a865395dbbdf3cdb4e23fd674-init: Error running removeDevice
Error: Cannot destroy container 6ed38beed9bf: Driver devicemapper failed to remove root filesystem 6ed38beed9bfbfadaba5e26e9a71f036f23197b4bdbc701149cb1820d0ceb6a5: Error running removeDevice
Error: Cannot destroy container 0e620bd03c2c: Driver devicemapper failed to remove root filesystem 0e620bd03c2c9c8e5c8214cd36948f6f7c2f5e5dcaa46c2abca4b54ee4685662: Error running removeDevice
Error: Cannot destroy container 99fc810a8637: Driver devicemapper failed to remove init filesystem 99fc810a8637dfbaa1071a73af4adaec52f3dad950935b2ba15aa12674bd09fb-init: Error running removeDevice
Error: Cannot destroy container 2ceabf01a9ba: Dri
66.85.144.237 - - [23/Feb/2014:20:42:07 -0500] "GET / HTTP/1.0" 401 495 "-" "masscan/1.0 (https://github.com/robertdavidgraham/masscan)"
119.9.74.172 - - [25/Feb/2014:05:58:44 -0500] "GET / HTTP/1.0" 401 495 "-" "masscan/1.0 (https://github.com/robertdavidgraham/masscan)"
173.244.215.194 - - [25/Feb/2014:10:53:12 -0500] "GET / HTTP/1.0" 401 495 "-" "masscan/1.0 (https://github.com/robertdavidgraham/masscan)"
173.244.206.13 - - [26/Feb/2014:09:44:30 -0500] "GET / HTTP/1.0" 401 495 "-" "masscan/1.0 (https://github.com/robertdavidgraham/masscan)"
109.68.190.145 - - [26/Feb/2014:17:45:23 -0500] "GET / HTTP/1.0" 401 495 "-" "masscan/1.0 (https://github.com/robertdavidgraham/masscan)"
173.244.206.19 - - [27/Feb/2014:12:50:06 -0500] "GET / HTTP/1.0" 401 495 "-" "masscan/1.0 (https://github.com/robertdavidgraham/masscan)"
# run #1 - run with just --db sqlite, one test is generated/runs
classics-MacBook-Pro-2:sqlalchemy classic$ py.test test/dialect/test_suite.py --db sqlite -k HasTableTest
============================================================= test session starts ==============================================================
platform darwin -- Python 2.7.5 -- py-1.4.20 -- pytest-2.5.2 -- /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
plugins: cov
collected 121 items
test/dialect/test_suite.py <- lib/sqlalchemy/testing/suite/test_reflection.py:31: HasTableTest_sqlite_pysqlite.test_has_table PASSED
>>>> x = object
>>>> inspect.isbuiltin(x)
False
>>>> inspect.isclass(x)
True
>>>> inspect.isbuiltin(x.__init__)
False
>>>> inspect.ismethod(x.__init__)
True
>>>> inspect.getargspec(x.__init__)
Python 2.7
>>> class O(object):
... pass
...
>>> O.__init__ is object.__init__
True
Python 3.4
from sqlalchemy import create_engine, MetaData, Table, Column, Integer, Text,\
ForeignKey
from sqlalchemy.orm import mapper, relationship, Session
from sqlalchemy.orm.attributes import set_attribute, get_attribute, \
del_attribute
from sqlalchemy.orm.instrumentation import is_instrumented
from sqlalchemy.orm import instrumentation
from sqlalchemy.ext.instrumentation import InstrumentationManager