| 880 | | sm = arena.add_store('legacydb', 'mysql', |
|---|
| 881 | | {"host": "localhost", "db": "existing_db", |
|---|
| 882 | | "user": "root", "passwd": "xxxx", |
|---|
| 883 | | }) |
|---|
| 884 | | dbtables = sm.db._get_tables() |
|---|
| 885 | | t = sm.db[""] |
|---|
| 886 | | uc = s.autoclass(t, cls.__name__) |
|---|
| 887 | | self.assert_(not issubclass(uc, cls)) |
|---|
| 888 | | self.assertEqual(uc.__name__, cls.__name__) |
|---|
| 889 | | for pname in uc.properties: |
|---|
| 890 | | copy = getattr(uc, pname) |
|---|
| 891 | | orig = getattr(cls, pname) |
|---|
| 892 | | self.assertEqual(copy.key, orig.key) |
|---|
| 893 | | # self.assertEqual(copy.type, orig.type) |
|---|
| 894 | | self.assertEqual(copy.default, orig.default, |
|---|
| 895 | | "%s.%s default %s != copy %s" |
|---|
| 896 | | % (cls.__name__, pname, |
|---|
| 897 | | `orig.default`, `copy.default`)) |
|---|
| 898 | | |
|---|
| 899 | | for k, v in orig.hints.iteritems(): |
|---|
| 900 | | if isinstance(v, (int, long)): |
|---|
| 901 | | v2 = copy.hints.get(k) |
|---|
| 902 | | if v2 != 0 and v2 < v: |
|---|
| 903 | | self.fail("%s.%s hint[%s] %s not >= %s" % |
|---|
| 904 | | (cls.__name__, pname, k, v2, v)) |
|---|
| 905 | | else: |
|---|
| 906 | | self.assertEqual(copy.hints[k], v) |
|---|
| 907 | | |
|---|
| | 888 | >>> sm = arena.add_store('legacydb', 'mysql', |
|---|
| | 889 | {"host": "localhost", "db": "existing_db", |
|---|
| | 890 | "user": "root", "passwd": "xxxx", |
|---|
| | 891 | }) |
|---|
| | 892 | >>> t = sm.autotable("zoo") |
|---|
| | 893 | >>> Zoo = s.autoclass(t, "Zoo") |
|---|
| | 894 | >>> Zoo |
|---|
| | 895 | <class 'dejavu.storage.db.Zoo'> |
|---|
| | 896 | >>> Zoo.properties |
|---|
| | 897 | ['id', 'name', 'admission', 'founded', 'lastescape', 'opens'] |
|---|
| 912 | | valid Python code to generate the requested Unit class.</p> |
|---|
| | 902 | valid Python code to generate the requested Unit class:</p> |
|---|
| | 903 | |
|---|
| | 904 | <pre> |
|---|
| | 905 | >>> t = sm.autotable("exhibit") |
|---|
| | 906 | >>> print s.autosource(t, "Exhibit") |
|---|
| | 907 | class Exhibit(Unit): |
|---|
| | 908 | pettingallowed = UnitProperty(bool) |
|---|
| | 909 | animals = UnitProperty(str) |
|---|
| | 910 | name = UnitProperty(str) |
|---|
| | 911 | zooid = UnitProperty(int) |
|---|
| | 912 | acreage = UnitProperty(decimal.Decimal) |
|---|
| | 913 | creators = UnitProperty(str) |
|---|
| | 914 | # Remove the default 'ID' property. |
|---|
| | 915 | ID = None |
|---|
| | 916 | identifiers = ('name', 'zooid') |
|---|
| | 917 | sequencer = UnitSequencer() |
|---|
| | 918 | </pre> |
|---|