def test_reading_empty(): holes = from_infraformat() assert isinstance(holes, Holes) holes = from_infraformat([]) assert isinstance(holes, Holes) holes = from_infraformat("") assert isinstance(holes, Holes)
def test_reading_bad_stringio(): for path in get_datafiles("bad"): with StringIO() as text: with open(path, "r") as f: text.write(f.read()) text.seek(0) with pytest.raises(Exception): from_infraformat(text, robust=False)
def test_reading_dir(): here = os.path.dirname(os.path.abspath(__file__)) data_directory = os.path.join(here, "test_data") paths_read = [] try: path_read = from_infraformat(data_directory) except: # this just tests that one of the files is read correctly. pass path_read = from_infraformat(data_directory, extension=".tek2") path_read = from_infraformat(data_directory, extension="tek2")
def test_set_logger(): pif.set_logger_level(10) pif.log_to_file("test_log.log") for path in get_datafiles("good"): holes = from_infraformat(path) with open("test_log.log") as f: length = len(f.read()) assert length > 0
def test_reading_good_bytesio(robust): for path in get_datafiles("good"): with BytesIO() as text: with open(path, "rb") as f: text.write(f.read()) text.seek(0) holes = from_infraformat(text, robust=robust) assert isinstance(holes, Holes) assert isinstance(holes.holes, list)
def test_output(): for path in get_datafiles("good"): holes = from_infraformat(path) assert isinstance(holes, Holes) if len(holes.holes) > 0: here = os.path.dirname(os.path.abspath(__file__)) output_path = os.path.join(here, "test_data", str(uuid4()) + "_output_example.csv") assert not os.path.exists(output_path) holes.to_csv(output_path) assert os.path.exists(output_path) os.remove(output_path) assert not os.path.exists(output_path) output_path = os.path.join(here, "test_data", str(uuid4()) + "_output_example") with pytest.raises(FileExtensionMissingError): holes.to_csv(output_path) output_path = os.path.join(here, "test_data", str(uuid4()) + "_output_example.xlsx") assert not os.path.exists(output_path) holes.to_excel(output_path) assert os.path.exists(output_path) os.remove(output_path) assert not os.path.exists(output_path) output_path = os.path.join(here, "test_data", str(uuid4()) + "_output_example") with pytest.raises(FileExtensionMissingError): holes.to_excel(output_path) output_path = os.path.join(here, "test_data", str(uuid4()) + "_output_example.tek") assert not os.path.exists(output_path) holes.to_infraformat(output_path) assert os.path.exists(output_path) os.remove(output_path) assert not os.path.exists(output_path) with StringIO() as output_io: output_io.seek(0) holes.to_infraformat(output_io) output_io.seek(0) assert len(output_io.read())
def test_reading_bad_encoding(encoding): for path in get_datafiles(None, "utf-16"): with pytest.raises(UnicodeDecodeError): from_infraformat(path, robust=False, encoding=encoding)
def test_reading_bad(): for path in get_datafiles("bad"): with pytest.raises(Exception): from_infraformat(path, robust=False) with pytest.raises(Exception): from_infraformat("../ImaginaryFolder")
def test_reading_good_encoding(robust, encoding): for path in get_datafiles("good", "utf-16"): holes = from_infraformat(path, robust=robust, encoding=encoding) assert isinstance(holes, Holes) assert isinstance(holes.holes, list)
def test_reading_good(robust): for path in get_datafiles("good"): holes = from_infraformat(path, robust=robust) assert isinstance(holes, Holes) assert isinstance(holes.holes, list)
def get_object(): here = os.path.dirname(os.path.abspath(__file__)) filepath = os.path.join(here, "test_data", "infraformat_hole_types.tek") object = from_infraformat(filepath) return object