-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Rule.from_string() and Rule.to_string()
- Loading branch information
drscannellrh
committed
Apr 6, 2014
1 parent
a77d999
commit 97f0018
Showing
3 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import os | ||
import re | ||
from css_parser.stylesheet import StyleSheet | ||
from css_parser.rule import Rule | ||
|
||
class TestCases: | ||
|
||
# ---------------------------------------- | ||
|
||
def test_from_string(self): | ||
tests = [ | ||
# one rule | ||
{'input': 'body{margin:0;}', | ||
'expected': 'body{margin:0;}' | ||
}, | ||
# one rule, space around | ||
{'input': ' p.indent {margin:0;} ', | ||
'expected': 'p.indent {margin:0;}' | ||
}, | ||
# one rule, multilined | ||
{'input': 'p.indent {' \ | ||
' margin:0;' \ | ||
'}', | ||
'expected': 'p.indent {' \ | ||
' margin:0;' \ | ||
'}' | ||
}, | ||
# one rule, media-queried | ||
{'input': '@media all {' \ | ||
' p { margin:0;}' \ | ||
'}', | ||
'expected': '@media all {' \ | ||
'p { margin:0;}' \ | ||
'}' | ||
} | ||
|
||
] | ||
|
||
for test in tests: | ||
yield self.check_from_string, test | ||
|
||
def check_from_string(self, test): | ||
rule = Rule.from_string(test['input']) | ||
observed = rule.to_string() | ||
for k in test: | ||
print '%s: %s' % (k, test[k]) | ||
print 'observed: %s' % (observed) | ||
assert observed == test['expected'] | ||
|
||
# ---------------------------------------- | ||
|
||
def test_from_string_multiple_rules(self): | ||
tests = [ | ||
# two rules | ||
{'input': 'body{margin:0;} p {padding:0 }', | ||
'expected': ['body{margin:0;}', 'p {padding:0 }'] | ||
}, | ||
# two rules, media-queried | ||
{'input': '@media all {' \ | ||
' p { margin:0;}' \ | ||
' span { margin:0;}' \ | ||
'}', | ||
'expected': ['@media all {p { margin:0;}}', | ||
'@media all {span { margin:0;}}'] | ||
} | ||
] | ||
|
||
for test in tests: | ||
yield self.check_from_string_multiple_rules, test | ||
|
||
def check_from_string_multiple_rules(self, test): | ||
rules = Rule.from_string(test['input']) | ||
observed = [r.to_string() for r in rules] | ||
for k in test: | ||
print '%s: %s' % (k, test[k]) | ||
print 'observed: %s' % (observed) | ||
assert observed == test['expected'] | ||
|
||
# ---------------------------------------- | ||
|
||
|
||
|