Skip to content

Fix test failures on windows #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Feb 7, 2025
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
- run: python -m flake8
- run: python -m mypy fluent.syntax/fluent fluent.runtime/fluent
test:
runs-on: ubuntu-latest
# Workaround Python 3.7 no longer supported https://github.com/actions/setup-python/issues/962#issuecomment-2414454450
#runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10", 3.11, 3.12, pypy3.9, pypy3.10]
Expand Down
7 changes: 7 additions & 0 deletions fluent.runtime/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os


# Unify path separator, default path separator on Windows is \ not /
# Needed in test_falllback.py because it uses dict + string compare to make a virtual file structure
def normalize_path(path):
return "/".join(os.path.split(path))
19 changes: 11 additions & 8 deletions fluent.runtime/tests/test_fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import unittest
from unittest import mock

from . import normalize_path

from fluent.runtime import FluentLocalization, FluentResourceLoader

ISFILE = os.path.isfile
Expand All @@ -25,11 +27,12 @@ def test_bundles(self, codecs_open, isfile):
"en/one.ftl": "four = exists",
"en/two.ftl": "five = exists",
}
isfile.side_effect = lambda p: p in data or ISFILE(p)
codecs_open.side_effect = lambda p, _, __: io.StringIO(data[p])
isfile.side_effect = lambda p: normalize_path(p) in data or ISFILE(p)
codecs_open.side_effect = lambda p, _, __: io.StringIO(data[normalize_path(p)])
l10n = FluentLocalization(
["de", "fr", "en"], ["one.ftl", "two.ftl"], FluentResourceLoader("{locale}")
)
# Curious
bundles_gen = l10n._bundles()
bundle_de = next(bundles_gen)
self.assertEqual(bundle_de.locales[0], "de")
Expand Down Expand Up @@ -57,8 +60,8 @@ def test_all_exist(self, codecs_open, isfile):
"en/one.ftl": "one = exists",
"en/two.ftl": "two = exists",
}
isfile.side_effect = lambda p: p in data
codecs_open.side_effect = lambda p, _, __: io.StringIO(data[p])
isfile.side_effect = lambda p: normalize_path(p) in data
codecs_open.side_effect = lambda p, _, __: io.StringIO(data[normalize_path(p)])
loader = FluentResourceLoader("{locale}")
resources_list = list(loader.resources("en", ["one.ftl", "two.ftl"]))
self.assertEqual(len(resources_list), 1)
Expand All @@ -69,8 +72,8 @@ def test_one_exists(self, codecs_open, isfile):
data = {
"en/two.ftl": "two = exists",
}
isfile.side_effect = lambda p: p in data
codecs_open.side_effect = lambda p, _, __: io.StringIO(data[p])
isfile.side_effect = lambda p: normalize_path(p) in data
codecs_open.side_effect = lambda p, _, __: io.StringIO(data[normalize_path(p)])
loader = FluentResourceLoader("{locale}")
resources_list = list(loader.resources("en", ["one.ftl", "two.ftl"]))
self.assertEqual(len(resources_list), 1)
Expand All @@ -79,8 +82,8 @@ def test_one_exists(self, codecs_open, isfile):

def test_none_exist(self, codecs_open, isfile):
data = {}
isfile.side_effect = lambda p: p in data
codecs_open.side_effect = lambda p, _, __: io.StringIO(data[p])
isfile.side_effect = lambda p: normalize_path(p) in data
codecs_open.side_effect = lambda p, _, __: io.StringIO(data[normalize_path(p)])
loader = FluentResourceLoader("{locale}")
resources_list = list(loader.resources("en", ["one.ftl", "two.ftl"]))
self.assertEqual(len(resources_list), 0)
Loading