本文整理汇总了Python中fileasobj.FileAsObj.check方法的典型用法代码示例。如果您正苦于以下问题:Python FileAsObj.check方法的具体用法?Python FileAsObj.check怎么用?Python FileAsObj.check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fileasobj.FileAsObj
的用法示例。
在下文中一共展示了FileAsObj.check方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_check_failure
# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
def test_check_failure(self):
""" Test check() method with wrong parameter type. """
test_file = FileAsObj()
with self.assertRaises(TypeError):
test_file.check(1)
with self.assertRaises(TypeError):
test_file.check(False)
示例2: test_replace_list
# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
def test_replace_list(self):
""" Test substitute lines using a list of strings. """
test_file = FileAsObj()
test_file.contents = TESTCONTENTS.split('\n')
self.assertFalse(test_file.changed)
old = ['#', '# ', '#1']
new = '###'
self.assertTrue(test_file.replace(old, new))
self.assertTrue(test_file.changed)
for this in old:
self.assertFalse(test_file.check(this))
self.assertEqual(test_file.check(new), new)
示例3: test_replace_list
# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
def test_replace_list(self):
test_file = FileAsObj(TestFile, verbose=True)
old = ['#', '# ', '#1']
new = '###'
self.assertTrue(test_file.replace(old, new))
for this in old:
self.assertFalse(test_file.check(this))
示例4:
# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
# Get all lines that contain a #
result = my_file.grep('#')
#
# Remove all lines that contain the word "foo"
# NOTE: this is dangerous and rarely needed.
my_file.rm(my_file.grep('foo'))
#
# Check for line in file, if exists remove it
if 'foo bar' in my_file:
my_file.rm('foo bar')
# or
my_file.rm(my_file.check('foo bar'))
# or
my_file.rm('foo bar') # OK if line not found.
#
# Now that you've changed data let's save it back to disk.
my_file.save()
# or
my_file.write()
# of
if my_file.virgin is False:
my_file.save()
#
示例5: test_check_line_not_present
# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
def test_check_line_not_present(self):
""" Test check() method with line that is not present in file. """
test_file = FileAsObj()
test_file.contents = TESTCONTENTS.split('\n')
self.assertFalse(test_file.check('This line does not exist in the file.'))
示例6: test_check_blank_line
# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
def test_check_blank_line(self):
""" Test check() method with empty line that is present in file. """
test_file = FileAsObj()
test_file.contents = BLANKFILE.split('\n')
self.assertEqual(test_file.check(''), '')
示例7: test_check_present
# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
def test_check_present(self):
""" Test check() method with line that is present in file. """
test_file = FileAsObj()
test_file.contents = TESTCONTENTS.split('\n')
self.assertTrue(test_file.check('# This is a test hosts file'))
示例8: example_search_for_whole_line_using_check
# 需要导入模块: from fileasobj import FileAsObj [as 别名]
# 或者: from fileasobj.FileAsObj import check [as 别名]
def example_search_for_whole_line_using_check():
""" Shorter version, find a complete line in file. """
my_file = FileAsObj('/etc/hosts')
return my_file.check('127.0.0.1 localhost')