Skip to content

Commit

Permalink
Merge 0bd06b5 into f99a6f3
Browse files Browse the repository at this point in the history
  • Loading branch information
snopoke committed May 29, 2019
2 parents f99a6f3 + 0bd06b5 commit f0e80ca
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions commcare_export/excel_query.py
Expand Up @@ -317,17 +317,17 @@ def parse_workbook(workbook):
2. Each other sheet represents one data table to emit
"""
try:
mappings_sheet = workbook.get_sheet_by_name('Mappings')
mappings_sheet = workbook['Mappings']
except KeyError:
mappings_sheet = None
mappings = compile_mappings(mappings_sheet) if mappings_sheet else None

emit_sheets = [sheet_name for sheet_name in workbook.get_sheet_names() if sheet_name != 'Mappings']
emit_sheets = [sheet_name for sheet_name in workbook.sheetnames if sheet_name != 'Mappings']

parsed_sheets = []
for sheet in emit_sheets:
try:
sheet_parts = parse_sheet(workbook.get_sheet_by_name(sheet), mappings)
sheet_parts = parse_sheet(workbook[sheet], mappings)
except Exception as e:
logger.warning('Ignoring sheet "{}": {}'.format(sheet, str(e)))
continue
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Expand Up @@ -15,6 +15,13 @@
logging.getLogger().addHandler(logging.StreamHandler())


def pytest_configure(config):
config.addinivalue_line("markers", "dbtest: mark test that requires database access")
config.addinivalue_line("markers", "postgres: mark PostgreSQL test")
config.addinivalue_line("markers", "mysql: mark MySQL test")
config.addinivalue_line("markers", "mssql: mark MSSQL test")


def _db_params(request, db_name):
db_url = request.param['url']
sudo_engine = sqlalchemy.create_engine(db_url % request.param.get('admin_db', ''), poolclass=sqlalchemy.pool.NullPool)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_excel_query.py
Expand Up @@ -73,7 +73,7 @@ def flatten(dd):

for filename, mappings in test_cases:
abs_path = os.path.join(os.path.dirname(__file__), filename)
compiled = compile_mappings(openpyxl.load_workbook(abs_path).get_sheet_by_name('Mappings'))
compiled = compile_mappings(openpyxl.load_workbook(abs_path)['Mappings'])
# Print will be suppressed by pytest unless it fails
if not (flatten(compiled) == mappings):
print('In %s:' % filename)
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_parse_sheet(self):
for filename, minilinq in test_cases:
print('Compiling sheet %s' % filename) # This output will be captured by pytest and printed in case of failure; helpful to isolate which test case
abs_path = os.path.join(os.path.dirname(__file__), filename)
compiled = parse_sheet(openpyxl.load_workbook(abs_path).get_active_sheet())
compiled = parse_sheet(openpyxl.load_workbook(abs_path).active)
# Print will be suppressed by pytest unless it fails
if not (compiled == minilinq):
print('In %s:' % filename)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_writers.py
Expand Up @@ -95,8 +95,8 @@ def test_Excel2007TableWriter_write_mutli(self):
def _check_Excel2007TableWriter_output(self, filename):
output_wb = openpyxl.load_workbook(filename)

assert list(output_wb.get_sheet_names()) == ['foo']
foo_sheet = output_wb.get_sheet_by_name('foo')
assert output_wb.sheetnames == ['foo']
foo_sheet = output_wb['foo']
assert [ [cell.value for cell in row] for row in foo_sheet['A1:C3']] == [
['a', 'bjørn', 'c'],
['1', '2', '3'], # Note how pyxl does some best-effort parsing to *whatever* type
Expand Down

0 comments on commit f0e80ca

Please sign in to comment.