def test10_creation(self): file = vfs.make_file(self.root + 'testfile.txt') file.write("one\n") file.close() self.assertEqual(vfs.is_file(self.root + 'testfile.txt'), True) url = self.root + 'tmp/dir' vfs.make_folder(url) self.assertEqual(vfs.is_folder(url), True) url = self.root + 'tmp/dir/file1' fh = vfs.make_file(url) fh.write("this is file1") fh.close() self.assertEqual(vfs.is_file(url), True) url = self.root + 'tmp/dir/zero' fh = vfs.make_file(url) fh.close() self.assertEqual(vfs.is_file(url), True) # this should raise an OSError because it's trying to make a file out # of an existing folder url = self.root + 'tmp/dir' self.assertRaises(OSError, vfs.make_file, url) # this should raise an OSError because it's trying to make a file in # another file url = self.root + 'tmp/dir/file1/file2' self.assertRaises(OSError, vfs.make_file, url)
def test14_remove_folder(self): # Create hierarchy vfs.make_folder('vfs/folder') vfs.make_folder('vfs/folder/a') vfs.make_file('vfs/folder/a/hello.txt') # Remove and test vfs.remove('vfs/folder') self.assertEqual(vfs.exists('vfs/folder'), False)
def test29_remove(self): url = 'mem:testfile.txt.old' vfs.remove(url) self.assertEqual(vfs.exists(url), False) url = 'mem:test/dir' vfs.make_folder(url) vfs.remove(url) self.assertEqual(vfs.exists(url), False) # Create hierarchy vfs.make_folder('mem:tests/folder') vfs.make_folder('mem:tests/folder/a') vfs.make_file('mem:tests/folder/a/hello.txt') # Remove and test vfs.remove('mem:tests/folder') self.assertEqual(vfs.exists('mem:tests/folder'), False)
def setUp(self): if vfs.exists(self.root + 'tmp'): vfs.remove(self.root + 'tmp') vfs.make_folder(self.root + 'tmp') file = vfs.make_file(self.root + 'tmp/blah.txt') file.write("BLAH!!!") file.close()
def test20_append(self): # Initialize with vfs.make_file('vfs/toto.txt') as file: file.write('hello\n') # Test with vfs.open('vfs/toto.txt', vfs.APPEND) as file: file.write('bye\n') self.assertEqual(open('vfs/toto.txt').read(), 'hello\nbye\n') # Remove temporary file vfs.remove('vfs/toto.txt')
def test21_write(self): # Initialize with vfs.make_file('vfs/truncate.txt') as file: file.write('hello there\n') # Test with vfs.open('vfs/truncate.txt', vfs.WRITE) as file: file.write('bye\n') self.assertEqual(open('vfs/truncate.txt').read(), 'bye\n') # Remove temporary file vfs.remove('vfs/truncate.txt')
def test13_folder_creation(self): url = 'mem:testfile.txt/dir' self.assertEqual(vfs.is_folder(url), False) self.assertRaises(OSError, vfs.make_folder, url) # This should raise an OSError because we're trying to make a file # inside another file file = vfs.make_file('mem:blah1') file.write("blah1\n") file.close() self.assertRaises(OSError, vfs.make_folder, 'mem:blah1/bad1') # This should raise OSError because we're trying to make a file with # the same name as an existing folder url = 'mem:blah2/file2' file = vfs.make_file(url) file.write("blah2\n") file.close() self.assertEqual(True, vfs.exists(url)) self.assertRaises(OSError, vfs.make_file, 'mem:blah2')
def test00_get(self): filename = 'vfs/perms.txt' with vfs.make_file(filename) as file: file.write('test\n') perms = vfs.get_permissions(filename) self.assert_(perms.is_mode_set('user', 'read')) perms.set_mode('user', 'execute', True) vfs.set_permissions(filename, perms) perms = vfs.get_permissions(filename) self.assert_(perms.is_mode_set('user', 'execute')) vfs.remove(filename)
def createErrorBuffer(cls, url, error): cls.error_buffer_count += 1 errurl = "mem:error-%d.txt" % cls.error_buffer_count fh = vfs.make_file(errurl) fh.write(u"Failed opening %s.\n\nDetailed error message follows:\n\n" % url) fh.write(error) fh.close() buffer = Buffer(errurl) buffer.openGUIThreadStart() buffer.openBackgroundThread() buffer.openGUIThreadSuccess() return buffer
def save(self, filename=None): if filename: url = vfs.normalize(filename) if vfs.is_file(url): fh = vfs.open(url, vfs.WRITE) else: fh = vfs.make_file(url) if fh: fh.write(str(self)) fh.close() else: eprint("Couldn't open %s for writing.\n" % filename)
def save(self,filename=None): if filename: url = vfs.normalize(filename) if vfs.is_file(url): fh = vfs.open(url, vfs.WRITE) else: fh = vfs.make_file(url) if fh: fh.write(str(self)) fh.close() else: eprint("Couldn't open %s for writing.\n" % filename)
def action(self, index=-1, multiplier=1): stylesheet = wx.GetApp().fonts.getStyleFile() dlg = PeppyStyleEditor(self.frame, -1) self.setSampleText(dlg) retval = dlg.ShowModal() if retval == wx.ID_OK: # Find style name from controls within the dialog ctrl = dlg.FindWindowById(style_editor.ed_glob.ID_PREF_SYNTHEME) tag = ctrl.GetStringSelection() ctrl = dlg.FindWindowById(wx.ID_NEW) if ctrl.GetValue(): tag = "untitled" dlg2 = wx.TextEntryDialog( self.frame, caption="Save Style Sheet", message= "Enter name for style sheet.\n\nThis style sheet must be saved in your personal\nconfiguration directory before it can be used.\n\nIf you cancel, the style sheet changes will be lost.", defaultValue=tag, style=wx.OK | wx.CANCEL) retval = dlg2.ShowModal() tag = dlg2.GetValue() if not tag: tag = "untitled" dlg2.Destroy() if retval == wx.ID_OK: #dprint("Saving style to %s" % tag) filename = wx.GetApp().fonts.getStylePath(tag) styles = ed_style.MergeStyles( dlg.preview.BlankStyleDictionary(), dlg.styles_new) dlg.preview.SetStyles(filename, styles, True) EditraSTCMixin.global_style_set = filename sheet = dlg.GenerateStyleSheet() #dprint(sheet) fh = open(filename, 'wb') fh.write(sheet) wx.GetApp().fonts.classprefs.editra_style_theme = tag Publisher().sendMessage('peppy.preferences.changed') elif retval == wx.ID_SAVE: dprint("Save!") sheet = dlg.GenerateStyleSheet() dprint(sheet) self.export_count += 1 url = "mem:///style-sheet-%d.ess" % self.export_count fh = vfs.make_file(url) fh.write(sheet) fh.close() fh = vfs.open(url) dprint(fh.read()) self.frame.open(url) dlg.Destroy()
def test13_folder_creation(self): file = vfs.make_file(self.root + 'testfile.txt') file.write("one\n") file.close() url = self.root + 'testfile.txt/dir' self.assertRaises(OSError, vfs.make_folder, url) # This should raise an OSError because we're trying to make a file # inside another file file = vfs.make_file(self.root + 'tmp/blah1') file.write("blah1\n") file.close() self.assertRaises(OSError, vfs.make_folder, self.root + 'tmp/blah1/bad1') # This should raise OSError because we're trying to make a file with # the same name as an existing folder url = self.root + 'tmp/blah2' file = vfs.make_file(url) file.write("blah2\n") file.close() self.assertEqual(True, vfs.exists(url)) self.assertRaises(OSError, vfs.make_file, self.root + 'tmp/blah2')
def test12_append(self): file = vfs.make_file(self.root + 'testfile.txt') file.write("one\n") file.close() file = vfs.open(self.root + 'testfile.txt', vfs.APPEND) file.write("two\n") file.close() file = vfs.open(self.root + 'testfile.txt') self.assertEqual(file.read(), 'one\ntwo\n') file = vfs.open(self.root + 'testfile.txt', vfs.WRITE) file.write("three\n") file.close() file = vfs.open(self.root + 'testfile.txt') self.assertEqual(file.read(), 'three\n')
def action(self, index=-1, multiplier=1): stylesheet = wx.GetApp().fonts.getStyleFile() dlg = PeppyStyleEditor(self.frame, -1) self.setSampleText(dlg) retval = dlg.ShowModal() if retval == wx.ID_OK: # Find style name from controls within the dialog ctrl = dlg.FindWindowById(style_editor.ed_glob.ID_PREF_SYNTHEME) tag = ctrl.GetStringSelection() ctrl = dlg.FindWindowById(wx.ID_NEW) if ctrl.GetValue(): tag = "untitled" dlg2 = wx.TextEntryDialog( self.frame, caption="Save Style Sheet", message="Enter name for style sheet.\n\nThis style sheet must be saved in your personal\nconfiguration directory before it can be used.\n\nIf you cancel, the style sheet changes will be lost.", defaultValue=tag, style=wx.OK|wx.CANCEL) retval = dlg2.ShowModal() tag = dlg2.GetValue() if not tag: tag = "untitled" dlg2.Destroy() if retval == wx.ID_OK: #dprint("Saving style to %s" % tag) filename = wx.GetApp().fonts.getStylePath(tag) styles = ed_style.MergeStyles(dlg.preview.BlankStyleDictionary(), dlg.styles_new) dlg.preview.SetStyles(filename, styles, True) EditraSTCMixin.global_style_set = filename sheet = dlg.GenerateStyleSheet() #dprint(sheet) fh = open(filename, 'wb') fh.write(sheet) wx.GetApp().fonts.classprefs.editra_style_theme = tag Publisher().sendMessage('peppy.preferences.changed') elif retval == wx.ID_SAVE: dprint("Save!") sheet = dlg.GenerateStyleSheet() dprint(sheet) self.export_count += 1 url = "mem:///style-sheet-%d.ess" % self.export_count fh = vfs.make_file(url) fh.write(sheet) fh.close() fh = vfs.open(url) dprint(fh.read()) self.frame.open(url) dlg.Destroy()
def test29_remove(self): url = self.root + 'tmp/dir' vfs.make_folder(url) vfs.remove(url) self.assertEqual(vfs.exists(url), False) # Create hierarchy vfs.make_folder(self.root + 'tmp3') vfs.exists(self.root + 'tmp3') vfs.make_folder(self.root + 'tmp3/folder') vfs.exists(self.root + 'tmp3/folder') vfs.make_folder(self.root + 'tmp3/folder/a') vfs.exists(self.root + 'tmp3/folder/a') fh = vfs.make_file(self.root + 'tmp3/folder/a/hello.txt') fh.write("blah") fh.close() vfs.exists(self.root + 'tmp3/folder/a/hello.txt') # Remove and test vfs.remove(self.root + 'tmp3/folder') self.assertEqual(vfs.exists(self.root + 'tmp3/folder'), False)
def test_simple(self): vfs.make_folder(self.root + 'tmp') file = vfs.make_file(self.root + 'tmp/blah.txt') file.write("BLAH!!!") file.close() # Probably too loose of a test, but the modification time has a 10 # second window for correctness mtime = vfs.get_mtime(self.root + 'tmp/blah.txt') current = datetime.now() assert abs(mtime - current) < timedelta(10) file = vfs.open(self.root + 'tmp/blah.txt') self.assertEqual(file.read(), 'BLAH!!!') assert vfs.exists(self.root + 'tmp') names = vfs.get_names(self.root) assert "tmp" in names names = vfs.get_names(self.root + 'tmp') assert "blah.txt" in names vfs.remove(self.root + 'tmp') assert not vfs.exists(self.root + 'tmp') assert not vfs.exists(self.root + 'tmp/blah.txt')
def test_simple(self): vfs.make_folder(self.root + "tmp") file = vfs.make_file(self.root + "tmp/blah.txt") file.write("BLAH!!!") file.close() # Probably too loose of a test, but the modification time has a 10 # second window for correctness mtime = vfs.get_mtime(self.root + "tmp/blah.txt") current = datetime.now() assert abs(mtime - current) < timedelta(10) file = vfs.open(self.root + "tmp/blah.txt") self.assertEqual(file.read(), "BLAH!!!") assert vfs.exists(self.root + "tmp") names = vfs.get_names(self.root) assert "tmp" in names names = vfs.get_names(self.root + "tmp") assert "blah.txt" in names vfs.remove(self.root + "tmp") assert not vfs.exists(self.root + "tmp") assert not vfs.exists(self.root + "tmp/blah.txt")
def test11_reading(self): file = vfs.make_file(self.root + 'testfile.txt') file.write("one\n") file.close() file = vfs.open(self.root + 'testfile.txt') self.assertEqual(file.read(), 'one\n')
def test06_make_file(self): vfs.make_file('vfs/file') self.assertEqual(vfs.is_file('vfs/file'), True)
def setUp(self): vfs.make_folder('mem:tmp') file = vfs.make_file('mem:tmp/blah.txt') file.write("BLAH!!!") file.close()