def METHOD_NAME(self):
    """Unit test for function download_url_to_fn()"""
    from bleachbit.Chaff import download_url_to_fn
    # 200: no error
    # 404: not retryable error
    # 503: retryable error
    tests = (('http://httpstat.us/200', True),
             ('http://httpstat.us/404', False),
             ('http://httpstat.us/503', False))
    fn = os.path.join(self.tempdir, 'download')
    on_error_called = [False]
    def on_error(msg1, msg2):
        print('test on_error(%s, %s)' % (msg1, msg2))
        on_error_called[0] = True
    for test in tests:
        self.assertNotExists(fn)
        url = test[0]
        expected_rc = test[1]
        on_error_called = [False]
        rc = download_url_to_fn(
            url, fn, on_error=on_error, max_retries=2, backoff_factor=1)
        self.assertEqual(rc, expected_rc)
        if expected_rc:
            self.assertExists(fn)
        self.assertNotEqual(rc, on_error_called[0])
        from bleachbit.FileUtilities import delete
        delete(fn, ignore_missing=True)