Skip to content

Commit 362824e

Browse files
committed
black chapter 2
1 parent 02be3d9 commit 362824e

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

chapter_02_repository.asciidoc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,12 @@ import model #<1>
314314
metadata = MetaData()
315315
316316
order_lines = Table( #<2>
317-
'order_lines', metadata,
318-
Column('id', Integer, primary_key=True, autoincrement=True),
319-
Column('sku', String(255)),
320-
Column('qty', Integer, nullable=False),
321-
Column('orderid', String(255)),
317+
"order_lines",
318+
metadata,
319+
Column("id", Integer, primary_key=True, autoincrement=True),
320+
Column("sku", String(255)),
321+
Column("qty", Integer, nullable=False),
322+
Column("orderid", String(255)),
322323
)
323324
324325
...
@@ -364,7 +365,7 @@ tests for it, as in the following example:
364365
----
365366
def test_orderline_mapper_can_load_lines(session): #<1>
366367
session.execute(
367-
'INSERT INTO order_lines (orderid, sku, qty) VALUES '
368+
"INSERT INTO order_lines (orderid, sku, qty) VALUES "
368369
'("order1", "RED-CHAIR", 12),'
369370
'("order1", "RED-TABLE", 13),'
370371
'("order2", "BLUE-LIPSTICK", 14)'
@@ -525,7 +526,6 @@ Here's what an abstract base class (ABC) for our repository would look like:
525526
[source,python]
526527
----
527528
class AbstractRepository(abc.ABC):
528-
529529
@abc.abstractmethod #<1>
530530
def add(self, batch: model.Batch):
531531
raise NotImplementedError #<2>
@@ -659,10 +659,10 @@ def test_repository_can_save_a_batch(session):
659659
repo.add(batch) #<1>
660660
session.commit() #<2>
661661
662-
rows = list(session.execute(
663-
'SELECT reference, sku, _purchased_quantity, eta FROM "batches"' #<3>
664-
))
665-
assert rows == [("batch1", "RUSTY-SOAPDISH", 100, None)]
662+
rows = session.execute( #<3>
663+
'SELECT reference, sku, _purchased_quantity, eta FROM "batches"'
664+
)
665+
assert list(rows) == [("batch1", "RUSTY-SOAPDISH", 100, None)]
666666
----
667667
====
668668

@@ -688,15 +688,16 @@ complex:
688688
----
689689
def insert_order_line(session):
690690
session.execute( #<1>
691-
'INSERT INTO order_lines (orderid, sku, qty)'
691+
"INSERT INTO order_lines (orderid, sku, qty)"
692692
' VALUES ("order1", "GENERIC-SOFA", 12)'
693693
)
694694
[[orderline_id]] = session.execute(
695-
'SELECT id FROM order_lines WHERE orderid=:orderid AND sku=:sku',
696-
dict(orderid="order1", sku="GENERIC-SOFA")
695+
"SELECT id FROM order_lines WHERE orderid=:orderid AND sku=:sku",
696+
dict(orderid="order1", sku="GENERIC-SOFA"),
697697
)
698698
return orderline_id
699699
700+
700701
def insert_batch(session, batch_id): #<2>
701702
...
702703
@@ -752,7 +753,6 @@ You end up with something like this:
752753
[source,python]
753754
----
754755
class SqlAlchemyRepository(AbstractRepository):
755-
756756
def __init__(self, session):
757757
self.session = session
758758

0 commit comments

Comments
 (0)