|
19 | 19 |
|
20 | 20 | pytestmark = [pytest.mark.single_cpu]
|
21 | 21 |
|
| 22 | +# XXX Some tests fail in the CI because an empty .pyiceberg file is found. |
| 23 | +# Checking here before importing the pyiceberg module, to provide better |
| 24 | +# error message |
| 25 | +import os |
| 26 | + |
| 27 | +def check_pyiceberg_yaml_file(): |
| 28 | + import strictyaml |
| 29 | + |
| 30 | + PYICEBERG_HOME = "PYICEBERG_HOME" |
| 31 | + search_dirs = [os.environ.get(PYICEBERG_HOME), os.path.expanduser("~"), os.getcwd()] |
| 32 | + for dir_ in search_dirs: |
| 33 | + path = None |
| 34 | + exists = False |
| 35 | + content = None |
| 36 | + if dir_: |
| 37 | + path = pathlib.Path(dir_) / ".pyiceberg.yaml" |
| 38 | + exists = path.exists() |
| 39 | + if exists: |
| 40 | + with open(path, encoding="utf-8") as f: |
| 41 | + yml_str = f.read() |
| 42 | + content = strictyaml.load(yml_str).data |
| 43 | + raise RuntimeError( |
| 44 | + ".pyiceberg.yaml file already exists\n" |
| 45 | + f"Path: {path}\nContent:\n{content}" |
| 46 | + ) |
| 47 | + |
| 48 | +try: |
| 49 | + import strictyaml |
| 50 | +except ImportError: |
| 51 | + pass |
| 52 | +else: |
| 53 | + check_pyiceberg_yaml_file() |
| 54 | +# XXX End checks |
| 55 | + |
| 56 | + |
22 | 57 | pyiceberg = pytest.importorskip("pyiceberg")
|
23 | 58 | pyiceberg_catalog = pytest.importorskip("pyiceberg.catalog")
|
24 | 59 | pq = pytest.importorskip("pyarrow.parquet")
|
@@ -47,7 +82,7 @@ def create_catalog(catalog_name_in_pyiceberg_config=None):
|
47 | 82 |
|
48 | 83 | if catalog_name_in_pyiceberg_config is not None:
|
49 | 84 | config_path = pathlib.Path.home() / ".pyiceberg.yaml"
|
50 |
| - with open(config_path, "w") as f: |
| 85 | + with open(config_path, "w", encoding="utf-8") as f: |
51 | 86 | f.write(f"""\
|
52 | 87 | catalog:
|
53 | 88 | {catalog_name_in_pyiceberg_config}:
|
|
0 commit comments