def test_syntax_9(): source = dedent("""\ template Main(A, B: 12, *C): pass """) compile_source(source, 'Main')
def test_syntax_3(): source = dedent("""\ template Main(): const value = 12 """) compile_source(source, 'Main')
def test_syntax_10(): source = dedent("""\ template Main(A=None): pass """) compile_source(source, 'Main')
def test_bad_syntax_17(): source = dedent("""\ template Main(): Foo(): a, *c """) compile_source(source, 'Main')
def test_bad_syntax_19(): source = dedent("""\ template Main(Arg): const Arg = 12 """) compile_source(source, 'Main')
def test_bad_syntax_12(): source = dedent("""\ template Main(A, B=None, C): pass """) compile_source(source, 'Main')
def test_bad_syntax_14(): source = dedent("""\ template Main(*C, A=None) pass """) compile_source(source, 'Main')
def test_bad_syntax_10(): source = dedent("""\ template Main(A B): pass """) compile_source(source, 'Main')
def test_bad_syntax_9(): source = dedent("""\ template Main(): alias value """) compile_source(source, 'Main')
def test_bad_syntax_8(): source = dedent("""\ template Main(): event value """) compile_source(source, 'Main')
def test_syntax_14(): source = dedent("""\ template Main(A, B: 12, C=None, *D): pass """) compile_source(source, 'Main')
def test_syntax_7(): source = dedent("""\ template Main(A, B, *C): pass """) compile_source(source, 'Main')
def test_bad_syntax_4(): source = dedent("""\ template Main: pass """) with pytest.raises(SyntaxError): compile_source(source, 'Main')
def test_bad_syntax_3(): source = dedent("""\ template Main: pass """) compile_source(source, 'Main')
def test_bad_syntax_19(): source = dedent("""\ template Main(Arg): const Arg = 12 """) with pytest.raises(SyntaxError): compile_source(source, 'Main')
def test_bad_syntax_20(): source = dedent("""\ template Main(Arg): const Args = 12 Field: Args: pass """) compile_source(source, 'Main')
def test_bad_syntax_18(): source = dedent("""\ template Main(): Field: a: pass Foo(): a: pass """) compile_source(source, 'Main')
def test_bad_syntax_9(): source = dedent("""\ template Main(): alias value """) with pytest.raises(SyntaxError): compile_source(source, 'Main')
def test_bad_syntax_17(): source = dedent("""\ template Main(): Foo(): a, *c """) with pytest.raises(SyntaxError): compile_source(source, 'Main')
def test_attr_syntax_1(): source = dedent("""\ from enaml.widgets.api import * enamldef Main(Window): attr d """) compile_source(source, 'Main')
def test_attr_syntax_2(): source = dedent("""\ from datetime import date from enaml.widgets.api import * enamldef Main(Window): attr d: date """) compile_source(source, 'Main')
def test_attr_syntax_6(): source = dedent("""\ import datetime from enaml.widgets.api import * enamldef Main(Window): attr d: datetime.date = datetime.date.today() """) compile_source(source, 'Main')
def test_bad_syntax_20(): source = dedent("""\ template Main(Arg): const Args = 12 Field: Args: pass """) with pytest.raises(SyntaxError): compile_source(source, 'Main')
def test_bad_syntax_18(): source = dedent("""\ template Main(): Field: a: pass Foo(): a: pass """) with pytest.raises(SyntaxError): compile_source(source, 'Main')
def test_bad_instantiation_4(): source = dedent("""\ template Other(A): pass template Other(A): pass """) compile_source(source, 'Main')
def test_syntax_15(): source = dedent("""\ template Main(A, B, C): Field: pass PushButton: pass """) compile_source(source, 'Main')
def test_bad_attr_syntax_3(): # No operator source = dedent("""\ from enaml.widgets.api import * enamldef Main(Window): attr d: object "" """) with pytest.raises(SyntaxError): compile_source(source, 'Main')
def test_bad_instantiation_4(): source = dedent("""\ template Other(A): pass template Other(A): pass """) with pytest.raises(TypeError): compile_source(source, 'Main')
def test_bad_attr_syntax_2(): # Dot in attr name source = dedent("""\ from enaml.widgets.api import * enamldef Main(Window): attr a.d """) with pytest.raises(SyntaxError): compile_source(source, 'Main')
def test_bad_instantiation_2(): source = dedent("""\ from enaml.widgets.api import * template Other(A, B, C): Field: pass enamldef Main(Window): Other(): pass """) compile_source(source, 'Main')
def test_bad_attr_syntax_1(): # Invalid type source = dedent("""\ import datetime from enaml.widgets.api import * enamldef Main(Window): attr d: datetime.date.now() """) with pytest.raises(SyntaxError): compile_source(source, 'Main')
def test_bad_instantiation_1(): source = dedent("""\ from enaml.widgets.api import * template Other(): Boo: pass enamldef Main(Window): Other(): pass """) with pytest.raises(NameError): compile_source(source, 'Main')
def test_ordering(): source = dedent("""\ from enaml.widgets.api import * enamldef Content(Container): Field: field: alias this_text: field.text alias text: field.this_text enamldef Main(Window): Content: pass """) compile_source(source, 'Main')
def test_syntax_3(): source = dedent("""\ from enaml.widgets.api import * enamldef Content(Container): alias pc: pb.text PushButton: pb: name = 'button' enamldef Main(Window): Content: name = 'content' """) compile_source(source, 'Main')
def test_bad_instantiation_8(): source = dedent("""\ from enaml.widgets.api import * template Foo(): Field: pass Field: pass Field: pass enamldef Main(Window): Foo(): a, b, c, d: pass """) compile_source(source, 'Main')
def test_invoking_broken_dfunc(attribute): """Test invoking a declarative function whose one key attribute is missing. """ source = dedent("""\ from enaml.widgets.window import Window enamldef MyWindow(Window): main: func call(arg, kwarg=1): return 1 """) tester = compile_source(source, 'MyWindow')() if attribute == '__builtins__': del tester.call.__func__.__globals__['__builtins__'] obj = tester elif attribute == '_d_storage': del tester.call.__self__._d_storage obj = object() else: raise RuntimeError('wrong parameter') exc = KeyError if attribute == '__builtins__' else AttributeError with pytest.raises(exc) as excinfo: type(tester).call(obj, 1) assert attribute in excinfo.exconly()
def test_bar_ordering(): source = dedent("""\ from enaml.widgets.api import * enamldef Content(Container): alias text: field.this_text Field: field: alias this_text: field.text enamldef Main(Window): Content: pass """) with pytest.raises(TypeError): compile_source(source, 'Main')
def test_bad_override_1(): source = dedent("""\ from enaml.widgets.api import * enamldef Content(Container): alias background Field: background: pass enamldef Main(Window): Content: pass """) with pytest.raises(TypeError): compile_source(source, 'Main')
def test_bad_instantiation_5(): source = dedent("""\ from enaml.widgets.api import * template Other(A, B: 12): pass template Other(A: 0, B): pass enamldef Main(Window): Other(0, 12): pass """) compile_source(source, 'Main')
def test_instantiation_10(): source = dedent("""\ from enaml.widgets.api import * template Spam(): Field: pass Label: pass Field: pass enamldef Main(Window): alias a alias b alias c attr rest = rest Spam(): a, b, c: pass Spam(): *rest: pass """) from enaml.widgets.api import Field, Label main = compile_source(source, 'Main')() assert isinstance(main.a, Field) assert isinstance(main.b, Label) assert isinstance(main.c, Field) types = (Field, Label, Field) rtypes = tuple(type(r) for r in main.rest) assert rtypes == types
def test_name_selector(): from enaml.styling import StyleCache source = dedent("""\ from enaml.widgets.api import Window, Container, PushButton from enaml.styling import StyleSheet, Style, Setter enamldef Sheet(StyleSheet): Style: object_name = 'button' Setter: field = 'background' value = 'blue' enamldef Main(Window): alias button alias other Sheet: pass Container: PushButton: button: name = 'button' PushButton: other: style_class = 'button' """) main = compile_source(source, 'Main')() assert len(StyleCache.styles(main.button)) == 1 assert len(StyleCache.styles(main.other)) == 0
def test_cache_1(): from enaml.application import Application from enaml.styling import StyleCache source = dedent("""\ from enaml.widgets.api import Window, Container, PushButton from enaml.styling import StyleSheet, Style, Setter enamldef Sheet(StyleSheet): Style: element = 'PushButton' Setter: field = 'background' value = 'blue' enamldef Main(Window): alias button Sheet: pass Container: PushButton: button: pass """) _clear_cache() app = Application.instance() if app is not None: app.style_sheet = None main = compile_source(source, 'Main')() styles = StyleCache.styles(main.button) assert len(styles) == 1 assert not _cache_items_empty() assert not _cache_styles_empty() main.destroy() assert _cache_items_empty() assert _cache_styles_empty()
def test_element_selector(): from enaml.styling import StyleCache source = dedent("""\ from enaml.widgets.api import Window, Container, PushButton, Field from enaml.styling import StyleSheet, Style, Setter enamldef Sheet(StyleSheet): Style: element = 'PushButton' Setter: field = 'background' value = 'blue' enamldef SubButton(PushButton): pass enamldef Main(Window): alias button alias subbutton alias field Sheet: pass Container: PushButton: button: pass SubButton: subbutton: pass Field: field: pass """) main = compile_source(source, 'Main')() assert len(StyleCache.styles(main.button)) == 1 assert len(StyleCache.styles(main.subbutton)) == 1 assert len(StyleCache.styles(main.field)) == 0
def test_set_comprehension_func(value): """Test running a set comprehension in a declarative function. """ source = FUNCTION_TEMPLATE.format('{%s for i in range(10)}' % value) win = compile_source(source, 'Main', namespace={'RUN_CHECK': True})() assert win.call()
def test_handling_nested_comprehension(): """Test handling nested comprehensions. """ source = FUNCTION_TEMPLATE.format('{self for i in {j for j in range(10)}}') win = compile_source(source, 'Main', namespace={'RUN_CHECK': True})() assert win.call()
def test_syntax_20(): source = dedent("""\ template Other(*Args): Slider: pass template Main(A, B, C): Field: pass PushButton: pass Other(A, B, C): *all: pass """) compile_source(source, 'Main')