forked from miracle2k/webassets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_loaders.py
More file actions
101 lines (84 loc) · 3.03 KB
/
test_loaders.py
File metadata and controls
101 lines (84 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import sys
from nose.tools import assert_raises
import textwrap
from StringIO import StringIO
from webassets.loaders import PythonLoader, YAMLLoader, LoaderError
from nose import SkipTest
class TestYAML(object):
def setup(self):
try:
import yaml
except ImportError:
raise SkipTest()
def loader(self, text, filename=None):
io = StringIO(textwrap.dedent(text))
if filename:
io.name = filename
return YAMLLoader(io)
def test_load_bundles(self):
bundles = self.loader("""
standard:
filters: cssmin,gzip
output: output.css
contents:
- file1
- file2
empty-bundle:
single-content-as-string-bundle:
contents: only-this
""").load_bundles()
assert len(bundles) == 3
assert bundles['standard'].output == 'output.css'
assert len(bundles['standard'].filters) == 2
assert bundles['standard'].contents == ('file1', 'file2')
assert bundles['empty-bundle'].contents == ()
assert bundles['single-content-as-string-bundle'].contents == ('only-this',)
def test_empty_files(self):
"""YAML loader can deal with empty files.
"""
self.loader("""""").load_bundles()
# A LoaderError is what we expect here, rather than, say, a TypeError.
assert_raises(LoaderError, self.loader("""""").load_environment)
def test_load_environment_error(self):
"""Check that "url" and "directory" are required.
"""
assert_raises(LoaderError, self.loader("""
url: /foo
""").load_environment)
assert_raises(LoaderError, self.loader("""
directory: bar
""").load_environment)
def test_load_environment(self):
environment = self.loader("""
url: /foo
directory: something
updater: 'always'
bundles:
test:
output: foo
""").load_environment()
assert environment.url == '/foo'
assert environment.updater == 'always'
# Because the loader isn't aware of the file location, the
# directory is read as-is, relative to cwd rather than the
# file location.
assert environment.directory == 'something'
# [bug] Make sure the bundles are loaded as well.
assert len(environment) == 1
def test_load_environment_directory_base(self):
environment = self.loader("""
url: /foo
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'
class TestPython(object):
"""Test the PythonLoader.
"""
def test_path(self):
"""[bug] Regression test: Python loader does not leave
sys.path messed up.
"""
old_path = sys.path[:]
loader = PythonLoader('sys')
assert sys.path == old_path