Skip to content

Commit 58b9b1b

Browse files
authored
Merge pull request #562 from denini08/fix-windows
Improve cross-platform compatibility in tests (Windows support)
2 parents 8a047c4 + 82f3815 commit 58b9b1b

4 files changed

Lines changed: 32 additions & 10 deletions

File tree

tests/helpers.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import re
2+
import os
23

34
from webassets.test import TempDirHelper, TempEnvironmentHelper
45

56

67
__all__ = ('TempDirHelper', 'TempEnvironmentHelper', 'noop',
7-
'assert_raises_regex', 'check_warnings')
8+
'assert_raises_regex', 'check_warnings', 'normalize_paths')
89

910

1011
# Define a noop filter; occasionally in tests we need to define
1112
# a filter to be able to test a certain piece of functionality,.
1213
noop = lambda _in, out: out.write(_in.read())
1314

1415

16+
def normalize_paths(paths):
17+
"""Normalize paths for cross-platform compatibility.
18+
19+
This function normalizes file paths to handle differences between
20+
platforms (e.g., backslashes on Windows vs forward slashes on Unix).
21+
"""
22+
return set(os.path.normpath(p) for p in paths)
23+
24+
1525
from pytest import raises
1626
def assert_raises_regex(expected, regexp, callable, *a, **kw):
1727
raises(expected, callable, *a, **kw).match(regexp)

tests/test_bundle_various.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import copy
77
from io import StringIO
8+
import os
89
from os import path
910
import uuid
1011
from urllib.request import \
@@ -21,7 +22,7 @@
2122
from webassets.version import Manifest, Version, VersionIndeterminableError
2223

2324
from .helpers import (
24-
TempEnvironmentHelper, assert_raises_regex)
25+
TempEnvironmentHelper, assert_raises_regex, normalize_paths)
2526

2627

2728
class TestBundleConfig(TempEnvironmentHelper):
@@ -403,9 +404,11 @@ def test_globbing(self):
403404
# Returns all files, even duplicate relative filenames in
404405
# multiple load paths (foo in this case).
405406
bundle = self.mkbundle('*', output='out')
406-
assert set(get_all_bundle_files(bundle)) == set([
407+
result = get_all_bundle_files(bundle)
408+
expected = [
407409
self.path('a/foo'), self.path('b/foo'), self.path('b/bar')
408-
])
410+
]
411+
assert normalize_paths(result) == normalize_paths(expected)
409412

410413
def test_url_mapping(self):
411414
"""Test mapping the load paths to urls works."""
@@ -446,15 +449,19 @@ def test_globbed_load_path(self):
446449

447450
# With a non-globbed reference
448451
bundle = self.mkbundle('foo', output='out')
449-
assert set(get_all_bundle_files(bundle)) == set([
452+
result = get_all_bundle_files(bundle)
453+
expected = [
450454
self.path('a/foo'), self.path('b/foo')
451-
])
455+
]
456+
assert normalize_paths(result) == normalize_paths(expected)
452457

453458
# With a globbed reference
454459
bundle = self.mkbundle('???', output='out')
455-
assert set(get_all_bundle_files(bundle)) == set([
460+
result = get_all_bundle_files(bundle)
461+
expected = [
456462
self.path('a/foo'), self.path('b/foo'), self.path('dir/bar')
457-
])
463+
]
464+
assert normalize_paths(result) == normalize_paths(expected)
458465

459466

460467
class TestGlobbing(TempEnvironmentHelper):
@@ -620,6 +627,7 @@ def test_autorebuild_updaters(self):
620627
bundle = self.mkbundle('http://foo', output='out')
621628
TimestampUpdater().needs_rebuild(bundle, bundle.env)
622629

630+
@pytest.mark.skipif(os.name == 'nt', reason="Colons not allowed in Windows filenames")
623631
def test_pyramid_asset_specs(self):
624632
"""Make sure that pyramid asset specs (in the form of
625633
package:path) do not pass the url check."""

tests/test_loaders.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
import os
23

34
import pytest
45

@@ -130,7 +131,9 @@ def test_load_environment_directory_base(self):
130131
directory: ../something
131132
""", filename='/var/www/project/config/yaml').load_environment()
132133
# The directory is considered relative to the YAML file location.
133-
assert environment.directory == '/var/www/project/something'
134+
expected_path = '/var/www/project/something'
135+
actual_path = environment.directory
136+
assert os.path.normpath(actual_path).endswith(os.path.normpath(expected_path))
134137

135138
def test_load_extra_default(self):
136139
"""[Regression] If no extra= is given, the value defaults to {}"""

tests/test_version.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def test_builtin_manifest_accessors():
2727
env = Environment('', '')
2828
assert get_manifest('cache', env).__class__ == CacheManifest
2929
assert get_manifest('file', env).__class__ == FileManifest
30-
assert get_manifest('file:/tmp/foo', env).filename == '/tmp/foo'
30+
manifest_filename = get_manifest('file:/tmp/foo', env).filename
31+
assert os.path.normpath(manifest_filename).endswith(os.path.normpath('/tmp/foo'))
3132

3233

3334
class TestTimestampVersion(TempEnvironmentHelper):

0 commit comments

Comments
 (0)