xonsh/tests/test_wizard.py

49 lines
1.2 KiB
Python
Raw Normal View History

2016-01-02 02:15:37 -08:00
# -*- coding: utf-8 -*-
"""Tests the xonsh lexer."""
from __future__ import unicode_literals, print_function
import os
2016-06-22 23:20:37 +03:00
import pytest
2016-01-02 02:15:37 -08:00
from xonsh.wizard import (Node, Wizard, Pass, PrettyFormatter,
2016-01-02 11:28:36 -08:00
Message, Question, StateVisitor)
2016-01-02 02:15:37 -08:00
TREE0 = Wizard(children=[Pass(), Message(message='yo')])
TREE1 = Question('wakka?', {'jawaka': Pass()})
def test_pretty_format_tree0():
exp = ('Wizard(children=[\n'
' Pass(),\n'
" Message('yo')\n"
'])')
obs = PrettyFormatter(TREE0).visit()
2016-06-22 23:20:37 +03:00
assert exp == obs
assert exp == str(TREE0)
assert exp.replace('\n', '') == repr(TREE0)
2016-01-02 02:15:37 -08:00
def test_pretty_format_tree1():
exp = ('Question(\n'
" question='wakka?',\n"
' responses={\n'
" 'jawaka': Pass()\n"
' }\n'
')')
obs = PrettyFormatter(TREE1).visit()
2016-06-22 23:20:37 +03:00
assert exp == obs
assert exp == str(TREE1)
assert exp.replace('\n', '') == repr(TREE1)
2016-01-02 02:15:37 -08:00
2016-01-02 11:28:36 -08:00
def test_state_visitor_store():
exp = {'rick': [{}, {}, {'and': 'morty'}]}
sv = StateVisitor()
sv.store('/rick/2/and', 'morty')
obs = sv.state
2016-06-22 23:20:37 +03:00
assert exp == obs
2016-01-02 11:28:36 -08:00
exp['rick'][1]['mr'] = 'meeseeks'
sv.store('/rick/-2/mr', 'meeseeks')
2016-06-22 23:20:37 +03:00
assert exp == obs