示例#1
0
    def testGetInputWithDefaultWithLists(self):
        diffcalc.util.raw_input = MockRawInput('')
        assert (getInputWithDefault('enter a thing',
                                    (1, 2.0, 3.1)) == (1.0, 2.0, 3.1))

        diffcalc.util.raw_input = MockRawInput('1 2.0 3.1')
        assert getInputWithDefault('enter a thing',
                                   'default') == [1.0, 2.0, 3.1]
示例#2
0
 def testGetInputWithDefaultWithStrings(self):
     diffcalc.util.raw_input = MockRawInput('reply')
     print ">>>"
     assert getInputWithDefault('enter a thing', 'default') == 'reply'
     print ">>>"
     diffcalc.util.raw_input = MockRawInput('')
     assert getInputWithDefault('enter a thing', 'default') == 'default'
     print ">>>"
     diffcalc.util.raw_input = MockRawInput('1.23 1 a')
     assert getInputWithDefault('enter a thing', 'default') == '1.23 1 a'
示例#3
0
    def testGetInputWithDefaultWithNumbers(self):
        diffcalc.util.raw_input = MockRawInput('')
        assert getInputWithDefault('enter a thing', 1) == 1.0

        diffcalc.util.raw_input = MockRawInput('')
        assert getInputWithDefault('enter a thing', 1.23) == 1.23

        diffcalc.util.raw_input = MockRawInput('1')
        assert getInputWithDefault('enter a thing', 'default') == 1.0

        diffcalc.util.raw_input = MockRawInput('1.23')
        assert getInputWithDefault('enter a thing', 'default') == 1.23
示例#4
0
    def testMockRawInput(self):
        raw_input = MockRawInput('a')  # @ReservedAssignment
        assert raw_input('?') == 'a'

        raw_input = MockRawInput(['a', '1234', '1 2 3'])  # @ReservedAssignment
        assert raw_input('?') == 'a'
        assert raw_input('?') == '1234'
        assert raw_input('?') == '1 2 3'
        with pytest.raises(IndexError):
            raw_input('?')

        raw_input = MockRawInput(1)  # @ReservedAssignment
        with pytest.raises(TypeError):
            raw_input('?')
示例#5
0
def prepareRawInput(listOfStrings):
    diffcalc.util.raw_input = MockRawInput(listOfStrings)