Exploring strange ansi string error

This commit is contained in:
Griatch 2018-10-14 18:18:59 +02:00
parent 89ce5b9c48
commit 48f334d959
2 changed files with 49 additions and 53 deletions

View file

@ -12,11 +12,6 @@ has markers in it to denounce fields to fill. The markers map the
absolute size of the field and will be filled with an `evtable.EvCell` absolute size of the field and will be filled with an `evtable.EvCell`
object when displaying the form. object when displaying the form.
Note, when printing examples with ANSI color, you need to wrap
the output in `unicode()`, such as `print unicode(form)`. This is
due to a bug in the Python parser and the `print` statement.
Example of input file `testform.py`: Example of input file `testform.py`:
```python ```python
@ -439,10 +434,6 @@ class EvForm(object):
"Prints the form" "Prints the form"
return str(ANSIString("\n").join([line for line in self.form])) return str(ANSIString("\n").join([line for line in self.form]))
def __unicode__(self):
"prints the form"
return str(ANSIString("\n").join([line for line in self.form]))
def _test(): def _test():
"test evform. This is used by the unittest system." "test evform. This is used by the unittest system."
@ -470,5 +461,4 @@ def _test():
# add the tables to the proper ids in the form # add the tables to the proper ids in the form
form.map(tables={"A": tableA, form.map(tables={"A": tableA,
"B": tableB}) "B": tableB})
# unicode is required since the example contains non-ascii characters
return str(form) return str(form)

View file

