john-kurkowski / tldextract

Accurately separates a URL’s subdomain, domain, and public suffix, using the Public Suffix List (PSL).
BSD 3-Clause "New" or "Revised" License
1.81k stars 211 forks source link

Tests on Windows + GitHub Actions #314

Closed elliotwutingfeng closed 7 months ago

elliotwutingfeng commented 7 months ago

Tests on Windows via GitHub Actions were not working. While trying to fix them, I've uncovered some strange behaviors. Currently all tests pass on macOS, Windows, and Linux for python 3.8-3.12 + pypy3.8.

1. Incomplete path conversion on Windows

import os
from pathlib import Path, PureWindowsPath

os.path.join('/home/anonymous', 'apple')
'/home/anonymous\\apple'

str(Path('/home/anonymous','apple'))
# you can simulate windows style Path() on UNIX systems via str(PureWindowsPath('/home/anonymous','apple'))
'\\home\\anonymous\\apple'

Unlike str(pathlib.Path), os.path.join does not convert existing forward-slashes, causing incomplete conversion of the monkeypatched UNIX-style paths to Windows-style.

  monkeypatch.setenv("HOME", "/home/john")
  monkeypatch.setenv("XDG_CACHE_HOME", "/my/alt/cache")
  monkeypatch.delenv("TLDEXTRACT_CACHE", raising=False)

2. Python 3.11 and 3.12 on Windows

For some unknown reason, in Python 3.11 & 3.12 on Windows (but not UNIX), the following receives a WindowsPath instead of a string. So I modified evil_unlink to perform relative path checks for both string and Path (since os.unlink supports both datatypes).

def evil_unlink(filename: str) -> None:

3. Erroneous stdout on pypy3.9 and pypy3.10 (all OSes)

See https://github.com/elliotwutingfeng/tldextract/actions/runs/6810665611/job/18519409296#step:5:60

E       AssertionError: assert '/Users/runne...s bbc co.uk\n' == ' example com...s bbc co.uk\n'
E         + /Users/runner/work/tldextract/tldextract/.tox/pypy39/lib/pypy3.9/site-packages/certifi/cacert.pem None
E            example com
E            bbc co.uk
E           forums bbc co.uk

I believe this has to do with the requests library, but I am unable to suppress the output (some kind of tuple?). This is probably the most important issue since pypy only supports the latest 1 or 2 versions of pypy.


4. Consider switching to GitHub Actions from Travis

If you are spending money on Travis, you may want to consider switching to GitHub Actions as it is free for public projects like this.


john-kurkowski commented 7 months ago

Okay there's a green checkmark on eb99020. 👍