Beispiel #1
0
def test_parseDate3(mocker):
    """ 
    Test parseDate with unusual input

    Expected result: result is None

    N.B. Worker.parseDate doesn't implement robust input validation, so will
    trigger an unhandled exception when fed non-string inputs. Hence, this
    test case is currently expected to fail.

    """
    # given: setup test framework
    worker = Worker()
    input_strings = [
        "12/1220", "01/01/19999", "Monday", -1, [], {
            "hello": "world"
        }, 3.5
    ]

    # when:
    for input_string in input_strings:
        result = worker.parseDate(input_string)

        # then:
        AssertThat(result).IsNone()
Beispiel #2
0
def test_parseDate3(mocker):
    """ 
    Test parseLine with bad Date format 1: dd/mmyy

    Expected result: result is None
    """    
    # given: setup test framework
    worker = Worker()
    testString = "12/1220"
    
    # when:
    result = worker.parseDate(testString)
    
    # then:
    AssertThat(result).IsNone()
Beispiel #3
0
def test_parseDate4(mocker):
    """ 
    Test parseLine with bad Date format 2: 32Jan2019

    Expected result: result is None
    """    
    # given: setup test framework
    worker = Worker()
    testString = "32Jan2019"
    
    # when:
    result = worker.parseDate(testString)
    
    # then:
    AssertThat(result).IsNone()
def test_worker_parseDate1_generative(mocker, input_date):

    # given
    input_string = input_date.strftime(format="%d%b%Y")
    worker = Worker()

    # when 
    result = worker.parseDate(input_string)
    
    print(input_string, result)
    
    # then
    AssertThat(result).IsInstanceOf(str)
    AssertThat(result).HasSize(10)
    AssertThat(result.split('-')).HasSize(3)
Beispiel #5
0
def test_parseDate2(mocker):
    """ 
    Test parseLine with Date format 2: ddmmmYYYY

    Expected result: formatted string in dd/mm/YYYY
    """    
    # given: setup test framework
    worker = Worker()
    testString = "04Jan2019"
    expected_result = "04/01/2019"
    
    # when:
    result = worker.parseDate(testString)
    
    # then: (Using PyTruth assertions)
    AssertThat(result).IsEqualTo(expected_result)
Beispiel #6
0
def test_parseDate2(mocker):
    """ 
    Test parseDate with date format: ddmmmYYYY

    Expected result: formatted string in YYYY-mm-dd
    """
    # given: setup test framework
    worker = Worker()
    testString = "04Jan2019"
    expected_result = "2019-01-04"

    # when:
    result = worker.parseDate(testString)

    # then: (Using PyTruth assertions)
    AssertThat(result).IsEqualTo(expected_result)
Beispiel #7
0
def test_parseDate4(mocker):
    """ 
    Test parseDate with unusual input

    Expected result: result is None

    N.B. Worker.parseDate contains some complicated logic, that can get tripped
    by some unusual input - in this case a real-world date format "19th June 2020".
    Hence, this test case is currently expected to fail.

    """
    # given: setup test framework
    worker = Worker()
    input_strings = ["32Jan2019", "Tuesday", "19th June 2020"]

    # when:
    for input_string in input_strings:
        result = worker.parseDate(input_string)

        # then:
        AssertThat(result).IsNone()