コード例 #1
0
ファイル: test_calculator.py プロジェクト: LeonamSilva/stoq
    def test_apply(self):
        entry = ProxyEntry()
        entry.data_type = currency
        entry.set_text('150')
        calc = CalculatorPopup(entry, CalculatorPopup.MODE_SUB)

        # calc.popup will not work here, so call _update_ui directly
        calc._update_ui()
        calc._entry.set_text('10%')
        event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
        event.keyval = gtk.keysyms.Return
        event.window = gtk.gdk.get_default_root_window()
        calc.emit('key-press-event', event)
        calc.emit('key-press-event', event)
        self.assertEqual(entry.read(), 135)
コード例 #2
0
    def test_apply(self):
        entry = ProxyEntry()
        entry.data_type = currency
        entry.set_text('150')
        calc = CalculatorPopup(entry, CalculatorPopup.MODE_SUB)

        # calc.popup will not work here, so call _update_ui directly
        calc._update_ui()
        calc._entry.set_text('10%')
        event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
        event.keyval = gtk.keysyms.Return
        event.window = gtk.gdk.get_default_root_window()
        calc.emit('key-press-event', event)
        calc.emit('key-press-event', event)
        self.assertEqual(entry.read(), 135)
コード例 #3
0
ファイル: test_calculator.py プロジェクト: LeonamSilva/stoq
    def test_validate(self):
        def validate_entry(entry, value):
            if value == 100:
                return ValidationError()

        # FIXME: For some reason, entry is not emitting 'changed' event
        # on set_text, not even if we call entry.emit('changed') by hand.
        # That only happens here on the test. Figure out why
        def update_entry(entry, value):
            entry.set_text(value)
            entry.validate(force=True)

        entry = ProxyEntry()
        entry.data_type = currency
        entry.connect('validate', validate_entry)
        entry.set_text('150')

        calc = CalculatorPopup(entry, CalculatorPopup.MODE_SUB)
        # calc.popup will not work here, so call _update_ui directly
        calc._update_ui()
        self.assertValid(calc, ['_entry'])
        self.assertNotVisible(calc, ['_warning'])

        for value in ['abc', '+10%', '-10%', '+10', '-10']:
            update_entry(calc._entry, value)
            self.assertInvalid(calc, ['_entry'])
            self.assertNotVisible(calc, ['_warning'])

        update_entry(calc._entry, '40')
        self.assertValid(calc, ['_entry'])
        self.assertNotVisible(calc, ['_warning'])

        # 50 of discount will make the value invalid on entry
        # (see validate_entry above)
        update_entry(calc._entry, '50')
        self.assertValid(calc, ['_entry'])
        self.assertVisible(calc, ['_warning'])
コード例 #4
0
    def test_validate(self):
        def validate_entry(entry, value):
            if value == 100:
                return ValidationError()

        # FIXME: For some reason, entry is not emitting 'changed' event
        # on set_text, not even if we call entry.emit('changed') by hand.
        # That only happens here on the test. Figure out why
        def update_entry(entry, value):
            entry.set_text(value)
            entry.validate(force=True)

        entry = ProxyEntry()
        entry.data_type = currency
        entry.connect('validate', validate_entry)
        entry.set_text('150')

        calc = CalculatorPopup(entry, CalculatorPopup.MODE_SUB)
        # calc.popup will not work here, so call _update_ui directly
        calc._update_ui()
        self.assertValid(calc, ['_entry'])
        self.assertNotVisible(calc, ['_warning'])

        for value in ['abc', '+10%', '-10%', '+10', '-10']:
            update_entry(calc._entry, value)
            self.assertInvalid(calc, ['_entry'])
            self.assertNotVisible(calc, ['_warning'])

        update_entry(calc._entry, '40')
        self.assertValid(calc, ['_entry'])
        self.assertNotVisible(calc, ['_warning'])

        # 50 of discount will make the value invalid on entry
        # (see validate_entry above)
        update_entry(calc._entry, '50')
        self.assertValid(calc, ['_entry'])
        self.assertVisible(calc, ['_warning'])