Exemplo n.º 1
0
def test_fetch_file(url, tmpdir):
    """Test URL retrieval."""
    tempdir = str(tmpdir)
    archive_name = op.join(tempdir, "download_test")
    with catch_logging() as log:
        _fetch_file(url, archive_name, timeout=30., verbose=True)
    log = log.getvalue()
    assert ', resuming at' not in log
    with open(archive_name, 'rb') as fid:
        data = fid.read()
    stop = len(data) // 2
    assert 0 < stop < len(data)
    with open(archive_name + '.part', 'wb') as fid:
        fid.write(data[:stop])
    with catch_logging() as log:
        _fetch_file(url, archive_name, timeout=30., verbose=True)
    log = log.getvalue()
    assert ', resuming at %s' % sizeof_fmt(stop) in log
    with pytest.raises(Exception, match='Cannot use'):
        _fetch_file('NOT_AN_ADDRESS', op.join(tempdir, 'test'), verbose=False)
    resume_name = op.join(tempdir, "download_resume")
    # touch file
    with open(resume_name + '.part', 'w'):
        os.utime(resume_name + '.part', None)
    _fetch_file(url, resume_name, resume=True, timeout=30., verbose=False)
    with pytest.raises(ValueError, match='Bad hash value'):
        _fetch_file(url, archive_name, hash_='a', verbose=False)
    with pytest.raises(RuntimeError, match='Hash mismatch'):
        _fetch_file(url, archive_name, hash_='a' * 32, verbose=False)
Exemplo n.º 2
0
 def __call__(self, gallery_conf, fname):
     import matplotlib.pyplot as plt
     try:
         from pyvista import Plotter
     except ImportError:
         Plotter = None
     reset_warnings(gallery_conf, fname)
     # in case users have interactive mode turned on in matplotlibrc,
     # turn it off here (otherwise the build can be very slow)
     plt.ioff()
     plt.rcParams['animation.embed_limit'] = 30.
     _assert_no_instances(Brain, 'running')  # calls gc.collect()
     if Plotter is not None:
         _assert_no_instances(Plotter, 'running')
     # This will overwrite some Sphinx printing but it's useful
     # for memory timestamps
     if os.getenv('SG_STAMP_STARTS', '').lower() == 'true':
         import psutil
         process = psutil.Process(os.getpid())
         mem = sizeof_fmt(process.memory_info().rss)
         print(f'{time.time() - self.t0:6.1f} s : {mem}'.ljust(22))
Exemplo n.º 3
0
def test_sizeof_fmt():
    """Test sizeof_fmt
    """
    assert_equal(sizeof_fmt(0), '0 bytes')
    assert_equal(sizeof_fmt(1), '1 byte')
    assert_equal(sizeof_fmt(1000), '1000 bytes')
Exemplo n.º 4
0
def test_sizeof_fmt():
    """Test sizeof_fmt."""
    assert_equal(sizeof_fmt(0), '0 bytes')
    assert_equal(sizeof_fmt(1), '1 byte')
    assert_equal(sizeof_fmt(1000), '1000 bytes')
Exemplo n.º 5
0
def test_sizeof_fmt():
    """Test sizeof_fmt."""
    assert sizeof_fmt(0) == '0 bytes'
    assert sizeof_fmt(1) == '1 byte'
    assert sizeof_fmt(1000) == '1000 bytes'
Exemplo n.º 6
0
def test_sizeof_fmt():
    """Test sizeof_fmt
    """
    assert_equal(sizeof_fmt(0), "0 bytes")
    assert_equal(sizeof_fmt(1), "1 byte")
    assert_equal(sizeof_fmt(1000), "1000 bytes")