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


Python tempfs.TempFS类代码示例

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


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

示例1: test_loader_methods

 def test_loader_methods(self):
     t = TempFS()
     self._init_modules(t)
     ih = FSImportHook(t)
     sys.meta_path.append(ih)
     try:
         self.assertEquals(ih.find_module("fsih_hello"),ih)
         self.assertEquals(ih.find_module("fsih_helo"),None)
         self.assertEquals(ih.find_module("fsih_pkg"),ih)
         self.assertEquals(ih.find_module("fsih_pkg.sub1"),ih)
         self.assertEquals(ih.find_module("fsih_pkg.sub2"),ih)
         self.assertEquals(ih.find_module("fsih_pkg.sub3"),None)
         m = ih.load_module("fsih_hello")
         self.assertEquals(m.message,"hello world!")
         self.assertRaises(ImportError,ih.load_module,"fsih_helo")
         ih.load_module("fsih_pkg")
         m = ih.load_module("fsih_pkg.sub1")
         self.assertEquals(m.message,"hello world!")
         self.assertEquals(m.a,42)
         m = ih.load_module("fsih_pkg.sub2")
         self.assertEquals(m.message,"hello world!")
         self.assertEquals(m.a,42 * 2)
         self.assertRaises(ImportError,ih.load_module,"fsih_pkg.sub3")
     finally:
         sys.meta_path.remove(ih)
         t.close()
开发者ID:anthonybishopric,项目名称:pyboxfs,代码行数:26,代码来源:test_importhook.py

示例2: TestDokan

    class TestDokan(unittest.TestCase,DokanTestCases,ThreadingTestCases):

        def setUp(self):
            self.temp_fs = TempFS()
            self.drive = "K"
            while os.path.exists(self.drive+":\\") and self.drive <= "Z":
                self.drive = chr(ord(self.drive) + 1)
            if self.drive > "Z":
                raise RuntimeError("no free drive letters")
            fs_to_mount = OSFS(self.temp_fs.getsyspath("/"))
            self.mount_proc = dokan.mount(fs_to_mount,self.drive)#,flags=dokan.DOKAN_OPTION_DEBUG|dokan.DOKAN_OPTION_STDERR,numthreads=1)
            self.fs = OSFS(self.mount_proc.path)

        def tearDown(self):
            self.mount_proc.unmount()
            for _ in xrange(10):
                try:
                    if self.mount_proc.poll() is None:
                        self.mount_proc.terminate()
                except EnvironmentError:
                    time.sleep(0.1)
                else:
                    break
            else:
                if self.mount_proc.poll() is None:
                    self.mount_proc.terminate()
            self.temp_fs.close()
开发者ID:anthonybishopric,项目名称:pyboxfs,代码行数:27,代码来源:test_expose.py

示例3: test_importer_on_meta_path

 def test_importer_on_meta_path(self):
     t = TempFS()
     self._init_modules(t)
     ih = FSImportHook(t)
     sys.meta_path.append(ih)
     try:
         self._check_imports_are_working()
     finally:
         sys.meta_path.remove(ih)
         t.close()
开发者ID:anthonybishopric,项目名称:pyboxfs,代码行数:10,代码来源:test_importhook.py

示例4: TestImporter

class TestImporter (TestCase):

    def setUp(self):
        TestCase.setUp(self)
        self.fs = TempFS()
        self.importer = Importer()
        
    def test_finds_index_file_in_a_subdirectory(self):
        self.fs.makedir("directory")
        self.fs.setcontents("directory/file.txt", "test")
        index_file = self.importer._find_index_file(self.fs, ["*.txt"])
        assert_equals("directory/file.txt", index_file)
开发者ID:rblinzler,项目名称:openmemo,代码行数:12,代码来源:test_importer.py

示例5: TestCSVExport

