def test_init_with_parameters(self): """Start.__init__() should set the given parameters, as the initial attribute values. """ exp = { 'data': grid.Grid(3, 3), 'term': blessed.Terminal(), } state = sui.Start(**exp) act = { 'data': state.data, 'term': state.term, } self._dicteq(exp, act)
def test_init_without_parameters(self): """Start.__init__() should create default attribute values if no parameters are passed to it. """ exp = { 'data': grid.Grid, 'term': blessed.Terminal, } state = sui.Start() act = { 'data': type(state.data), 'term': type(state.term), } self._dicteq(exp, act)
def test_update_ui(self, mock_print): """Start.update_ui() should draw the initial UI.""" data = grid.Grid(3, 3) term = blessed.Terminal() state = sui.Start(data, term) exp = [ call(loc.format(1, 1) + ' '), call(loc.format(2, 1) + ' '), call(loc.format(3, 1) + '\u2500' * data.width), call(loc.format(4, 1) + state.menu + clr_eol, end='', flush=True), ] state.update_ui() act = mock_print.mock_calls self._listeq(exp, act)
def test_input(self, mock_print, _, __): """Start.input() should return the run command if any key is pressed.""" term = blessed.Terminal() exp = ('run', ) exp_calls = [ call(loc.format(term.height, 1) + 'Press any key to continue.' + clr_eol, end='', flush=True), ] state = sui.Start() act = state.input() act_calls = mock_print.mock_calls self.assertTupleEqual(exp, act) self.assertListEqual(exp_calls, act_calls)
def test_run(self): """Start.run() should always return a Core object initialized with the Start object's grid and term. """ exp_class = sui.Core exp_attrs = { 'data': grid.Grid(3, 3), 'term': blessed.Terminal(), } state = sui.Start(**exp_attrs) act = state.run() act_attrs = { 'data': act.data, 'term': act.term, } self.assertIsInstance(act, exp_class) self.assertDictEqual(exp_attrs, act_attrs)