+remove method of file, test for file

This commit is contained in:
chidea 2015-03-22 01:09:25 +09:00
parent 911e2dad2d
commit cc8d65f76a
2 changed files with 16 additions and 1 deletions

View File

@ -22,4 +22,10 @@ class File():
def open(self):
'''tries to open with os default viewer'''
call(('cmd /c start "" "'+ self._path +'"')if os.name is 'nt' else ('open' if platform.startswith('darwin') else 'xdg-open', self._path))
call(('cmd /c start "" "'+ self._path +'"')if os.name is 'nt' else ('open' if platform.startswith('darwin') else 'xdg-open', self._path))
def remove(self):
''' try to remove the file '''
try:
os.remove(self._path)
except FileNotFoundError: pass

9
tests/file.py Normal file
View File

@ -0,0 +1,9 @@
from classes.file import File
from os.path import exists
f = File('text.txt')
assert f.write_bytes(b'testing bytes i/o')
assert f.read_bytes(), b'testing bytes i/o'
f.open() # does it open any text editor on your system?
f.remove()
assert exists('text.txt'), False