| 166 | |
| 167 | |
| 168 | def test_timezone_absent(datadir, tmpdir): |
| 169 | # Example file relies on the timezone "US/Pacific". It should gracefully |
| 170 | # fail, not crash, if the timezone database is present but the timezone |
| 171 | # is not found (GH-40633). |
| 172 | source_tzdir = Path('/usr/share/zoneinfo') |
| 173 | if not source_tzdir.exists(): |
| 174 | pytest.skip(f"Test needs timezone database in {source_tzdir}") |
| 175 | tzdir = Path(tmpdir / 'zoneinfo') |
| 176 | try: |
| 177 | shutil.copytree(source_tzdir, tzdir, symlinks=True) |
| 178 | except OSError as e: |
| 179 | pytest.skip(f"Failed to copy timezone database: {e}") |
| 180 | # ORC 2.1.1 Creates an alias between some legacy Timezones |
| 181 | # https://github.com/apache/orc/pull/2422 |
| 182 | # Example US/Pacific -> America/Los_Angeles |
| 183 | # Remove both to simulate missing timezone and avoid alias resolution |
| 184 | (tzdir / 'US' / 'Pacific').unlink(missing_ok=True) |
| 185 | (tzdir / 'America' / 'Los_Angeles').unlink(missing_ok=True) |
| 186 | |
| 187 | path = datadir / 'TestOrcFile.testDate1900.orc' |
| 188 | code = f"""if 1: |
| 189 | import os |
| 190 | os.environ['TZDIR'] = {str(tzdir)!r} |
| 191 | |
| 192 | from pyarrow import orc |
| 193 | orc_file = orc.ORCFile({str(path)!r}) |
| 194 | try: |
| 195 | orc_file.read() |
| 196 | except Exception as e: |
| 197 | timezones = ["zoneinfo/US/Pacific", "zoneinfo/America/Los_Angeles"] |
| 198 | assert any(tz in str(e) for tz in timezones), e |
| 199 | else: |
| 200 | assert False, "Should have raised exception" |
| 201 | """ |
| 202 | subprocess.run([sys.executable, "-c", code], check=True) |
| 203 | |
| 204 | |
| 205 | def test_orcfile_empty(datadir): |