def test_files_override_default_wildcards(): """Default wildcardlist will not be used if explicit files are provided""" assert "0 0 0 0" in open("perm.grdecl").read() assert "0 0 0 0" in open("eclipse/include/props/perm.grdecl").read() main_eclcompress("perm.grdecl", None) assert "13*0" in open("perm.grdecl").read() assert "13*0" not in open("eclipse/include/props/perm.grdecl").read()
def test_utf8(tmp_path): """Test that we can parse and write a file with utf-8 chars""" os.chdir(tmp_path) nastyfile = "nastyfile.inc" Path(nastyfile).write_text("-- Gullfaks Sør\nPORO\n 1 1 1 1/\n", encoding="utf8") main_eclcompress(nastyfile, None) assert "4*1" in Path(nastyfile).read_text(encoding="utf8")
def test_utf8(tmpdir): """Test that we can parse and write a file with utf-8 chars""" tmpdir.chdir() nastyfile = "nastyfile.inc" Path(nastyfile).write_text("-- Gullfaks Sør\nPORO\n 1 1 1 1/\n") main_eclcompress(nastyfile, None) assert "4*1" in open(nastyfile).read()
def test_empty_file(tmp_path): """Check that compression of empty files is a noop""" os.chdir(tmp_path) emptyfilename = "emptyfile.grdecl" Path(emptyfilename).write_text("", encoding="utf8") assert os.stat(emptyfilename).st_size == 0 main_eclcompress(emptyfilename, None) assert os.stat(emptyfilename).st_size == 0
def test_empty_file(tmpdir): """Check that compression of empty files is a noop""" tmpdir.chdir() emptyfilename = "emptyfile.grdecl" with open(emptyfilename, "w"): pass assert os.stat(emptyfilename).st_size == 0 main_eclcompress(emptyfilename, None) assert os.stat(emptyfilename).st_size == 0
def test_default_pattern(): """Check how eclcompress behaves as a command line tool in a standardized directory structure""" main_eclcompress(None, None) assert ("File compressed with eclcompress" in open("eclipse/include/props/perm.grdecl").read()) assert ("File compressed with eclcompress" in open("eclipse/include/regions/fipnum.grdecl").read()) assert "13*0" in open("eclipse/include/props/perm.grdecl").read()
def test_iso8859(tmpdir): """Test that a text file with ISO-8859 encoding does not trigger bugs (and is written back as utf-8)""" tmpdir.chdir() nastyfile = "nastyfile.inc" Path(nastyfile).write_text("-- Gullfaks Sør\nPORO\n 1 1 1 1/\n", encoding="ISO-8859-1") main_eclcompress(nastyfile, None) assert "4*1" in open(nastyfile).read() # Outputted file is always UTF-8
def test_no_touch_non_eclipse(tmpdir): """Check that we do not change a file that does not contain any Eclipse data""" tmpdir.chdir() filename = "foo.txt" with open(filename, "w") as file_h: file_h.write("Some random text\nAnother line\nbut no Eclipse keywords") origsize = os.stat(filename).st_size main_eclcompress(filename, None) assert origsize == os.stat(filename).st_size
def test_compress_files_filelist(args): """Test the command line options for giving in both excplicit files and a list of file(pattern)s""" main_eclcompress(args[0], args[1]) assert "File compressed with eclcompress" in open("perm.grdecl").read() assert "File compressed with eclcompress" in open("poro.grdecl").read() assert "13*0" in open("perm.grdecl").read() assert "7*1" in open("poro.grdecl").read()
def test_iso8859(tmp_path): """Test that a text file with ISO-8859 encoding does not trigger bugs (and is written back as utf-8)""" os.chdir(tmp_path) nastyfile = "nastyfile.inc" Path(nastyfile).write_text( "-- Gullfaks Sør\nPORO\n 1 1 1 1/\n", encoding="ISO-8859-1" ) main_eclcompress(nastyfile, None) assert "4*1" in Path(nastyfile).read_text(encoding="utf8")
def test_no_touch_non_eclipse(tmp_path): """Check that we do not change a file that does not contain any Eclipse data""" os.chdir(tmp_path) filename = "foo.txt" Path(filename).write_text( "Some random text\nAnother line\nbut no Eclipse keywords", encoding="utf8" ) origsize = os.stat(filename).st_size main_eclcompress(filename, None) assert origsize == os.stat(filename).st_size