Switch from nose to pytest
This commit is contained in:
parent
63c8357d1b
commit
b1638a41d6
2
Makefile
2
Makefile
@ -3,7 +3,7 @@ all: clean test dists
|
|||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
nosetests -v
|
pytest
|
||||||
|
|
||||||
dists:
|
dists:
|
||||||
python setup.py sdist
|
python setup.py sdist
|
||||||
|
|||||||
@ -93,6 +93,9 @@ class Database(object):
|
|||||||
"""Get a SQLAlchemy inspector."""
|
"""Get a SQLAlchemy inspector."""
|
||||||
return inspect(self.executable)
|
return inspect(self.executable)
|
||||||
|
|
||||||
|
def has_table(self, name):
|
||||||
|
return self.inspect.has_table(name, schema=self.schema)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def metadata(self):
|
def metadata(self):
|
||||||
"""Return a SQLAlchemy schema cache object."""
|
"""Return a SQLAlchemy schema cache object."""
|
||||||
|
|||||||
@ -228,7 +228,9 @@ class Table(object):
|
|||||||
chunk = []
|
chunk = []
|
||||||
columns = []
|
columns = []
|
||||||
for index, row in enumerate(rows):
|
for index, row in enumerate(rows):
|
||||||
columns.extend(col for col in row.keys() if (col not in columns) and (col not in keys))
|
columns.extend(
|
||||||
|
col for col in row.keys() if (col not in columns) and (col not in keys)
|
||||||
|
)
|
||||||
|
|
||||||
# bindparam requires names to not conflict (cannot be "id" for id)
|
# bindparam requires names to not conflict (cannot be "id" for id)
|
||||||
for key in keys:
|
for key in keys:
|
||||||
@ -240,7 +242,7 @@ class Table(object):
|
|||||||
if len(chunk) == chunk_size or index == len(rows) - 1:
|
if len(chunk) == chunk_size or index == len(rows) - 1:
|
||||||
cl = [self.table.c[k] == bindparam("_%s" % k) for k in keys]
|
cl = [self.table.c[k] == bindparam("_%s" % k) for k in keys]
|
||||||
stmt = self.table.update(
|
stmt = self.table.update(
|
||||||
whereclause=and_(*cl),
|
whereclause=and_(True, *cl),
|
||||||
values={col: bindparam(col, required=False) for col in columns},
|
values={col: bindparam(col, required=False) for col in columns},
|
||||||
)
|
)
|
||||||
self.db.executable.execute(stmt, chunk)
|
self.db.executable.execute(stmt, chunk)
|
||||||
@ -431,7 +433,7 @@ class Table(object):
|
|||||||
clauses.append(self._generate_clause(column, op, op_value))
|
clauses.append(self._generate_clause(column, op, op_value))
|
||||||
else:
|
else:
|
||||||
clauses.append(self._generate_clause(column, "=", value))
|
clauses.append(self._generate_clause(column, "=", value))
|
||||||
return and_(*clauses)
|
return and_(True, *clauses)
|
||||||
|
|
||||||
def _args_to_order_by(self, order_by):
|
def _args_to_order_by(self, order_by):
|
||||||
orderings = []
|
orderings = []
|
||||||
|
|||||||
@ -14,7 +14,7 @@ class DatasetException(Exception):
|
|||||||
def convert_row(row_type, row):
|
def convert_row(row_type, row):
|
||||||
if row is None:
|
if row is None:
|
||||||
return None
|
return None
|
||||||
return row_type(row.items())
|
return row_type(row._mapping.items())
|
||||||
|
|
||||||
|
|
||||||
def iter_result_proxy(rp, step=None):
|
def iter_result_proxy(rp, step=None):
|
||||||
|
|||||||
4
setup.py
4
setup.py
@ -33,7 +33,7 @@ setup(
|
|||||||
extras_require={
|
extras_require={
|
||||||
"dev": [
|
"dev": [
|
||||||
"pip",
|
"pip",
|
||||||
"nose",
|
"pytest",
|
||||||
"wheel",
|
"wheel",
|
||||||
"flake8",
|
"flake8",
|
||||||
"coverage",
|
"coverage",
|
||||||
@ -42,7 +42,7 @@ setup(
|
|||||||
"cryptography",
|
"cryptography",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
tests_require=["nose"],
|
tests_require=["pytest"],
|
||||||
test_suite="test",
|
test_suite="test",
|
||||||
entry_points={},
|
entry_points={},
|
||||||
)
|
)
|
||||||
|
|||||||
@ -35,7 +35,7 @@ class DatabaseTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
def test_create_table(self):
|
def test_create_table(self):
|
||||||
table = self.db["foo"]
|
table = self.db["foo"]
|
||||||
assert table.table.exists()
|
assert self.db.has_table(table.table.name)
|
||||||
assert len(table.table.columns) == 1, table.table.columns
|
assert len(table.table.columns) == 1, table.table.columns
|
||||||
assert "id" in table.table.c, table.table.c
|
assert "id" in table.table.c, table.table.c
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ class DatabaseTestCase(unittest.TestCase):
|
|||||||
def test_create_table_custom_id1(self):
|
def test_create_table_custom_id1(self):
|
||||||
pid = "string_id"
|
pid = "string_id"
|
||||||
table = self.db.create_table("foo2", pid, self.db.types.string(255))
|
table = self.db.create_table("foo2", pid, self.db.types.string(255))
|
||||||
assert table.table.exists()
|
assert self.db.has_table(table.table.name)
|
||||||
assert len(table.table.columns) == 1, table.table.columns
|
assert len(table.table.columns) == 1, table.table.columns
|
||||||
assert pid in table.table.c, table.table.c
|
assert pid in table.table.c, table.table.c
|
||||||
table.insert({pid: "foobar"})
|
table.insert({pid: "foobar"})
|
||||||
@ -60,7 +60,7 @@ class DatabaseTestCase(unittest.TestCase):
|
|||||||
def test_create_table_custom_id2(self):
|
def test_create_table_custom_id2(self):
|
||||||
pid = "string_id"
|
pid = "string_id"
|
||||||
table = self.db.create_table("foo3", pid, self.db.types.string(50))
|
table = self.db.create_table("foo3", pid, self.db.types.string(50))
|
||||||
assert table.table.exists()
|
assert self.db.has_table(table.table.name)
|
||||||
assert len(table.table.columns) == 1, table.table.columns
|
assert len(table.table.columns) == 1, table.table.columns
|
||||||
assert pid in table.table.c, table.table.c
|
assert pid in table.table.c, table.table.c
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ class DatabaseTestCase(unittest.TestCase):
|
|||||||
def test_create_table_custom_id3(self):
|
def test_create_table_custom_id3(self):
|
||||||
pid = "int_id"
|
pid = "int_id"
|
||||||
table = self.db.create_table("foo4", primary_id=pid)
|
table = self.db.create_table("foo4", primary_id=pid)
|
||||||
assert table.table.exists()
|
assert self.db.has_table(table.table.name)
|
||||||
assert len(table.table.columns) == 1, table.table.columns
|
assert len(table.table.columns) == 1, table.table.columns
|
||||||
assert pid in table.table.c, table.table.c
|
assert pid in table.table.c, table.table.c
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user