def test_SetVariableFrame_set_bg(self): top_widget = SetVariablesFrame() down_1 = tk.Frame(master=top_widget) down_2 = tk.Frame(master=down_1) down_3 = tk.Label(master=down_2) top_widget.set_bg('blue') for widget in [top_widget, down_1, down_2, down_3]: self.assertEqual(widget.cget('bg'), 'blue')
def set_up_frame(self, frame: SetVariablesFrame): for key, value in self._dictionary.items(): try: frame.set_variable(key, value) except AttributeError: continue except ValueError: msg = 'Tried to set key: {!r} to incompatible value: {!r}.'.format( key, value) raise ConfigFileError(msg)
def test_SetVariableFrame_IntVar_and_bool(self): frame = SetVariablesFrame() frame.boolean = tk.IntVar() frame.set_variable('boolean', True) self.assertEqual(frame.boolean.get(), 1) frame.set_variable('boolean', False) self.assertEqual(frame.boolean.get(), 0)
def test_SetVariableFrame_set_variable_WTF_edge_case_bool_is_int_and_Tk_evaluates_to_zero( self): frame = SetVariablesFrame() frame.int = IntSpinBox(range_=(0, 10)) frame.pct = PctSpinBox() frame.set_variable('int', True) self.assertEqual(frame.int.get_int(), 0) frame.set_variable('pct', True) self.assertEqual(frame.pct.get_probability(), 0.0)
def test_SetVariableFrame_unanticipated_value_raises_error(self): frame = SetVariablesFrame() frame.pct = PctSpinBox() frame.int_box = IntSpinBox(range_=(2, 5)) frame.int_var = tk.IntVar() frame.str_var = tk.StringVar() self.assertRaises(ValueError, frame.set_variable, 'pct', '.1') self.assertRaises(ValueError, frame.set_variable, 'int_box', 1.0) self.assertRaises(ValueError, frame.set_variable, 'int_var', 1.0) self.assertRaises(ValueError, frame.set_variable, 'str_var', True)
def test_SetVariableFrame_set_variable_EDGE_CASE_pct_spin_box_set_int( self): frame = SetVariablesFrame() frame.pct = PctSpinBox() frame.set_variable('pct', 5) self.assertEqual(frame.pct.get_probability(), 0.05)
def test_SetVariableFrame_PopupSelectVar_str(self): frame = SetVariablesFrame() frame.selector = PopupSelectVar() frame.set_variable('selector', 'new_value') self.assertEqual(frame.selector.get(), 'new_value')
def test_SetVariableFrame_IntBox_and_int(self): frame = SetVariablesFrame() frame.int = IntSpinBox(range_=(2, 10)) frame.set_variable('int', 11) self.assertEqual(frame.int.get_int(), 10)
def test_SetVariableFrame_PctSpinBox_and_int(self): frame = SetVariablesFrame() frame.pct = PctSpinBox() frame.set_variable('pct', 2) self.assertEqual(frame.pct.get_probability(), 0.02)
def test_SetVariableFrame_non_existent_value_raise_attribute_error(self): frame = SetVariablesFrame() self.assertRaises(AttributeError, frame.set_variable, 'not_there', 2)