1. Evgeniy Tatarkin
  2. sadisplay

Commits

Evgeniy Tatarkin  committed e2abb7c

#8 sqlalchemy 9.x support by improve properties detecting, sort methods and properties lists

  • Participants
  • Parent commits 9433b20
  • Branches default

Comments (0)

Files changed (3)

File sadisplay/__init__.py

View file
 # -*- coding: utf-8 -*-
 
-__version__ = '0.3.6dev'
+__version__ = '0.3.7dev'
 
 from sadisplay.describe import describe     # pyflakes:ignore
 from sadisplay.render import plantuml, dot  # pyflakes:ignore

File sadisplay/describe.py

View file
 from sqlalchemy import exc, orm
 from sqlalchemy.orm import class_mapper
 from sqlalchemy import Column, Integer, Table
-from sqlalchemy.orm.properties import PropertyLoader
+from sqlalchemy.orm.properties import ColumnProperty
 
 
 def describe(items, show_methods=True, show_properties=True):
                         result_item['methods'].append(name)
 
         if show_properties and entry.properties:
-            for loader in entry.properties:
-                if isinstance(loader, PropertyLoader) \
-                        and loader.mapper.class_.__name__ in entries:
-                    result_item['props'].append(loader.key)
+            for item in entry.properties:
+                if not isinstance(item, ColumnProperty):
+                    result_item['props'].append(item.key)
+
+        # ordering
+        for key in ('methods', 'props'):
+            result_item[key].sort()
 
         objects.append(result_item)
 

File tests/test_describe.py

View file
 # -*- coding: utf-8 -*-
+from nose.tools import assert_equal
 import sadisplay
 import model
 
         assert len(objects) == 1
         assert relations == []
         assert inherits == []
-        assert objects[0] == {
+        assert_equal(
+            objects[0],
+            {
                 'name': model.User.__name__,
                 'cols': [('Integer', 'id'), ('Unicode', 'name'), ],
-                'props': [],
+                'props': ['address', 'books', ],
                 'methods': ['login', ],
             }
+        )
 
     def test_single_table(self):
 
         assert len(objects) == 1
         assert relations == []
         assert inherits == []
-        assert objects[0] == {
+        assert_equal(
+            objects[0],
+            {
                 'name': model.notes.name,
                 'cols': [('Integer', 'id'),
                     ('Unicode', 'name'),
                 'props': [],
                 'methods': [],
             }
+        )
 
     def test_inherits(self):
 
         assert len(relations) == 0
         assert len(objects) == 2
         assert len(inherits) == 1
-        assert objects[1] == {
+        assert_equal(
+            objects[1],
+            {
                 'name': model.Admin.__name__,
                 'cols': [('Integer', 'id'),
                     ('Unicode', 'name'),
                     ('Unicode', 'phone'), ],
-                'props': [],
+                'props': ['address', 'books', ],
                 'methods': ['permissions', ],
             }
+        )
 
-        assert inherits[0] == {
+        assert_equal(
+            inherits[0],
+            {
                 'child': model.Admin.__name__,
                 'parent': model.User.__name__,
             }
+        )
 
     def test_relation(self):
 
                 .describe([model.User, model.Address])
 
         assert len(objects) == 2
-        assert objects[1] == {
+        assert_equal(
+            objects[1],
+            {
                 'name': model.Address.__name__,
                 'cols': [('Integer', 'id'), ('Integer', 'user_id'), ],
                 'props': ['user'],
                 'methods': [],
             }
+        )
 
         assert len(inherits) == 0
-        assert relations[0] == {
+        assert_equal(
+            relations[0],
+            {
                 'from': model.Address.__name__,
                 'to': model.User.__name__,
                 'by': 'user_id',
             }
+        )
 
     def test_table(self):
 
                 .describe([model.Book])
 
         assert len(objects) == 1
-        assert objects[0] == {
+        assert_equal(
+            objects[0],
+            {
                 'name': model.Book.__name__,
                 'cols': [('Integer', 'id'),
                         ('Unicode', 'title'),
                         ('Integer', 'user_id'), ],
-                'props': [],
+                'props': ['user'],
                 'methods': [],
             }
+        )
 
         objects, relations, inherits = sadisplay \
                 .describe([model.Book, model.books])
 
         assert len(objects) == 1
-        assert objects[0] == {
+        assert_equal(
+            objects[0],
+            {
                 'name': model.Book.__name__,
                 'cols': [('Integer', 'id'),
                         ('Unicode', 'title'),
                         ('Integer', 'user_id'), ],
-                'props': [],
+                'props': ['user'],
                 'methods': [],
             }
+        )