Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import re
import os

from webassets.test import TempDirHelper, TempEnvironmentHelper


__all__ = ('TempDirHelper', 'TempEnvironmentHelper', 'noop',
'assert_raises_regex', 'check_warnings')
'assert_raises_regex', 'check_warnings', 'normalize_paths')


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


def normalize_paths(paths):
"""Normalize paths for cross-platform compatibility.

This function normalizes file paths to handle differences between
platforms (e.g., backslashes on Windows vs forward slashes on Unix).
"""
return set(os.path.normpath(p) for p in paths)


from pytest import raises
def assert_raises_regex(expected, regexp, callable, *a, **kw):
raises(expected, callable, *a, **kw).match(regexp)
Expand Down
22 changes: 15 additions & 7 deletions tests/test_bundle_various.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import copy
from io import StringIO
import os
from os import path
import uuid
from urllib.request import \
Expand All @@ -21,7 +22,7 @@
from webassets.version import Manifest, Version, VersionIndeterminableError

from .helpers import (
TempEnvironmentHelper, assert_raises_regex)
TempEnvironmentHelper, assert_raises_regex, normalize_paths)


class TestBundleConfig(TempEnvironmentHelper):
Expand Down Expand Up @@ -403,9 +404,11 @@ def test_globbing(self):
# Returns all files, even duplicate relative filenames in
# multiple load paths (foo in this case).
bundle = self.mkbundle('*', output='out')
assert set(get_all_bundle_files(bundle)) == set([
result = get_all_bundle_files(bundle)
expected = [
self.path('a/foo'), self.path('b/foo'), self.path('b/bar')
])
]
assert normalize_paths(result) == normalize_paths(expected)

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

# With a non-globbed reference
bundle = self.mkbundle('foo', output='out')
assert set(get_all_bundle_files(bundle)) == set([
result = get_all_bundle_files(bundle)
expected = [
self.path('a/foo'), self.path('b/foo')
])
]
assert normalize_paths(result) == normalize_paths(expected)

# With a globbed reference
bundle = self.mkbundle('???', output='out')
assert set(get_all_bundle_files(bundle)) == set([
result = get_all_bundle_files(bundle)
expected = [
self.path('a/foo'), self.path('b/foo'), self.path('dir/bar')
])
]
assert normalize_paths(result) == normalize_paths(expected)


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

@pytest.mark.skipif(os.name == 'nt', reason="Colons not allowed in Windows filenames")
def test_pyramid_asset_specs(self):
"""Make sure that pyramid asset specs (in the form of
package:path) do not pass the url check."""
Expand Down
5 changes: 4 additions & 1 deletion tests/test_loaders.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import os

import pytest

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

def test_load_extra_default(self):
"""[Regression] If no extra= is given, the value defaults to {}"""
Expand Down
3 changes: 2 additions & 1 deletion tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def test_builtin_manifest_accessors():
env = Environment('', '')
assert get_manifest('cache', env).__class__ == CacheManifest
assert get_manifest('file', env).__class__ == FileManifest
assert get_manifest('file:/tmp/foo', env).filename == '/tmp/foo'
manifest_filename = get_manifest('file:/tmp/foo', env).filename
assert os.path.normpath(manifest_filename).endswith(os.path.normpath('/tmp/foo'))


class TestTimestampVersion(TempEnvironmentHelper):
Expand Down