fix: format all code with black
and from now on should not deviate from that...
This commit is contained in:
parent
49f9a0228b
commit
a6bb538ce9
59 changed files with 2762 additions and 2131 deletions
|
@ -14,10 +14,10 @@ except ImportError:
|
|||
else:
|
||||
|
||||
class MockBatch(model.BatchMixin, model.Base):
|
||||
__tablename__ = 'testing_batch_mock'
|
||||
__tablename__ = "testing_batch_mock"
|
||||
|
||||
class MockBatchRow(model.BatchRowMixin, model.Base):
|
||||
__tablename__ = 'testing_batch_mock_row'
|
||||
__tablename__ = "testing_batch_mock_row"
|
||||
__batch_class__ = MockBatch
|
||||
|
||||
class MockBatchHandler(mod.BatchHandler):
|
||||
|
@ -30,12 +30,12 @@ else:
|
|||
|
||||
def test_model_class(self):
|
||||
handler = mod.BatchHandler(self.config)
|
||||
self.assertRaises(NotImplementedError, getattr, handler, 'model_class')
|
||||
self.assertRaises(NotImplementedError, getattr, handler, "model_class")
|
||||
|
||||
def test_batch_type(self):
|
||||
with patch.object(mod.BatchHandler, 'model_class', new=MockBatch):
|
||||
with patch.object(mod.BatchHandler, "model_class", new=MockBatch):
|
||||
handler = mod.BatchHandler(self.config)
|
||||
self.assertEqual(handler.batch_type, 'testing_batch_mock')
|
||||
self.assertEqual(handler.batch_type, "testing_batch_mock")
|
||||
|
||||
def test_make_batch(self):
|
||||
handler = self.make_handler()
|
||||
|
@ -50,25 +50,30 @@ else:
|
|||
self.assertEqual(second, first + 1)
|
||||
|
||||
third = handler.consume_batch_id(self.session, as_str=True)
|
||||
self.assertEqual(third, f'{first + 2:08d}')
|
||||
self.assertEqual(third, f"{first + 2:08d}")
|
||||
|
||||
def test_get_data_path(self):
|
||||
model = self.app.model
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
|
||||
with patch.object(mod.BatchHandler, 'model_class', new=MockBatch):
|
||||
with patch.object(mod.BatchHandler, "model_class", new=MockBatch):
|
||||
handler = self.make_handler()
|
||||
|
||||
# root storage (default)
|
||||
with patch.object(self.app, 'get_appdir', return_value=self.tempdir):
|
||||
with patch.object(self.app, "get_appdir", return_value=self.tempdir):
|
||||
path = handler.get_data_path()
|
||||
self.assertEqual(path, os.path.join(self.tempdir, 'data', 'batch', 'testing_batch_mock'))
|
||||
self.assertEqual(
|
||||
path,
|
||||
os.path.join(
|
||||
self.tempdir, "data", "batch", "testing_batch_mock"
|
||||
),
|
||||
)
|
||||
|
||||
# root storage (configured)
|
||||
self.config.setdefault('wutta.batch.storage_path', self.tempdir)
|
||||
self.config.setdefault("wutta.batch.storage_path", self.tempdir)
|
||||
path = handler.get_data_path()
|
||||
self.assertEqual(path, os.path.join(self.tempdir, 'testing_batch_mock'))
|
||||
self.assertEqual(path, os.path.join(self.tempdir, "testing_batch_mock"))
|
||||
|
||||
batch = handler.make_batch(self.session, created_by=user)
|
||||
self.session.add(batch)
|
||||
|
@ -78,11 +83,18 @@ else:
|
|||
path = handler.get_data_path(batch)
|
||||
uuid = batch.uuid.hex
|
||||
final = os.path.join(uuid[-2:], uuid[:-2])
|
||||
self.assertEqual(path, os.path.join(self.tempdir, 'testing_batch_mock', final))
|
||||
self.assertEqual(
|
||||
path, os.path.join(self.tempdir, "testing_batch_mock", final)
|
||||
)
|
||||
|
||||
# with filename
|
||||
path = handler.get_data_path(batch, 'input.csv')
|
||||
self.assertEqual(path, os.path.join(self.tempdir, 'testing_batch_mock', final, 'input.csv'))
|
||||
path = handler.get_data_path(batch, "input.csv")
|
||||
self.assertEqual(
|
||||
path,
|
||||
os.path.join(
|
||||
self.tempdir, "testing_batch_mock", final, "input.csv"
|
||||
),
|
||||
)
|
||||
|
||||
# makedirs
|
||||
path = handler.get_data_path(batch)
|
||||
|
@ -118,7 +130,7 @@ else:
|
|||
def test_remove_row(self):
|
||||
model = self.app.model
|
||||
handler = self.make_handler()
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
batch = handler.make_batch(self.session, created_by=user)
|
||||
self.session.add(batch)
|
||||
|
@ -134,7 +146,7 @@ else:
|
|||
model = self.app.model
|
||||
handler = self.make_handler()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
batch = handler.make_batch(self.session, created_by=user)
|
||||
self.session.add(batch)
|
||||
|
@ -152,7 +164,7 @@ else:
|
|||
|
||||
def test_do_execute(self):
|
||||
model = self.app.model
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
|
||||
handler = self.make_handler()
|
||||
|
@ -161,7 +173,7 @@ else:
|
|||
self.session.flush()
|
||||
|
||||
# error if execution not allowed
|
||||
with patch.object(handler, 'why_not_execute', return_value="bad batch"):
|
||||
with patch.object(handler, "why_not_execute", return_value="bad batch"):
|
||||
self.assertRaises(RuntimeError, handler.do_execute, batch, user)
|
||||
|
||||
# nb. coverage only; tests nothing
|
||||
|
@ -178,7 +190,7 @@ else:
|
|||
model = self.app.model
|
||||
handler = self.make_handler()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
|
||||
# simple delete
|
||||
|
@ -201,13 +213,13 @@ else:
|
|||
self.assertEqual(self.session.query(MockBatch).count(), 0)
|
||||
|
||||
# delete w/ files
|
||||
self.config.setdefault('wutta.batch.storage_path', self.tempdir)
|
||||
self.config.setdefault("wutta.batch.storage_path", self.tempdir)
|
||||
batch = handler.make_batch(self.session, created_by=user)
|
||||
self.session.add(batch)
|
||||
self.session.flush()
|
||||
path = handler.get_data_path(batch, 'data.txt', makedirs=True)
|
||||
with open(path, 'wt') as f:
|
||||
f.write('foo=bar')
|
||||
path = handler.get_data_path(batch, "data.txt", makedirs=True)
|
||||
with open(path, "wt") as f:
|
||||
f.write("foo=bar")
|
||||
self.assertEqual(self.session.query(MockBatch).count(), 1)
|
||||
path = handler.get_data_path(batch)
|
||||
self.assertTrue(os.path.exists(path))
|
||||
|
@ -216,13 +228,13 @@ else:
|
|||
self.assertFalse(os.path.exists(path))
|
||||
|
||||
# delete w/ files (dry-run)
|
||||
self.config.setdefault('wutta.batch.storage_path', self.tempdir)
|
||||
self.config.setdefault("wutta.batch.storage_path", self.tempdir)
|
||||
batch = handler.make_batch(self.session, created_by=user)
|
||||
self.session.add(batch)
|
||||
self.session.flush()
|
||||
path = handler.get_data_path(batch, 'data.txt', makedirs=True)
|
||||
with open(path, 'wt') as f:
|
||||
f.write('foo=bar')
|
||||
path = handler.get_data_path(batch, "data.txt", makedirs=True)
|
||||
with open(path, "wt") as f:
|
||||
f.write("foo=bar")
|
||||
self.assertEqual(self.session.query(MockBatch).count(), 1)
|
||||
path = handler.get_data_path(batch)
|
||||
self.assertTrue(os.path.exists(path))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue