def test_filenames(self): for (filename, stem, ext, expectation) in expectations(): fieldnames = None if '#headers' in filename: fieldnames = stem.split('#')[2] try: fieldnames = int(fieldnames) except ValueError: fieldnames = fieldnames.split('-') src = sources.Source(here(filename), fieldnames=fieldnames) result = list(src) self.assertEqual(result, expectation, msg="%s, by filename" % filename) # check that we can limit result size if expectation: src = sources.Source(here(filename), limit=1, fieldnames=fieldnames) self.assertEqual(list(src)[0], expectation[0], msg='%s, limiting to 1') if ext == 'xls': continue # now test against an open file object with sources._open(here(filename)) as infile: src = sources.Source(infile, fieldnames=fieldnames) self.assertEqual(list(src), expectation, msg="%s, by file obj" % filename) # now test against the text contents if not filename.endswith('.pickle'): with open(here(filename)) as infile: src = sources.Source(infile.read(), fieldnames=fieldnames) self.assertEqual(list(src), expectation, msg="%s, by contents" % filename)
def test_filenames(self): for (filename, stem, ext) in split_filenames(): print(filename) expectation_filename = '%s.result' % stem with open(expectation_filename) as infile: expectation = eval(infile.read()) src = sources.Source(filename) self.assertEqual(list(src), expectation, msg="%s, by filename" % filename) # check that we can limit result size src = sources.Source(filename, limit=1) self.assertEqual(list(src), expectation[:1], msg='%s, limiting to 1') # now test against an open file object with sources._open(filename) as infile: src = sources.Source(infile) self.assertEqual(list(src), expectation, msg="%s, by file obj" % filename) # now test against the text contents if not filename.endswith('.pickle'): with open(filename) as infile: src = sources.Source(infile.read()) self.assertEqual(list(src), expectation, msg="%s, by contents" % filename)