Skip to content

Commit 5015c71

Browse files
committed
PLAT-245 -- Amend library as per PR.
1 parent 6b86a88 commit 5015c71

File tree

6 files changed

+102
-315
lines changed

6 files changed

+102
-315
lines changed

docs/source/index.rst

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,71 +13,72 @@ PyTest Example
1313
Comparing two schemas is easy. You can verify they are the same like
1414
this:
1515

16-
.. literalinclude:: ../../test/endtoend/test_example.py
17-
:lines: 6,8,9,13-22
18-
19-
20-
You can also verify that they are different:
21-
22-
.. literalinclude:: ../../test/endtoend/test_example.py
23-
:lines: 25-33
24-
25-
26-
You will get back a ``result`` object: ``result.is_match`` will be
27-
``True`` when the two schemas are the same, and ``False`` when they are
28-
different.
29-
30-
When two schemas don't match, you can call ``result.dump_errors()`` to
31-
save all the differences between them to a JSON file that will look
32-
like this:
33-
34-
35-
.. code-block:: JSON
36-
37-
{
38-
'tables': {
39-
'left_only': ['addresses'],
40-
'right_only': ['roles']
41-
},
42-
'tables_data': {
43-
'employees': {
44-
'columns': {
45-
'left_only': [
46-
{
47-
'default': None,
48-
'name': 'favourite_meal',
49-
'nullable': False,
50-
'type': "ENUM('meat','vegan')"
51-
}
52-
],
53-
'right_only': [
54-
{
55-
'autoincrement': False,
56-
'default': None,
57-
'name': 'role_id',
58-
'nullable': False,
59-
'type': 'INTEGER(11)'
60-
},
61-
{
62-
'autoincrement': False,
63-
'default': None,
64-
'name': 'number_of_pets',
65-
'nullable': False,
66-
'type': 'INTEGER(11)'
16+
.. code-block:: Python
17+
18+
>>> result = compare(uri_left, uri_right)
19+
>>> result.is_match
20+
True
21+
22+
23+
When they are different, ``result.is_match`` will be ``False``.
24+
25+
When two schemas don't match, you can inspect the differences between
26+
them by looking at the ``errors`` dict on the ``result``:
27+
28+
.. code-block:: Python
29+
30+
>>> result = compare(uri_left, uri_right)
31+
>>> result.is_match
32+
False
33+
>>> result.errors
34+
{
35+
'tables': {
36+
'left_only': ['addresses'],
37+
'right_only': ['roles']
38+
},
39+
'tables_data': {
40+
'employees': {
41+
'columns': {
42+
'left_only': [
43+
{
44+
'default': None,
45+
'name': 'favourite_meal',
46+
'nullable': False,
47+
'type': "ENUM('meat','vegan')"
48+
}
49+
],
50+
'right_only': [
51+
{
52+
'autoincrement': False,
53+
'default': None,
54+
'name': 'role_id',
55+
'nullable': False,
56+
'type': 'INTEGER(11)'
57+
},
58+
{
59+
'autoincrement': False,
60+
'default': None,
61+
'name': 'number_of_pets',
62+
'nullable': False,
63+
'type': 'INTEGER(11)'
64+
},
65+
]
6766
},
68-
]
67+
'foreign_keys': { ... },
68+
'primary_keys': { ... },
69+
'indexes': { .. }
70+
},
71+
'phone_numbers': { ... }
6972
},
70-
'foreign_keys': { ... },
71-
'primary_keys': { ... },
72-
'indexes': { .. }
73-
},
74-
'phone_numbers': { ... }
75-
},
76-
'uris': {
77-
'left': "your left URI",
78-
'right': "your right URI",
79-
}
80-
}
73+
'uris': {
74+
'left': "your left URI",
75+
'right': "your right URI",
76+
}
77+
}
78+
79+
80+
If you wish to persist that dict to a JSON file, you can quickly do so
81+
by calling ``result.dump_errors()``.
8182

8283

8384
Features

setup.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
setup(
1515
name='sqlalchemy-diff',
16-
version='0.0.2',
16+
version='0.0.3',
1717
description='Compare two database schemas using sqlalchemy.',
1818
long_description=readme,
1919
author='student.com',
@@ -34,11 +34,6 @@
3434
"Sphinx==1.3.1",
3535
],
3636
},
37-
entry_points={
38-
'pytest11': [
39-
'sqlalchemy_diff=sqlalchemydiff.pyfixtures'
40-
]
41-
},
4237
zip_safe=True,
4338
license='Apache License, Version 2.0',
4439
classifiers=[

sqlalchemydiff/pyfixtures.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/endtoend/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding: utf-8 -*-
2+
import pytest
3+
4+
5+
@pytest.fixture(scope="module")
6+
def db_uri():
7+
return "mysql+mysqlconnector://root:@localhost/sqlalchemydiff"

test/endtoend/test_example.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,42 @@
44
import pytest
55

66
from sqlalchemydiff.comparer import compare
7-
from sqlalchemydiff.util import prepare_schema_from_models
7+
from sqlalchemydiff.util import (
8+
destroy_database,
9+
get_temporary_uri,
10+
new_db,
11+
prepare_schema_from_models,
12+
)
813
from .models_left import Base as Base_left
914
from .models_right import Base as Base_right
1015

1116
from test import assert_items_equal
1217

1318

19+
@pytest.fixture(scope="module")
20+
def uri_left(db_uri):
21+
return get_temporary_uri(db_uri)
22+
23+
24+
@pytest.fixture(scope="module")
25+
def uri_right(db_uri):
26+
return get_temporary_uri(db_uri)
27+
28+
29+
@pytest.yield_fixture
30+
def new_db_left(uri_left):
31+
new_db(uri_left)
32+
yield
33+
destroy_database(uri_left)
34+
35+
36+
@pytest.yield_fixture
37+
def new_db_right(uri_right):
38+
new_db(uri_right)
39+
yield
40+
destroy_database(uri_right)
41+
42+
1443
@pytest.mark.usefixtures("new_db_left")
1544
@pytest.mark.usefixtures("new_db_right")
1645
def test_same_schema_is_the_same(uri_left, uri_right):

0 commit comments

Comments
 (0)