Skip to content

Commit 6b86a88

Browse files
committed
PLAT-245 -- Amend library according to code review.
1 parent 29c963b commit 6b86a88

File tree

11 files changed

+43
-121
lines changed

11 files changed

+43
-121
lines changed

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ SQLAlchemy Diff
33

44
.. pull-quote::
55

6-
Compare two database schemas using SQLAlchemy.
6+
Compare and generate a diff between two databases using SQLAlchemy's
7+
inspection API.
78

89
Documentation here: (link to read the docs)

docs/__init__.py

Whitespace-only changes.

docs/source/full_example.rst

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

docs/source/index.rst

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,34 @@ SQLAlchemy Diff
33

44
.. pull-quote::
55

6-
Compare two database schemas using SQLAlchemy.
6+
Compare and generate a diff between two databases using SQLAlchemy's
7+
inspection API
78

89

910
PyTest Example
1011
--------------
1112

12-
This is how you can use the library to verify that two schemas are
13-
the same:
13+
Comparing two schemas is easy. You can verify they are the same like
14+
this:
1415

15-
.. literalinclude:: ../testing/test_example.py
16+
.. literalinclude:: ../../test/endtoend/test_example.py
1617
:lines: 6,8,9,13-22
17-
:emphasize-lines: 11
1818

1919

20-
You can also make sure that two schemas are different:
20+
You can also verify that they are different:
2121

22-
.. literalinclude:: ../testing/test_example.py
22+
.. literalinclude:: ../../test/endtoend/test_example.py
2323
:lines: 25-33
24-
:emphasize-lines: 7
2524

2625

27-
If your test fails, you can dump the errors to a file by just adding
28-
the following line of code:
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.
2929

30-
.. code-block:: Python
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:
3133

32-
result.dump_errors()
33-
34-
35-
That will dump the errors dict to a JSON file that looks like this:
3634

3735
.. code-block:: JSON
3836
@@ -82,15 +80,6 @@ That will dump the errors dict to a JSON file that looks like this:
8280
}
8381
8482
85-
Using unittest
86-
--------------
87-
88-
If you prefer, you can use unittest:
89-
90-
.. literalinclude:: ../testing/test_unittest.py
91-
:lines: 2-47
92-
93-
9483
Features
9584
--------
9685

@@ -109,10 +98,3 @@ Installation
10998
.. code-block:: bash
11099
111100
$ pip install sqlalchemy-diff
112-
113-
114-
Full Example
115-
------------
116-
117-
:ref:`Here <full_example>` you can find a full example on how to test
118-
two databases which are different.

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@
1313

1414
setup(
1515
name='sqlalchemy-diff',
16-
version='0.0.1',
16+
version='0.0.2',
1717
description='Compare two database schemas using sqlalchemy.',
1818
long_description=readme,
1919
author='student.com',
20-
author_email='dark-side@student.com', # TODO - Add proper email here
20+
author_email='wearehiring@student.com',
2121
url='https://github.com/Overseas-Student-Living/sqlalchemy-diff',
2222
packages=find_packages(exclude=['docs', 'test', 'test.*']),
2323
install_requires=[
2424
"six==1.10.0",
2525
"mock==1.3.0",
26-
"mysql-connector-python==2.0.4",
2726
"sqlalchemy-utils==0.31.2",
2827
],
2928
extras_require={
3029
'dev': [
30+
"mysql-connector-python==2.0.4",
3131
"pytest==2.8.2",
3232
],
3333
'docs': [

sqlalchemydiff/util.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,3 @@ def prepare_schema_from_models(uri, sqlalchemy_base):
103103
"""Creates the database schema from the ``SQLAlchemy`` models. """
104104
engine = create_engine(uri)
105105
sqlalchemy_base.metadata.create_all(engine)
106-
107-
108-
def walk_dict(d, path):
109-
"""Walks a dict given a path of keys.
110-
111-
For example, if we have a dict like this::
112-
113-
d = {
114-
'a': {
115-
'B': {
116-
1: ['hello', 'world'],
117-
2: ['hello', 'again'],
118-
}
119-
}
120-
}
121-
122-
Then ``walk_dict(d, ['a', 'B', 1])`` would return
123-
``['hello', 'world']``.
124-
"""
125-
if not path:
126-
return d
127-
return walk_dict(d[path[0]], path[1:])
File renamed without changes.
File renamed without changes.
File renamed without changes.

docs/testing/test_example.py renamed to test/endtoend/test_example.py

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

66
from sqlalchemydiff.comparer import compare
7-
from sqlalchemydiff.util import prepare_schema_from_models, walk_dict
7+
from sqlalchemydiff.util import prepare_schema_from_models
88
from .models_left import Base as Base_left
99
from .models_right import Base as Base_right
1010

@@ -233,3 +233,25 @@ def compare_error_dicts(err1, err2):
233233
assert_items_equal(walk_dict(err1, path), walk_dict(err2, path))
234234

235235
assert sorted(json.dumps(err1)) == sorted(json.dumps(err2))
236+
237+
238+
def walk_dict(d, path):
239+
"""Walks a dict given a path of keys.
240+
241+
For example, if we have a dict like this::
242+
243+
d = {
244+
'a': {
245+
'B': {
246+
1: ['hello', 'world'],
247+
2: ['hello', 'again'],
248+
}
249+
}
250+
}
251+
252+
Then ``walk_dict(d, ['a', 'B', 1])`` would return
253+
``['hello', 'world']``.
254+
"""
255+
if not path:
256+
return d
257+
return walk_dict(d[path[0]], path[1:])

0 commit comments

Comments
 (0)