Added composer.literal
diff --git a/setup.cfg b/setup.cfg
index 29543d6..34eb9c3 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,7 +1,6 @@
[bdist_wheel]
universal = 1
-
[flake8]
max-line-length = 140
exclude = */migrations/*
@@ -21,6 +20,8 @@
--doctest-modules
--doctest-glob=\*.rst
--tb=short
+markers =
+ literal
[isort]
force_single_line = True
diff --git a/src/composer/__init__.py b/src/composer/__init__.py
index a6822ff..753c2c1 100644
--- a/src/composer/__init__.py
+++ b/src/composer/__init__.py
@@ -5,4 +5,7 @@
_composer = Compiler()
def sequence(*arguments):
- return _composer.sequence(*arguments)
\ No newline at end of file
+ return _composer.sequence(*arguments)
+
+def literal(value):
+ return _composer.literal(value)
\ No newline at end of file
diff --git a/src/composer/composer.py b/src/composer/composer.py
index fcfbfea..5392565 100644
--- a/src/composer/composer.py
+++ b/src/composer/composer.py
@@ -44,7 +44,6 @@
self.message = message
self.argument = arguments
-
def serialize(obj):
return obj.__dict__
@@ -56,6 +55,9 @@
return json.dumps(self.__dict__, indent=2, default=serialize)
class Compiler:
+ def literal(self, value):
+ return self._compose('literal', (value,))
+
def empty(self):
return self._compose('empty', ())
@@ -99,7 +101,8 @@
if 'type' not in arg:
setattr(composition, arg['_'], self.task(argument))
elif arg['type'] == 'value':
- # if (typeof argument === 'function') throw new ComposerError('Invalid argument', argument)
+ if type(argument).__name__ == 'function':
+ raise ComposerError('Invalid argument', argument)
setattr(composition, arg['_'], argument)
else:
setattr(composition, arg['_'], argument)
@@ -146,12 +149,12 @@
return delimiter+newName
# class Composer(Compiler):
-# def action(self, name, options):
-# """ enhanced action combinator: mangle name, capture code """
+# def action(self, name, options):
+# """ enhanced action combinator: mangle name, capture code """
# name = parseActionName(name)
- # let exec
+# let exec
- # const composition = { type: 'action', name }
- # if (exec) composition.action = { exec }
- # return new Composition(composition)
+# const composition = { type: 'action', name }
+# if (exec) composition.action = { exec }
+# return new Composition(composition)
diff --git a/tests/test_composer.py b/tests/test_composer.py
index b827a7a..52d52a1 100644
--- a/tests/test_composer.py
+++ b/tests/test_composer.py
@@ -1,6 +1,5 @@
-
import composer
-
+import pytest
def test_parse_action_name():
combos = [
@@ -34,3 +33,22 @@
def test_main():
composition = composer.sequence("first", "second")
print(composition)
+
+@pytest.mark.literal
+class TestLiteral:
+
+ def test_boolean(self):
+ composition = composer.literal(True)
+ print(composition)
+
+ def test_number(self):
+ composition = composer.literal(42)
+ print(composition)
+
+ def test_invalid_arg(self):
+ try:
+ composer.literal(lambda x:x)
+ assert False
+ except composer.ComposerError as error:
+ assert error.message == 'Invalid argument'
+