Пример #1
0
 def test_cat(self):
     f1 = MutableFile("file_2.txt")
     f1.touch()
     f1.append("123\n")
     f1.append("123\n")
     self.assertEqual(f1.cat(), "123\n123\n")
     f1.rm()
Пример #2
0
 def test_append(self):
     f1 = MutableFile("file_2.txt")
     f1.touch()
     f1.append("123\n")
     with open(f1.get_name(), "r") as fhin:
         self.assertEqual(fhin.read(), "123\n")
     f1.rm()
Пример #3
0
 def test_chmod(self):
     f1 = MutableFile("chmodtest.txt")
     f1.touch()
     f1.chmod(644)
     self.assertEqual(f1.chmod(), 644)
     f1.chmod("u+x")
     self.assertEqual(f1.chmod(), 744)
     f1.rm()
Пример #4
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)
Пример #5
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)
Пример #6
0
    def test_textfile(self):
        dsname = "/blah/blah/BLAH/"
        fname = "tfsampletest.tmp"

        # make a temporary file putting in some dummy filenames
        # to be picked up by FilelistSample
        mf = MutableFile(fname)
        mf.touch()
        nfiles = 3
        for i in range(1, nfiles + 1):
            mf.append("ntuple{}.root\n".format(i))
        tfsamp = FilelistSample(dataset=dsname, filelist=fname)
        self.assertEqual(len(tfsamp.get_files()), nfiles)

        # clean up
        mf.rm()
Пример #7
0
from __future__ import print_function

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