Update after review.

This commit is contained in:
Adi Roiban 2014-02-18 11:24:00 +02:00
parent f11e9e6ece
commit e82ca278c4
3 changed files with 21 additions and 11 deletions

1
.gitignore vendored
View File

@ -9,4 +9,3 @@ dist
MANIFEST
.tox
.venv*
*.egg-info/

View File

@ -77,23 +77,32 @@ class LessParser(object):
self.result = None
self.target = None
def parse(self, filename='', filestream=None, debuglevel=0):
def parse(self, filename=None, file=None, debuglevel=0):
""" Parse file.
kwargs:
filename (str): File to parse
debuglevel (int): Parser debuglevel
"""
self.scope.push()
if not file:
# We use a path.
file = filename
else:
# We use a stream and try to extract the name from the stream.
if hasattr(file, 'name'):
if filename is not None:
raise AssertionError(
'names of file and filename are in conflict')
filename = file.name()
else:
filename = '(stream)'
self.target = filename
if self.verbose:
print('Compiling target: %s' % filename, file=sys.stderr)
self.scope.push()
self.target = filename
if filestream:
content = filestream
else:
content = filename
self.result = self.parser.parse(
content, lexer=self.lex, debug=debuglevel)
file, lexer=self.lex, debug=debuglevel)
self.post_parse()

View File

@ -24,10 +24,12 @@ class TestLessParser(unittest.TestCase):
@nice-blue: #5B83AD;
""")
self.parser.parse(filestream=stream)
self.parser.parse(file=stream)
# A single object is parser which is the expected variable.
self.assertEqual(1, len(self.parser.result))
# This is a stream without a name so it sets default name.
self.assertEqual('(stream)', self.parser.target)
variable = self.parser.result[0]
self.assertEqual('@nice-blue', variable.name)
self.assertEqual(['#5b83ad'], variable.value)