Skip to content

Commit

Permalink
removed unused imports, linting updates, added another test
Browse files Browse the repository at this point in the history
  • Loading branch information
aschroed committed Oct 28, 2022
1 parent eea16bc commit 0b1737e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
14 changes: 13 additions & 1 deletion tests/conftest.py
Expand Up @@ -33,6 +33,18 @@ def prompt_for_lab_award(self, lab=None, award=None):
return


class MockedGauth(object):
def __init__(self):
pass

def open_by_key(self, gsid):
wkbk = MockedGoogleWorkBook()
sheet2 = MockedGoogleWorkSheet()
sheet2.set_title('Sheet2')
wkbk.add_sheets([MockedGoogleWorkSheet(), sheet2])
return wkbk


class MockedGoogleWorkSheet(object):
''' very basic mocked object to represent a gsheet sheet'''
def __init__(self, title='Sheet1', data={}):
Expand All @@ -57,7 +69,7 @@ def __init__(self, gsid='1111', sheets=[]):
self.sheets = sheets

def add_sheets(self, sheets=[]):
self.sheets.extend(sheets)
self.sheets = sheets


def worksheets(self):
Expand Down
15 changes: 11 additions & 4 deletions tests/test_import_data.py
Expand Up @@ -5,7 +5,7 @@
import pytest
import inspect
import wranglertools.import_data as imp
from tests.conftest import MockedGoogleWorkSheet, MockedGoogleWorkBook
from tests.conftest import MockedGoogleWorkSheet, MockedGoogleWorkBook, MockedGauth

# test data is in conftest.py

Expand Down Expand Up @@ -126,7 +126,6 @@ def test_reader_wrong_sheetname(capsys):
assert out == msg



@pytest.fixture
def gs_test_data():
return {'row1': ['a', 'b', 'c'], 'row2': ['d', 'e', 'f']}
Expand Down Expand Up @@ -175,12 +174,20 @@ def test_reader_gsheet_bad_name(mock_gsheet, capsys):
def test_row_generator_gsheet(mock_gsheet, gs_test_data):
res = imp.row_generator(mock_gsheet, 'gsheet')
# import pdb; pdb.set_trace()
assert(inspect.isgenerator(res))
assert inspect.isgenerator(res)
lres = list(res)
assert len(lres) == 2
assert lres[0] == gs_test_data['row1']


def test_open_gsheets():
test_names = ['Sheet1', 'Sheet2']
ret_wkbk, ret_names = imp.open_gsheets('gsid1234', MockedGauth())
assert type(ret_wkbk) is MockedGoogleWorkBook
for rn in ret_names:
assert rn in test_names


def test_cell_value(workbooks):
readxls = imp.reader(workbooks.get('test_cell_values.xlsx'))
list_readxls = list(readxls)
Expand Down Expand Up @@ -977,7 +984,7 @@ def test_cabin_cross_check_remote_w_award_not_for_lab_options(mocker, connection
mocker.patch('wranglertools.import_data._verify_and_return_item', side_effect=[
{'awards': ['/awards/test_award/', '/awards/1U54DK107977-01/']}, {'@id': '/awards/non-ren-lab-award/'}
])
with pytest.raises (SystemExit):
with pytest.raises(SystemExit):
connection_mock.labs = ['test_lab', '/labs/bing-ren-lab']
imp.cabin_cross_check(connection_mock, False, False, True, '/labs/bing-ren-lab/', '/awards/non-ren-lab-award/')

Expand Down
2 changes: 0 additions & 2 deletions wranglertools/import_data.py
Expand Up @@ -15,8 +15,6 @@
import warnings # to suppress openpyxl warnings
from base64 import b64encode
from collections import Counter, OrderedDict
# from contextlib import closing
from urllib import request as urllib2

import gspread
# https://github.com/ahupp/python-magic
Expand Down

0 comments on commit 0b1737e

Please sign in to comment.