Exemple #1
0
 def test_directory(self):
     d1 = MutableFile("mf_test/")
     self.assertEqual(os.path.exists(d1.get_name()), False)
     d1.touch()
     self.assertEqual(d1.exists(), True)
     self.assertEqual(os.path.exists(d1.get_name()), True)
     d1.rm()
     self.assertEqual(os.path.exists(d1.get_name()), False)
Exemple #2
0
 def test_file(self):
     f1 = MutableFile("file_1.root")
     self.assertEqual(os.path.exists(f1.get_name()), False)
     f1.touch()
     self.assertEqual(f1.exists(), True)
     self.assertEqual(os.path.exists(f1.get_name()), True)
     f1.rm()
     self.assertEqual(os.path.exists(f1.get_name()), False)
Exemple #3
0
from metis.File import MutableFile
"""
Showcases some file operations normally done using the os
module, but nicely wrapped in the MutableFile object
"""
if __name__ == "__main__":

    # Make a mutable file object
    fo = MutableFile("mutablefile_test.txt")

    # Touch the file to guarantee its existence
    fo.touch()

    # Does it exist? Hint: yes
    print("File exists?", fo.exists())

    # What are the current permissions?
    print("Permissions =", fo.chmod())

    # Add some text to it
    fo.append("test text\n")
    fo.append("more text")

    # And cat it out
    print("---- Begin contents --->")
    print(fo.cat())
    print("<--- End contents ----")

    # Clean up by removing the file
    fo.rm()