def test_table_data(temp_dir, table_one_data): path = temp_dir + "test_file.rst" writer.SimpleRSTWriter(path, ("Cool Cities", table_one_data)).write_tables() table = tableread.SimpleRSTReader(path).first assert all( attr.asdict(table_row) == _convert_col_names(test_row) for table_row, test_row in zip(table, table_one_data))
def get_sample_reader_from_file(): tmp_file = tempfile.NamedTemporaryFile(suffix='.rst', delete=False) tmp_file.write(SAMPLE_TABLES.encode()) tmp_file.close() reader = tableread.SimpleRSTReader(tmp_file.name) os.remove(tmp_file.name) return reader
def test_empty_rst_source_file_gives_error(): tmp_file = tempfile.NamedTemporaryFile(suffix='.rst') with pytest.raises(AssertionError): tableread.SimpleRSTReader(tmp_file.name)
def test_empty_rst_source_string_gives_error(): with pytest.raises(AssertionError): tableread.SimpleRSTReader('')
def test_non_existent_file_errors_appropriately(): with pytest.raises(AssertionError): tableread.SimpleRSTReader('./not/a/valid/path/to/file.rst')
''' def get_sample_reader_from_file(): tmp_file = tempfile.NamedTemporaryFile(suffix='.rst', delete=False) tmp_file.write(SAMPLE_TABLES.encode()) tmp_file.close() reader = tableread.SimpleRSTReader(tmp_file.name) os.remove(tmp_file.name) return reader readers = [ get_sample_reader_from_file(), tableread.SimpleRSTReader(SAMPLE_TABLES) ] @attr.s class FirstTableRow(object): name = attr.ib() favorite_color = attr.ib() favorite_number = attr.ib() @pytest.fixture def first_table(): return [ FirstTableRow(*x) for x in [('Bob', 'Red', '3'), ('Sue', 'Blue',
def test_empty_rst_source_file_gives_error(): tmp_file = tempfile.NamedTemporaryFile(suffix=".rst") with pytest.raises(tableread.InvalidFileException): tableread.SimpleRSTReader(tmp_file.name)
def test_empty_rst_source_string_gives_error(): with pytest.raises(tableread.InvalidFileException): tableread.SimpleRSTReader("")
def test_non_existent_file_errors_appropriately(): with pytest.raises(FileNotFoundError): tableread.SimpleRSTReader("./not/a/valid/path/to/file.rst")