def test_file_gz(): src = get_fn('tz2_2.pdb.gz') fh = FileManager(src) nt.assert_true(fh.use_filename) nt.assert_true(fh.is_compressed) nt.assert_equal(fh.compressed_ext, 'gz') nt.assert_true(fh.ext, 'pdb') nt.assert_true(fh.is_filename) with open(src, 'rb') as src2: fh2 = FileManager(src2, compressed=True) nt.assert_false(fh2.is_filename) nt.assert_true(fh.is_compressed) def func(): fh2.ext nt.assert_raises(ValueError, func) with open(src, 'rb') as src3: fh3 = FileManager(src3, compressed=True, ext='pdb') nt.assert_true(fh3.ext, 'pdb') # specify compression fh4 = FileManager(src, compressed=True) nt.assert_true(fh4.is_compressed) content = gzip.open(src).read() nt.assert_equal(fh4.read(force_buffer=True), content)
def test_file_gz(): src = get_fn('tz2_2.pdb.gz') fh = FileManager(src) assert fh.use_filename assert fh.is_compressed assert_equal(fh.compressed_ext, 'gz') assert fh.ext.endswith('pdb') assert fh.is_filename with open(src, 'rb') as src2: fh2 = FileManager(src2, compressed=True) assert not fh2.is_filename assert fh.is_compressed def func(): fh2.ext with pytest.raises(ValueError): func() with open(src, 'rb') as src3: fh3 = FileManager(src3, compressed=True, ext='pdb') assert fh3.ext.endswith('pdb') # specify compression fh4 = FileManager(src, compressed=True) assert fh4.is_compressed content = gzip.open(src).read() assert_equal(fh4.read(force_buffer=True), content)
def test_file_current_folder(): src = get_fn('tz2.pdb') fh = FileManager(src) nt.assert_true(fh.use_filename) nt.assert_false(fh.is_compressed) nt.assert_true(fh.ext, 'pdb') nt.assert_true(fh.is_filename) nt.assert_true(fh.read(), fh.src) with open(src) as src2: fh2 = FileManager(src2) nt.assert_false(fh2.is_filename) nt.assert_true(fh2.read(), src2.read()) with open(src) as src2: nt.assert_true(fh.read(), src2.read()) fh3 = FileManager(src) content = open(src, 'rb').read() nt.assert_equal(fh3.read(force_buffer=True), content) # blob fh4 = FileManager(content) nt.assert_equal(fh4.read(force_buffer=True), content)
def test_file_current_folder(): src = get_fn('tz2.pdb') fh = FileManager(src) assert fh.use_filename assert not fh.is_compressed assert fh.ext.endswith('pdb') assert fh.is_filename assert fh.read() == fh.src with open(src) as src2: fh2 = FileManager(src2) assert not fh2.is_filename fh2_content = fh2.read() src2.seek(0) assert fh2_content == src2.read() with open(src) as src2: fh_content = fh.read() src2.seek(0) assert fh_content != src2.read() fh3 = FileManager(src) content = open(src, 'rb').read() assert_equal(fh3.read(force_buffer=True), content) # blob fh4 = FileManager(content) assert_equal(fh4.read(force_buffer=True), content)
def test_file_not_use_filename(): src = os.path.abspath(nglview.__file__) fh = FileManager(src) nt.assert_false(fh.is_compressed) nt.assert_true(fh.ext, 'py') nt.assert_true(fh.is_filename) with open(src) as src2: fh2 = FileManager(src2) nt.assert_false(fh2.is_filename) nt.assert_true(fh2.read(), src2.read())
def test_file_manager_use_url(): fh = FileManager('rcsb://1tsu.pdb') nt.assert_true(fh.is_url) nt.assert_equal(fh.ext, 'pdb') nt.assert_false(fh.is_compressed) fh = FileManager('http://dummy.com/1tsu.pdb') nt.assert_true(fh.is_url) nt.assert_equal(fh.ext, 'pdb') fh = FileManager('http://dummy.com/1tsu.pdb.gz') nt.assert_true(fh.is_url) nt.assert_equal(fh.ext, 'pdb') nt.assert_true(fh.is_compressed)
def test_file_not_use_filename(): src = os.path.join(os.path.dirname(nglview.__file__), '__init__.py') fh = FileManager(src) assert not fh.is_compressed assert fh.ext.endswith('py') assert fh.is_filename with open(src) as src2: fh2 = FileManager(src2) assert not fh2.is_filename fh2_content = fh2.read() src2.seek(0) assert fh2_content == src2.read()
def test_file_manager_use_url(): fh = FileManager('rcsb://1tsu.pdb') assert fh.is_url assert_equal(fh.ext, 'pdb') assert not fh.is_compressed fh = FileManager('http://dummy.com/1tsu.pdb') assert fh.is_url assert_equal(fh.ext, 'pdb') fh = FileManager('http://dummy.com/1tsu.pdb.gz') assert fh.is_url assert_equal(fh.ext, 'pdb') assert fh.is_compressed
def test_file_passing_blob(): src = get_fn('tz2.pdb') blob = open(src).read() fm = FileManager(blob) nt.assert_false(fm.is_filename) nt.assert_raises(ValueError, lambda: fm.ext)
def test_file_passing_blob(): src = get_fn('tz2.pdb') blob = open(src).read() fm = FileManager(blob) assert not fm.is_filename with pytest.raises(ValueError): fm.ext
def test_file_passing_blob_from_gzip(): import gzip src = get_fn('tz2_2.pdb.gz') blob = gzip.open(src).read() fm = FileManager(blob) nt.assert_false(fm.is_filename) nt.assert_raises(ValueError, lambda: fm.ext)
def test_file_passing_blob_from_gzip(): import gzip src = get_fn('tz2_2.pdb.gz') blob = gzip.open(src).read() fm = FileManager(blob) assert not fm.is_filename with pytest.raises(ValueError): fm.ext
def test_file_current_folder(): src = get_fn('tz2.pdb') fh = FileManager(src) assert fh.use_filename assert not fh.is_compressed assert fh.ext.endswith('pdb') assert fh.is_filename assert fh.read() == os.path.relpath(fh.src) with open(src) as src2: fh2 = FileManager(src2) assert not fh2.is_filename fh2_content = fh2.read() src2.seek(0) assert fh2_content == src2.read() with open(src) as src2: fh_content = fh.read() src2.seek(0) assert fh_content != src2.read() fh3 = FileManager(src) content = open(src, 'r').read() assert_equal(fh3.read(force_buffer=True), content) # blob fh4 = FileManager(content) assert_equal(fh4.read(force_buffer=True), content)