コード例 #1
0
def test_fmt_thousands_integer_value_error():
    """
    It should raise a ValueError if the value does not represent a valid integer.
    """
    csv_formatter = CsvFormatter({})
    for test_case in ('bad', None):
        try:
            csv_formatter._fmt_thousands_integer(test_case)
            msg = 'The _fmt_thousands_integer must raise an exception when the value is not a representation of an integer'
            assert False, format_msg(msg)
        except ValueError as e:
            if not e.args:
                msg = 'It is expected that the ValueError exception include a descriptive message, but none was provided'
                assert False, format_msg(msg)

            expected_message = 'The value "{:s}" is not valid for the thousands_integer formatter'.format(
                str(test_case))
            msg = 'The exception message did not match the expected message:  Your message: {:s} != Expected message {:s}'.format(
                e.args[0], expected_message)
            assert expected_message == e.args[0], format_msg(msg)
コード例 #2
0
def test_fmt_thousands_integer():
    """
    It should return a value formatted as an integer with commas grouping thousands.
    """
    csv_formatter = CsvFormatter({})
    expected_result = '12,345'
    result = csv_formatter._fmt_thousands_integer('12345')
    msg = 'The _fmt_thousands_integer method must return a formatted string, not None'
    assert result is not None, format_msg(msg)
    msg = 'The expected result was not produced:  Your result: {:s} != Expected result: {:s}'.format(
        result, expected_result)
    assert result == expected_result, format_msg(msg)