예제 #1
0
def test_fmt_us_currency_value_error():
    """
    It should raise a ValueError if the value is not a representation of a float.
    """
    csv_formatter = CsvFormatter({})
    for test_case in ('bad', None):
        try:
            csv_formatter._fmt_us_currency(test_case)
            msg = 'The _fmt_us_currency must raise an exception when the value is not a representation of a floating point number'
            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 us_currency 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_us_currency_success():
    """
    It should return a value formatted as us currency - without commas
    """
    csv_formatter = CsvFormatter({})
    expected_result = '$12345.00'
    test_cases = ('12345', '12345.000')
    for test_case in test_cases:
        result = csv_formatter._fmt_us_currency(test_case)
        msg = 'The _fmt_us_currency 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)