コード例 #1
0
def test_exercise():
    os.chdir('src')

    import exercise

    input_values = ["data.csv","FURIA","data.csv","ENCE"]
    output = []

    def mock_input(s=None):
        if s is not None:
            output.append(s)
            return input_values.pop(0)
        else:
            output.append("")
            return input_values.pop(0)

    exercise.input = mock_input
    exercise.print = lambda s : output.append(s)

    exercise.main()

    exercise.input = mock_input
    exercise.print = lambda s : output.append(s)

    exercise.main()

    assert output == ["File:","Team:","Games: 2","Wins: 1","Losses: 1",\
                      "File:","Team:","Games: 6","Wins: 3","Losses: 3"]
def test_exercise():

    os.chdir('src')
    import exercise

    input_values = ["Nothing","2010","Random","2013","Random","2013",""]
    output = []

    def mock_input(s=None):
        if s is not None:
            output.append(s)
            return input_values.pop(0)
        else:
            output.append("")
            return input_values.pop(0)

    exercise.input = mock_input
    exercise.print = lambda s : output.append(s)

    exercise.main()

    assert output == ["Name (empty will stop):","Publication year:",\
                        "Name (empty will stop):","Publication year:",\
                            "Name (empty will stop):","Publication year:","The book is already on the list. Let's not add the same book again.",\
                                "Name (empty will stop):","Thank you! Books added: 2"]
def test_exercise():
    os.chdir('src')

    import exercise

    input_values = [
        "ZSDRG204", "Random", "ZSDRG104", "Test", "ZSDRG304", "Nothing", ""
    ]
    output = []

    def mock_input(s=None):
        if s is not None:
            output.append(s)
            return input_values.pop(0)
        else:
            output.append("")
            return input_values.pop(0)

    exercise.input = mock_input
    exercise.print = lambda s: output.append(s)

    exercise.main()

    assert output == ["Identifier? (empty will stop)","Name? (empty will stop)",\
                        "Identifier? (empty will stop)","Name? (empty will stop)",\
                            "Identifier? (empty will stop)","Name? (empty will stop)",\
                                "Identifier? (empty will stop)","==Items==","ZSDRG204: Random","ZSDRG104: Test","ZSDRG304: Nothing"]
コード例 #4
0
def test_case(capsys):

    input_values = []
    result = 'Hello, world!\n'

    exercise.input = lambda prompt: input_values.pop(0)

    exercise.main()

    out, err = capsys.readouterr()

    assert out == result, f'for input(s) of {input_values}, the output should be {result} instead of your {out}'
    assert err == ''
コード例 #5
0
ファイル: test.py プロジェクト: adrianrfreedman/CupStack
    def test_12_correct_args_with_error(self, sys, mock_cs):
        mock_cs.return_value.__getitem__.side_effect = cs.CupStackIndexError()

        exercise.main(3, 2, 5, 0)

        sys.exit.assert_called()
コード例 #6
0
ファイル: test.py プロジェクト: adrianrfreedman/CupStack
    def test_11_correct_args(self, _, cs):
        exercise.main(3, 2, 1, 0)

        cs.assert_called_with(levels=3)
        cs.return_value.fill.assert_called_with(2)
        cs.return_value.__getitem__.assert_called_with((1, 0))
コード例 #7
0
def test_case():

    out = exercise.main('')  # enter parameter(s) to test
    result = ''  # enter what should be returned

    assert out == result, f'the function should return {result} instead of {out}'