class TestCSVExport (TestCase):
    def setUp(self):
        TestCase.setUp(self)
        self.fs = TempFS()
        self.exporter = CSVExporter(self.fs, m.HTMLMarkupExporter(self))
        
    def test_single_card(self):
        card = m.ContentObject()
        card['question'] = u'Question'
        card['answer'] = u'Answer'
        self.exporter([card])
        expected = '"Question","Answer"\r\n'
        assert_equals(expected, self.fs.getcontents('index.csv'))

    def test_multiple_cards(self):
        card = m.ContentObject()
        card['question'] = u'Question'
        card['answer'] = u'Answer'
        card2 = m.ContentObject()
        card2['question'] = u'Question 2'
        card2['answer'] = u'Answer 2'
        self.exporter([card, card2])
        expected = '"Question","Answer"\r\n"Question 2","Answer 2"\r\n'
        assert_equals(expected, self.fs.getcontents('index.csv'))
        
    def test_multiline_question_and_answer(self):
        card = m.ContentObject()
        card['question'] = u"Question\nend of question"
        card['answer'] = u"Answer\nend of answer"
        self.exporter([card])
        expected = '"Question\r\nend of question","Answer\r\nend of answer"\r\n'
        assert_equals(expected, self.fs.getcontents('index.csv'))              

    def test_custom_encoding(self):
        card = m.ContentObject()
        card['question'] = u"chrząszcz brzmi w trzcinie"
        card['answer'] =  u"zażółć gęślą jaźń"
        self.exporter.encoding = 'cp1250'
        self.exporter([card])
        expected = u'"chrząszcz brzmi w trzcinie","zażółć gęślą jaźń"\r\n'.encode('cp1250')
        assert_equals(expected, self.fs.getcontents('index.csv'))
        
    def test_card_with_image(self):
        self.images = [m.Image(filename='img2'), m.Image(filename='img1')]
        card = m.ContentObject()
        card['question'] = u'Question <img src="img2" />'
        card['answer'] = u'Answer <img src="img1" />'
        self.exporter([card])
        expected = '"Question <img src=""images/img2.jpg""/>","Answer <img src=""images/img1.jpg""/>"\r\n'
        assert_equals(expected, self.fs.getcontents('index.csv'))                  
开发者ID:rblinzler,项目名称:openmemo,代码行数:50,代码来源:test_csv_export.py

示例6: test_url_on_sys_path

 def test_url_on_sys_path(self):
     t = TempFS()
     zpath = t.getsyspath("modules.zip")
     z = ZipFS(zpath,"w")
     self._init_modules(z)
     z.close()
     z = ZipFS(zpath,"r")
     assert z.isfile("fsih_hello.py")
     z.close()
     sys.path.append("zip://" + zpath)
     FSImportHook.install()
     try:
         self._check_imports_are_working()
     finally:
         sys.path_hooks.remove(FSImportHook)
         sys.path.pop()
         t.close()
开发者ID:anthonybishopric,项目名称:pyboxfs,代码行数:17,代码来源:test_importhook.py

示例7: setUp

 def setUp(self):
     self.temp_fs = TempFS()            
     self.temp_fs.makedir("root")
     self.temp_fs.makedir("mount")
     self.mounted_fs = self.temp_fs.opendir("root")
     self.mount_point = self.temp_fs.getsyspath("mount")
     self.fs = OSFS(self.temp_fs.getsyspath("mount"))
     self.mount_proc = fuse.mount(self.mounted_fs,self.mount_point)
开发者ID:anthonybishopric,项目名称:pyboxfs,代码行数:8,代码来源:test_expose.py