@ -9,49 +9,55 @@ from evennia.utils import evform
class TestEvForm(TestCase): class TestEvForm(TestCase):
def test_form(self): def test_form(self):
self.maxDiff = None self.maxDiff = None
form = evform._test() form1 = evform._test()
self.assertEqual(form, print("len(form1): {}".format(len(form1)))
'.------------------------------------------------.\n' form2 = evform._test()
'| |\n' print("len(form2): {}".format(len(form2)))
'| Name: \x1b[0m\x1b[1m\x1b[32mTom\x1b[1m\x1b[32m \x1b'
'[1m\x1b[32mthe\x1b[1m\x1b[32m \x1b[0m \x1b[0m ' self.assertEqual(form1, form2)
'Account: \x1b[0m\x1b[1m\x1b[33mGriatch '
'\x1b[0m\x1b[0m\x1b[1m\x1b[32m\x1b[1m\x1b[32m\x1b[1m\x1b[32m\x1b[1m\x1b[32m\x1b[0m\x1b[0m ' # self.assertEqual(form, "")
'|\n' # '.------------------------------------------------.\n'
'| \x1b[0m\x1b[1m\x1b[32mBouncer\x1b[0m \x1b[0m |\n' # '| |\n'
'| |\n' # '| Name: \x1b[0m\x1b[1m\x1b[32mTom\x1b[1m\x1b[32m \x1b'
' >----------------------------------------------< \n' # '[1m\x1b[32mthe\x1b[1m\x1b[32m \x1b[0m \x1b[0m '
'| |\n' # 'Account: \x1b[0m\x1b[1m\x1b[33mGriatch '
'| Desc: \x1b[0mA sturdy \x1b[0m \x1b[0m' # '\x1b[0m\x1b[0m\x1b[1m\x1b[32m\x1b[1m\x1b[32m\x1b[1m\x1b[32m\x1b[1m\x1b[32m\x1b[0m\x1b[0m '
' STR: \x1b[0m12 \x1b[0m\x1b[0m\x1b[0m\x1b[0m' # '|\n'
' DEX: \x1b[0m10 \x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n' # '| \x1b[0m\x1b[1m\x1b[32mBouncer\x1b[0m \x1b[0m |\n'
'| \x1b[0mfellow\x1b[0m \x1b[0m' # '| |\n'
' INT: \x1b[0m5 \x1b[0m\x1b[0m\x1b[0m\x1b[0m' # ' >----------------------------------------------< \n'
' STA: \x1b[0m18 \x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n' # '| |\n'
'| \x1b[0m \x1b[0m' # '| Desc: \x1b[0mA sturdy \x1b[0m \x1b[0m'
' LUC: \x1b[0m10 \x1b[0m\x1b[0m\x1b[0m' # ' STR: \x1b[0m12 \x1b[0m\x1b[0m\x1b[0m\x1b[0m'
' MAG: \x1b[0m3 \x1b[0m\x1b[0m\x1b[0m |\n' # ' DEX: \x1b[0m10 \x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
'| |\n' # '| \x1b[0mfellow\x1b[0m \x1b[0m'
' >----------.-----------------------------------< \n' # ' INT: \x1b[0m5 \x1b[0m\x1b[0m\x1b[0m\x1b[0m'
'| | |\n' # ' STA: \x1b[0m18 \x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
'| \x1b[0mHP\x1b[0m|\x1b[0mMV \x1b[0m|\x1b[0mMP\x1b[0m ' # '| \x1b[0m \x1b[0m'
'| \x1b[0mSkill \x1b[0m|\x1b[0mValue \x1b[0m' # ' LUC: \x1b[0m10 \x1b[0m\x1b[0m\x1b[0m'
'|\x1b[0mExp \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n' # ' MAG: \x1b[0m3 \x1b[0m\x1b[0m\x1b[0m |\n'
'| ~~+~~~+~~ | ~~~~~~~~~~~+~~~~~~~~~~+~~~~~~~~~~~ |\n' # '| |\n'
'| \x1b[0m**\x1b[0m|\x1b[0m***\x1b[0m\x1b[0m|\x1b[0m**\x1b[0m\x1b[0m ' # ' >----------.-----------------------------------< \n'
'| \x1b[0mShooting \x1b[0m|\x1b[0m12 \x1b[0m' # '| | |\n'
'|\x1b[0m550/1200 \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n' # '| \x1b[0mHP\x1b[0m|\x1b[0mMV \x1b[0m|\x1b[0mMP\x1b[0m '
'| \x1b[0m \x1b[0m|\x1b[0m**\x1b[0m \x1b[0m|\x1b[0m*\x1b[0m \x1b[0m ' # '| \x1b[0mSkill \x1b[0m|\x1b[0mValue \x1b[0m'
'| \x1b[0mHerbalism \x1b[0m|\x1b[0m14 \x1b[0m' # '|\x1b[0mExp \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
'|\x1b[0m990/1400 \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n' # '| ~~+~~~+~~ | ~~~~~~~~~~~+~~~~~~~~~~+~~~~~~~~~~~ |\n'
'| \x1b[0m \x1b[0m|\x1b[0m \x1b[0m|\x1b[0m \x1b[0m ' # '| \x1b[0m**\x1b[0m|\x1b[0m***\x1b[0m\x1b[0m|\x1b[0m**\x1b[0m\x1b[0m '
'| \x1b[0mSmithing \x1b[0m|\x1b[0m9 \x1b[0m' # '| \x1b[0mShooting \x1b[0m|\x1b[0m12 \x1b[0m'
'|\x1b[0m205/900 \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n' # '|\x1b[0m550/1200 \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
'| | |\n' # '| \x1b[0m \x1b[0m|\x1b[0m**\x1b[0m \x1b[0m|\x1b[0m*\x1b[0m \x1b[0m '
' -----------`-------------------------------------\n' # '| \x1b[0mHerbalism \x1b[0m|\x1b[0m14 \x1b[0m'
' Footer: \x1b[0mrev 1 \x1b[0m \n' # '|\x1b[0m990/1400 \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
' info \n' # '| \x1b[0m \x1b[0m|\x1b[0m \x1b[0m|\x1b[0m \x1b[0m '
' ') # '| \x1b[0mSmithing \x1b[0m|\x1b[0m9 \x1b[0m'
# '|\x1b[0m205/900 \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
# '| | |\n'
# ' -----------`-------------------------------------\n'
# ' Footer: \x1b[0mrev 1 \x1b[0m \n'
# ' info \n'
# ' ')
def test_ansi_escape(self): def test_ansi_escape(self):
# note that in a msg() call, the result would be the correct |-----, # note that in a msg() call, the result would be the correct |-----,