本文整理汇总了Python中numpy.lib._datasource.open方法的典型用法代码示例。如果您正苦于以下问题:Python _datasource.open方法的具体用法?Python _datasource.open怎么用?Python _datasource.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.lib._datasource
的用法示例。
在下文中一共展示了_datasource.open方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_Bz2File_text_mode_warning
# 需要导入模块: from numpy.lib import _datasource [as 别名]
# 或者: from numpy.lib._datasource import open [as 别名]
def test_Bz2File_text_mode_warning(self):
try:
import bz2
except ImportError:
# We don't have the bz2 capabilities to test.
pytest.skip()
# Test datasource's internal file_opener for BZip2 files.
filepath = os.path.join(self.tmpdir, 'foobar.txt.bz2')
fp = bz2.BZ2File(filepath, 'w')
fp.write(magic_line)
fp.close()
with assert_warns(RuntimeWarning):
fp = self.ds.open(filepath, 'rt')
result = fp.readline()
fp.close()
assert_equal(magic_line, result)
示例2: test_ValidGzipFile
# 需要导入模块: from numpy.lib import _datasource [as 别名]
# 或者: from numpy.lib._datasource import open [as 别名]
def test_ValidGzipFile(self):
try:
import gzip
except ImportError:
# We don't have the gzip capabilities to test.
import nose
raise nose.SkipTest
# Test datasource's internal file_opener for Gzip files.
filepath = os.path.join(self.tmpdir, 'foobar.txt.gz')
fp = gzip.open(filepath, 'w')
fp.write(magic_line)
fp.close()
fp = self.ds.open(filepath)
result = fp.readline()
fp.close()
self.assertEqual(magic_line, result)
示例3: test_Bz2File_text_mode_warning
# 需要导入模块: from numpy.lib import _datasource [as 别名]
# 或者: from numpy.lib._datasource import open [as 别名]
def test_Bz2File_text_mode_warning(self):
try:
import bz2
except ImportError:
# We don't have the bz2 capabilities to test.
raise SkipTest
# Test datasource's internal file_opener for BZip2 files.
filepath = os.path.join(self.tmpdir, 'foobar.txt.bz2')
fp = bz2.BZ2File(filepath, 'w')
fp.write(magic_line)
fp.close()
with assert_warns(RuntimeWarning):
fp = self.ds.open(filepath, 'rt')
result = fp.readline()
fp.close()
assert_equal(magic_line, result)
示例4: test_ValidHTTP
# 需要导入模块: from numpy.lib import _datasource [as 别名]
# 或者: from numpy.lib._datasource import open [as 别名]
def test_ValidHTTP(self):
fh = self.ds.open(valid_httpurl())
assert_(fh)
fh.close()
示例5: test_InvalidHTTP
# 需要导入模块: from numpy.lib import _datasource [as 别名]
# 或者: from numpy.lib._datasource import open [as 别名]
def test_InvalidHTTP(self):
url = invalid_httpurl()
assert_raises(IOError, self.ds.open, url)
try:
self.ds.open(url)
except IOError as e:
# Regression test for bug fixed in r4342.
assert_(e.errno is None)
示例6: test_ValidFile
# 需要导入模块: from numpy.lib import _datasource [as 别名]
# 或者: from numpy.lib._datasource import open [as 别名]
def test_ValidFile(self):
local_file = valid_textfile(self.tmpdir)
fh = self.ds.open(local_file)
assert_(fh)
fh.close()
示例7: test_InvalidFile
# 需要导入模块: from numpy.lib import _datasource [as 别名]
# 或者: from numpy.lib._datasource import open [as 别名]
def test_InvalidFile(self):
invalid_file = invalid_textfile(self.tmpdir)
assert_raises(IOError, self.ds.open, invalid_file)
示例8: test_ValidGzipFile
# 需要导入模块: from numpy.lib import _datasource [as 别名]
# 或者: from numpy.lib._datasource import open [as 别名]
def test_ValidGzipFile(self):
try:
import gzip
except ImportError:
# We don't have the gzip capabilities to test.
pytest.skip()
# Test datasource's internal file_opener for Gzip files.
filepath = os.path.join(self.tmpdir, 'foobar.txt.gz')
fp = gzip.open(filepath, 'w')
fp.write(magic_line)
fp.close()
fp = self.ds.open(filepath)
result = fp.readline()
fp.close()
assert_equal(magic_line, result)
示例9: test_CachedHTTPFile
# 需要导入模块: from numpy.lib import _datasource [as 别名]
# 或者: from numpy.lib._datasource import open [as 别名]
def test_CachedHTTPFile(self):
localfile = valid_httpurl()
# Create a locally cached temp file with an URL based
# directory structure. This is similar to what Repository.open
# would do.
scheme, netloc, upath, pms, qry, frg = urlparse(localfile)
local_path = os.path.join(self.repos._destpath, netloc)
os.mkdir(local_path, 0o0700)
tmpfile = valid_textfile(local_path)
assert_(self.repos.exists(tmpfile))
示例10: test_DataSourceOpen
# 需要导入模块: from numpy.lib import _datasource [as 别名]
# 或者: from numpy.lib._datasource import open [as 别名]
def test_DataSourceOpen(self):
local_file = valid_textfile(self.tmpdir)
# Test case where destpath is passed in
fp = datasource.open(local_file, destpath=self.tmpdir)
assert_(fp)
fp.close()
# Test case where default destpath is used
fp = datasource.open(local_file)
assert_(fp)
fp.close()
示例11: test_InvalidHTTP
# 需要导入模块: from numpy.lib import _datasource [as 别名]
# 或者: from numpy.lib._datasource import open [as 别名]
def test_InvalidHTTP(self):
url = invalid_httpurl()
self.assertRaises(IOError, self.ds.open, url)
try:
self.ds.open(url)
except IOError as e:
# Regression test for bug fixed in r4342.
assert_(e.errno is None)
示例12: test_InvalidFile
# 需要导入模块: from numpy.lib import _datasource [as 别名]
# 或者: from numpy.lib._datasource import open [as 别名]
def test_InvalidFile(self):
invalid_file = invalid_textfile(self.tmpdir)
self.assertRaises(IOError, self.ds.open, invalid_file)
示例13: test_ValidGzipFile
# 需要导入模块: from numpy.lib import _datasource [as 别名]
# 或者: from numpy.lib._datasource import open [as 别名]
def test_ValidGzipFile(self):
try:
import gzip
except ImportError:
# We don't have the gzip capabilities to test.
raise SkipTest
# Test datasource's internal file_opener for Gzip files.
filepath = os.path.join(self.tmpdir, 'foobar.txt.gz')
fp = gzip.open(filepath, 'w')
fp.write(magic_line)
fp.close()
fp = self.ds.open(filepath)
result = fp.readline()
fp.close()
self.assertEqual(magic_line, result)