示例8: snapshot

    def snapshot(self, path):
        """Takes a snapshot of an individual file."""

        # try grabbing the temp filesystem system path
        temp_dir = None
        temp_dir = self.tmp.getsyspath('/')

        # Create a temp file system to be snapshotted
        temp_snapshot_fs = TempFS(temp_dir=temp_dir)
        src_path = temp_snapshot_fs.getsyspath('/')

        with self.fs.open(path, 'rb') as source_file:
            with temp_snapshot_fs.open('datafile', 'wb') as temp_file:
                shutil.copyfileobj(source_file, temp_file)

        # snapshot destination directory
        dest_dir = self.snapshot_snap_path(path)

        command = ['rdiff-backup',
                   '--parsable-output',
                   '--no-eas',
                   '--no-file-statistics',
                   '--no-acls',
                   '--tempdir', self.tmp.getsyspath('/'),
                   src_path, dest_dir]

        # speed up the tests
        if self.__testing:
            command.insert(5, '--current-time')
            command.insert(6, str(self.__testing['time']))
            self.__testing['time'] += 1

        process = Popen(command, stdout=PIPE, stderr=PIPE)
        stderr = process.communicate()[1]

        ignore = [lambda x: x.startswith("Warning: could not determine case")]

        if len(stderr) is not 0:
            for rule in ignore:
                if not rule(stderr):
                    raise SnapshotError(stderr)

        # close the temp snapshot filesystem
        temp_snapshot_fs.close()
开发者ID:pombreda,项目名称:file-versioning,代码行数:44,代码来源:__init__.py

示例9: TestCacheFS

class TestCacheFS(unittest.TestCase,FSTestCases,ThreadingTestCases):
    """Test simple operation of CacheFS"""

    def setUp(self):
        self._check_interval = sys.getcheckinterval()
        sys.setcheckinterval(10)
        self.wrapped_fs = TempFS()
        self.fs = CacheFS(self.wrapped_fs,cache_timeout=0.01)

    def tearDown(self):
        self.fs.close()
        sys.setcheckinterval(self._check_interval)

    def test_values_are_used_from_cache(self):
        old_timeout = self.fs.cache_timeout
        self.fs.cache_timeout = None
        try:
            self.assertFalse(self.fs.isfile("hello"))
            self.wrapped_fs.setcontents("hello","world")
            self.assertTrue(self.fs.isfile("hello"))
            self.wrapped_fs.remove("hello")
            self.assertTrue(self.fs.isfile("hello"))
            self.fs.clear_cache()
            self.assertFalse(self.fs.isfile("hello"))
        finally:
            self.fs.cache_timeout = old_timeout

    def test_values_are_updated_in_cache(self):
        old_timeout = self.fs.cache_timeout
        self.fs.cache_timeout = None
        try:
            self.assertFalse(self.fs.isfile("hello"))
            self.wrapped_fs.setcontents("hello","world")
            self.assertTrue(self.fs.isfile("hello"))
            self.wrapped_fs.remove("hello")
            self.assertTrue(self.fs.isfile("hello"))
            self.wrapped_fs.setcontents("hello","world")
            self.assertTrue(self.fs.isfile("hello"))
            self.fs.remove("hello")
            self.assertFalse(self.fs.isfile("hello"))
        finally:
            self.fs.cache_timeout = old_timeout
开发者ID:offlinehacker,项目名称:pyfilesystem,代码行数:42,代码来源:test_remote.py

示例10: TestSuperMemoQAExport

class TestSuperMemoQAExport (TestCase):
    def setUp(self):
        TestCase.setUp(self)
        self.fs = TempFS()
        self.exporter = SuperMemoQAExporter(self.fs)
        self.exporter.index_file = 'out.txt'        
 
    def test_single_card(self):
        card = m.ContentObject()
        card['question'] = u'Question'
        card['answer'] = u'Answer'
        self.exporter([card])
        expected = "Q: Question\r\nA: Answer\r\n"
        assert_equals(expected, self.fs.getcontents('out.txt'))

    def test_multiple_cards(self):
        card = m.ContentObject()
        card['question'] = u'Question'
        card['answer'] = u'Answer'
        card2 = m.ContentObject()
        card2['question'] = u'Question 2'
        card2['answer'] = u'Answer 2'
        self.exporter([card, card2])
        expected = "Q: Question\r\nA: Answer\r\n\r\nQ: Question 2\r\nA: Answer 2\r\n"
        assert_equals(expected, self.fs.getcontents('out.txt'))
        
    def test_multiline_question_and_answer(self):
        card = m.ContentObject()
        card['question'] = u"Question\nend of question"
        card['answer'] = u"Answer\nend of answer"
        self.exporter([card])
        expected = "Q: Question\r\nQ: end of question\r\nA: Answer\r\nA: end of answer\r\n"
        assert_equals(expected, self.fs.getcontents('out.txt'))             

    def test_custom_encoding(self):
        card = m.ContentObject()
        card['question'] = u"chrząszcz brzmi w trzcinie"
        card['answer'] =  u"zażółć gęślą jaźń"
        self.exporter.encoding = 'cp1250'
        self.exporter([card])
        expected = u'Q: chrząszcz brzmi w trzcinie\r\nA: zażółć gęślą jaźń\r\n'.encode('cp1250')
        assert_equals(expected, self.fs.getcontents('out.txt'))              
