+remove method of file, test for file
This commit is contained in:
parent
911e2dad2d
commit
cc8d65f76a
@ -23,3 +23,9 @@ 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))
|
||||
|
||||
def remove(self):
|
||||
''' try to remove the file '''
|
||||
try:
|
||||
os.remove(self._path)
|
||||
except FileNotFoundError: pass
|
9
tests/file.py
Normal file
9
tests/file.py
Normal 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
|
Loading…
x
Reference in New Issue
Block a user