Skip to content

Commit

Permalink
Switch from nose to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
pudo committed Oct 30, 2021
1 parent 63c8357 commit b1638a4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ all: clean test dists

.PHONY: test
test:
nosetests -v
pytest

dists:
python setup.py sdist
Expand Down
3 changes: 3 additions & 0 deletions dataset/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def inspect(self):
"""Get a SQLAlchemy inspector."""
return inspect(self.executable)

def has_table(self, name):
return self.inspect.has_table(name, schema=self.schema)

@property
def metadata(self):
"""Return a SQLAlchemy schema cache object."""
Expand Down
8 changes: 5 additions & 3 deletions dataset/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ def update_many(self, rows, keys, chunk_size=1000, ensure=None, types=None):
chunk = []
columns = []
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)
for key in keys:
Expand All @@ -240,7 +242,7 @@ def update_many(self, rows, keys, chunk_size=1000, ensure=None, types=None):
if len(chunk) == chunk_size or index == len(rows) - 1:
cl = [self.table.c[k] == bindparam("_%s" % k) for k in keys]
stmt = self.table.update(
whereclause=and_(*cl),
whereclause=and_(True, *cl),
values={col: bindparam(col, required=False) for col in columns},
)
self.db.executable.execute(stmt, chunk)
Expand Down Expand Up @@ -431,7 +433,7 @@ def _args_to_clause(self, args, clauses=()):
clauses.append(self._generate_clause(column, op, op_value))
else:
clauses.append(self._generate_clause(column, "=", value))
return and_(*clauses)
return and_(True, *clauses)

def _args_to_order_by(self, order_by):
orderings = []
Expand Down
2 changes: 1 addition & 1 deletion dataset/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DatasetException(Exception):
def convert_row(row_type, row):
if row is None:
return None
return row_type(row.items())
return row_type(row._mapping.items())


def iter_result_proxy(rp, step=None):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
extras_require={
"dev": [
"pip",
"nose",
"pytest",
"wheel",
"flake8",
"coverage",
Expand All @@ -42,7 +42,7 @@
"cryptography",
]
},
tests_require=["nose"],
tests_require=["pytest"],
test_suite="test",
entry_points={},
)
8 changes: 4 additions & 4 deletions test/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_contains(self):

def test_create_table(self):
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 "id" in table.table.c, table.table.c

Expand All @@ -51,7 +51,7 @@ def test_create_table_no_ids(self):
def test_create_table_custom_id1(self):
pid = "string_id"
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 pid in table.table.c, table.table.c
table.insert({pid: "foobar"})
Expand All @@ -60,7 +60,7 @@ def test_create_table_custom_id1(self):
def test_create_table_custom_id2(self):
pid = "string_id"
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 pid in table.table.c, table.table.c

Expand All @@ -70,7 +70,7 @@ def test_create_table_custom_id2(self):
def test_create_table_custom_id3(self):
pid = "int_id"
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 pid in table.table.c, table.table.c

Expand Down

0 comments on commit b1638a4

Please sign in to comment.