开发者ID:rblinzler,项目名称:openmemo,代码行数:42,代码来源:test_sm_qa_export.py

示例11: setUp

 def setUp(self):
     TestCase.setUp(self)
     self.fs = TempFS()
     factory = m.ImportedInstanceFactory(self, field_types={    
         'question': 'html',
         'answer': 'html'                                    
     })      
     self.importer = SuperMemoQAImporter(self.fs, factory, m.HTMLMarkupImporter(self))
     self.cos = []
     self.images = []
     self.sounds = []
开发者ID:rblinzler,项目名称:openmemo,代码行数:11,代码来源:test_sm_qa_import.py

示例12: TestFUSE

class TestFUSE(unittest.TestCase,FSTestCases):

    def setUp(self):
        self.temp_fs = TempFS()
        self.temp_fs.makedir("root")
        self.temp_fs.makedir("mount")
        self.mounted_fs = self.temp_fs.opendir("root")
        self.mount_point = self.temp_fs.getsyspath("mount")
        self.fs = OSFS(self.temp_fs.getsyspath("mount"))
        self.mount_proc = fuse.mount(self.mounted_fs,self.mount_point)

    def tearDown(self):
        self.mount_proc.unmount()
        self.temp_fs.close()

    def check(self,p):
        return self.mounted_fs.exists(p)
开发者ID:svn2github,项目名称:pyfilesystem,代码行数:17,代码来源:test_expose.py

示例13: setUp

 def setUp(self):
     self._check_interval = sys.getcheckinterval()
     sys.setcheckinterval(10)
     self.wrapped_fs = TempFS()
     self.fs = CacheFS(self.wrapped_fs,cache_timeout=0.01)
开发者ID:offlinehacker,项目名称:pyfilesystem,代码行数:5,代码来源:test_remote.py

示例14: wrap_error

                    #write(wrap_prefix(prefix[:-1] + '       ') + wrap_error('max recursion levels reached'))
                else:
                    print_dir(fs, pathjoin(path, item), levels[:] + [is_last_item])
            else:
                write('%s %s' % (wrap_prefix(prefix + char_line), wrap_filename(item)))

        return len(dir_listing)

    print_dir(fs, path)
    return dircount[0], filecount[0]


if __name__ == "__main__":
    from fs.tempfs import TempFS
    from six import b
    t1 = TempFS()
    t1.setcontents("foo", b("test"))
    t1.makedir("bar")
    t1.setcontents("bar/baz", b("another test"))

    t1.tree()

    t2 = TempFS()
    print t2.listdir()
    movedir(t1, t2)

    print t2.listdir()
    t1.tree()
    t2.tree()

开发者ID:ctismer,项目名称:pyfilesystem,代码行数:29,代码来源:utils.py

示例15: TestSuperMemoQAImport

