I managed to do so using unittest
making two sperate files >> test.py , run_tests.py
1- putting the prompt-toolkit output in a function like so
in test.py
def test_getTitledText():
title, value, height, read_only, width = prompt('input')
wid = getTitledText(
title=title,
name='',
height=height,
value=value,
read_only=read_only,
width=width
)
return wid.get_children()[0].content.text() + wid.get_children()[1].content.buffer.text == title + ': '+value ## dont remove this space
In this way, I am accessing the real output of the prompt-toolkit lib for my custom widget (can be done for any type of widget)
2- test it by the expected output
in run_tests.py
class Test_GetTitledText(unittest.TestCase):
def test_getTitledText1(self): ### valid values
with patch('test.prompt', return_value = ("Title","value",1,False,0)) as prompt : ## return_value >> title, value, height, read_only, width
self.assertEqual(test_getTitledText(), True)
prompt.assert_called_once_with('input')
def test_getTitledText2(self): ### valid values with hight=3, and read_only
with patch('test.prompt', return_value = ("Title","value",3,True,2)) as prompt : ## return_value >> title, value, height, read_only, width
self.assertEqual(test_getTitledText(), True)
prompt.assert_called_once_with('input')
I dont know if there is an other valid way to do so, but this way worked for me.