当前位置: 首页>>代码示例>>Python>>正文


Python fileasobj.FileAsObj类代码示例

本文整理汇总了Python中fileasobj.FileAsObj的典型用法代码示例。如果您正苦于以下问题:Python FileAsObj类的具体用法?Python FileAsObj怎么用?Python FileAsObj使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FileAsObj类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: example_read_catch_errors

def example_read_catch_errors():
    """ Reading a file and catch errors. """
    try:
        my_file = FileAsObj()
        my_file.read('/tmp/example_file.txt')
    except Exception as msg:
        print(msg)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:examples.py

示例2: test_append_failure_param

 def test_append_failure_param(self):
     """ Test wrong param type in append() """
     test_file = FileAsObj()
     with self.assertRaises(TypeError):
         test_file.append(1)
     with self.assertRaises(TypeError):
         test_file.append(True)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例3: test_replace_list

 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))
开发者ID:nullpass,项目名称:fileasobj,代码行数:7,代码来源:test_fileasobj.py

示例4: test_check_failure

 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)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例5: test_logging_enabled

 def test_logging_enabled(self):
     """ Test local log enabled by default. """
     test_file = FileAsObj()
     self.assertIsNotNone(str(test_file.log))
     test_file.log('FINDME')
     self.assertTrue('FINDME' in str(test_file.log))
     self.assertTrue('FINDME' in test_file.log.trace)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例6: test_append_string_no_unique

 def test_append_string_no_unique(self):
     """ Test content integrity using `unique` """
     test_file = FileAsObj()
     subject = 'uniq'
     self.assertTrue(test_file.append(subject))
     self.assertTrue(test_file.append(subject))
     self.assertTrue(test_file.contents == [subject, subject])
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例7: test_egrep_no_matches

 def test_egrep_no_matches(self):
     """ Test egrep with valid regex but pattern not in file. """
     test_file = FileAsObj()
     test_file.add(TESTCONTENTS)
     result = test_file.egrep('^this is not present in file.*')
     self.assertTrue(result is False)
     self.assertIsInstance(result, bool)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例8: test_egrep_string_start

 def test_egrep_string_start(self):
     """ Test egrep with valid regex. """
     test_file = FileAsObj()
     test_file.add(TESTCONTENTS)
     result = test_file.egrep('^10.*')
     self.assertTrue(len(result) == 5)
     self.assertIsInstance(result, list)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例9: test_good_regex

 def test_good_regex(self):
     """ Test egrep with valid wildcard regex. """
     test_file = FileAsObj()
     test_file.add(TESTCONTENTS)
     result = test_file.egrep('.*rd')
     self.assertTrue(result)
     self.assertIsInstance(result, list)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例10: test_egrep_word_list

 def test_egrep_word_list(self):
     """ Test egrep with valid choice regex. """
     test_file = FileAsObj()
     test_file.add(TESTCONTENTS)
     result = test_file.egrep('(host|bird)')
     self.assertTrue(result)
     self.assertIsInstance(result, list)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例11: test_egrep_word

 def test_egrep_word(self):
     """ Test egrep with a word. """
     test_file = FileAsObj()
     test_file.add(TESTCONTENTS)
     result = test_file.egrep('bird')
     self.assertTrue(result)
     self.assertIsInstance(result, list)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例12: test_subtract

 def test_subtract(self):
     """ Test __sub__ method. """
     test_file = FileAsObj()
     test_file.contents = TESTCONTENTS.split('\n')
     self.assertFalse(test_file.changed)
     self.assertTrue(test_file - '#comment')
     self.assertTrue(test_file.changed)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例13: test_subtract_fail

 def test_subtract_fail(self):
     """ Test __sub__ method fails. """
     test_file = FileAsObj()
     test_file.contents = TESTCONTENTS.split('\n')
     self.assertFalse(test_file.changed)
     self.assertFalse(test_file - 'this string does not exist in file!')
     self.assertFalse(test_file.changed)
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例14: test_replace_whole_line

 def test_replace_whole_line(self):
     """ Test substitute a line. """
     test_file = FileAsObj()
     test_file.add(TESTCONTENTS)
     old = '172.19.18.17    freebird.example.com'
     new = '172.19.18.17    freebird.example.com  # Added 1976.10.29 -jh'
     self.assertTrue(test_file.replace(old, new))
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py

示例15: test_save_with_changes

 def test_save_with_changes(self):
     """ Instance an empty test file, overwrite its contents and save to disk. """
     test_file = FileAsObj()
     test_file.filename = TESTFILE
     test_file.contents = TESTCONTENTS.split('\n')
     self.assertEqual(TESTCONTENTS, str(test_file))
     self.assertTrue(test_file.save())
开发者ID:jhazelwo,项目名称:python-fileasobj,代码行数:7,代码来源:tests_fileasobj.py


注:本文中的fileasobj.FileAsObj类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。