class TestSuperMemoQAImport (TestCase):

    def setUp(self):
        TestCase.setUp(self)
        self.fs = TempFS()
        factory = m.ImportedInstanceFactory(self, field_types={    
            'question': 'html',
            'answer': 'html'                                    
        })      
        self.importer = SuperMemoQAImporter(self.fs, factory, m.HTMLMarkupImporter(self))
        self.cos = []
        self.images = []
        self.sounds = []
 
    def test_single_card(self):
        data = u"Q: question 1\nA: answer 1"
        self.fs.setcontents('cards.txt', data)
        self.importer()
        assert_equals(1, len(self.cos))
        assert_equals(unicode, type(self.cos[0]['question']))
        assert_equals(unicode, type(self.cos[0]['answer']))        
        assert_equals(u"question 1", self.cos[0]['question'])
        assert_equals(u"answer 1", self.cos[0]['answer'])
        
    def test_windows_line_endings(self):
        data = u"Q: question 1\r\nA: answer 1"
        self.fs.setcontents('cards.txt', data)
        self.importer()
        assert_equals(1, len(self.cos))
        assert_equals(u"question 1", self.cos[0]['question'])
        assert_equals(u"answer 1", self.cos[0]['answer'])
        
    def test_multiple_cards(self):
        data = """Q: question
A: answer

Q: question 2
A: answer 2"""
        self.fs.setcontents('cards.txt', data)
        self.importer()
        assert_equals(2, len(self.cos))
        assert_equals(u"question", self.cos[0]['question'])
        assert_equals(u"answer", self.cos[0]['answer'])
        assert_equals(u"question 2", self.cos[1]['question'])
        assert_equals(u"answer 2", self.cos[1]['answer'])
        
    def test_content_is_right_trimmed(self):
        data = u"Q: question   \nA: answer   \n"
        self.fs.setcontents('cards.txt', data)
        self.importer()
        assert_equals(1, len(self.cos))
        assert_equals(u"question", self.cos[0]['question'])
        assert_equals(u"answer", self.cos[0]['answer'])            
 
    def test_multiline_question_and_answer(self):
        data = """Q: question
Q: end of question
A: answer
A: end of answer"""
        self.fs.setcontents('cards.txt', data)
        self.importer()
        assert_equals(1, len(self.cos))
        assert_equals(u"question\nend of question", self.cos[0]['question'])
        assert_equals(u"answer\nend of answer", self.cos[0]['answer'])            
        
    def test_multiline_question_and_answer_lines_are_rtrimmed(self):
        data = "Q: question  \nQ: end of question  \nA: answer  \nA: end of answer  "
        self.fs.setcontents('cards.txt', data)
        self.importer()
        assert_equals(1, len(self.cos))
        assert_equals(u"question\nend of question", self.cos[0]['question'])
        assert_equals(u"answer\nend of answer", self.cos[0]['answer'])            
 
    def test_custom_encoding(self):
        data = (u"Q: być szczerym\nA: to be frank").encode('cp1250')
        self.fs.setcontents('cards.txt', data)
        self.importer.encoding = 'cp1250'
        self.importer()        
        assert_equals(1, len(self.cos))
        assert_equals(unicode, type(self.cos[0]['question']))
        assert_equals(unicode, type(self.cos[0]['answer']))
        assert_equals(u"być szczerym", self.cos[0]['question'])
        assert_equals(u"to be frank", self.cos[0]['answer']) 
               
    def test_html_tags_are_preserved(self):
        data = """Q: hist: When did we <b>land on the moon</b>?
A: 1969 <i>(July 20)</i>"""
        self.fs.setcontents('cards.txt', data)
        self.importer()
        assert_equals(u"hist: When did we <b>land on the moon</b>?", self.cos[0]['question'])
        assert_equals(u"1969 <i>(July 20)</i>", self.cos[0]['answer'])
        
    def test_card_with_image(self):
        data = u"""Q: <img src="image.jpg" />
A: answer"""
        self.fs.setcontents('index.txt', data)
        image_data = self.data.getcontents('small.jpg')
        self.fs.setcontents('image.jpg', image_data)
        self.importer()

#.........这里部分代码省略.........
开发者ID:rblinzler,项目名称:openmemo,代码行数:101,代码来源:test_sm_qa_import.py


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