예제 #1
0
 def test_calc_original_location_when_absolute(self) :
     instance = TrashDirectory(
         Path("/mnt/disk/.Trash-123"),
         Volume(Path("/mnt/disk"), True))
     
     assert_equals(Path("/foo"),
                   instance._calc_original_location(Path("/foo")))
예제 #2
0
class TestTrashDirectory_persit_trash_info(TestCase) :
    def setUp(self):
        self.trashdirectory_base_dir = Path(os.path.realpath("./sandbox/testTrashDirectory"))
        self.trashdirectory_base_dir.remove()
        
        self.instance=TrashDirectory(self.trashdirectory_base_dir, Volume(Path("/")))
        
    def test_persist_trash_info_first_time(self):
        trash_info=TrashInfo(Path("dummy-path"), datetime(2007,01,01))

        basename=trash_info.path.basename
        content=trash_info.render()
        (trash_info_file,
                trash_info_id)=self.instance.persist_trash_info(basename,content)

        self.assertTrue(isinstance(trash_info_file, Path))
        self.assertEquals('dummy-path', trash_info_id)
        self.assertEquals(self.trashdirectory_base_dir.join('info').join('dummy-path.trashinfo').path, trash_info_file)

        self.assertEquals("""[Trash Info]
Path=dummy-path
DeletionDate=2007-01-01T00:00:00
""", trash_info_file.read())
        
    def test_persist_trash_info_first_100_times(self):
        self.test_persist_trash_info_first_time()
        
        for i in range(1,100) :
            trash_info=TrashInfo(Path("dummy-path"), datetime(2007,01,01))
            
            basename=trash_info.path.basename
            content=trash_info.render()
            (trash_info_file,
                    trash_info_id)=self.instance.persist_trash_info(basename,content)
    
            self.assertTrue(isinstance(trash_info_id, str))
            self.assertEquals('dummy-path'+"_" + str(i), trash_info_id)
            self.assertEquals("""[Trash Info]
Path=dummy-path
DeletionDate=2007-01-01T00:00:00
""", trash_info_file.read())

    def test_persist_trash_info_other_times(self):
        self.test_persist_trash_info_first_100_times()
        
        for i in range(101,200) :
            trash_info=TrashInfo(Path("dummy-path"), datetime(2007,01,01))
            
            basename=trash_info.path.basename
            content=trash_info.render()
            (trash_info_file,
                    trash_info_id)=self.instance.persist_trash_info(basename,content)
    
            self.assertTrue(isinstance(trash_info_id, str))
            self.assertTrue(trash_info_id.startswith("dummy-path_"))
            self.assertEquals("""[Trash Info]
Path=dummy-path
DeletionDate=2007-01-01T00:00:00
""", trash_info_file.read())
예제 #3
0
파일: test_persist.py 프로젝트: ahua/python
class TestTrashDirectory_persit_trash_info(TestCase) :
    def setUp(self):
        self.trashdirectory_base_dir = os.path.realpath("./sandbox/testTrashDirectory")
        require_empty_dir(self.trashdirectory_base_dir)
        
        self.instance=TrashDirectory(self.trashdirectory_base_dir, "/")
        
    def test_persist_trash_info_first_time(self):
        trash_info=TrashInfo("dummy-path", datetime(2007,01,01))

        basename=os.path.basename(trash_info.path)
        content=trash_info.render()
        (trash_info_file,
                trash_info_id)=self.instance.persist_trash_info(basename,content)

        self.assertEquals('dummy-path', trash_info_id)
        self.assertEquals(join(self.trashdirectory_base_dir,'info', 'dummy-path.trashinfo'), trash_info_file)

        self.assertEquals("[Trash Info]\n"
                          "Path=dummy-path\n"
                          "DeletionDate=2007-01-01T00:00:00\n", 
                          read(trash_info_file))

    def test_persist_trash_info_first_100_times(self):
        self.test_persist_trash_info_first_time()
        
        for i in range(1,100) :
            trash_info=TrashInfo("dummy-path", datetime(2007,01,01))
            
            basename=os.path.basename(trash_info.path)
            content=trash_info.render()
            (trash_info_file,
                    trash_info_id)=self.instance.persist_trash_info(basename,content)
    
            self.assertEquals('dummy-path'+"_" + str(i), trash_info_id)
            self.assertEquals("""[Trash Info]
Path=dummy-path
DeletionDate=2007-01-01T00:00:00
""", read(trash_info_file))

    def test_persist_trash_info_other_times(self):
        self.test_persist_trash_info_first_100_times()
        
        for i in range(101,200) :
            trash_info=TrashInfo("dummy-path", datetime(2007,01,01))
            
            basename=os.path.basename(trash_info.path)
            content=trash_info.render()
            (trash_info_file,
                    trash_info_id)=self.instance.persist_trash_info(basename,content)
    
            self.assertTrue(trash_info_id.startswith("dummy-path_"))
            self.assertEquals("""[Trash Info]
Path=dummy-path
DeletionDate=2007-01-01T00:00:00
""", read(trash_info_file))
예제 #4
0
class TestWhenListingTrashinfo:
    def setUp(self):
        require_empty_dir('sandbox')
        self.trash_dir = TrashDirectory('sandbox', '/')
        self.logger = Mock()
        self.trash_dir.logger = self.logger

    def test_should_list_a_trashinfo(self):
        write_file('sandbox/info/foo.trashinfo')

        result = self.list_trashinfos()

        assert_equals(['sandbox/info/foo.trashinfo'], result)

    def test_should_list_multiple_trashinfo(self):
        write_file('sandbox/info/foo.trashinfo')
        write_file('sandbox/info/bar.trashinfo')
        write_file('sandbox/info/baz.trashinfo')

        result = self.list_trashinfos()

        assert_items_equal([
            'sandbox/info/foo.trashinfo', 'sandbox/info/baz.trashinfo',
            'sandbox/info/bar.trashinfo'
        ], result)

    def test_should_ignore_non_trashinfo(self):
        write_file('sandbox/info/not-a-trashinfo')

        result = self.list_trashinfos()

        assert_equals([], result)

    def test_non_trashinfo_should_reported_as_a_warn(self):
        write_file('sandbox/info/not-a-trashinfo')

        self.list_trashinfos()

        self.logger.warning.assert_called_with(
            'Non .trashinfo file in info dir')

    def list_trashinfos(self):
        return list(self.trash_dir.all_info_files())
class TestWhenListingTrashinfo:
    def setUp(self):
        require_empty_dir('sandbox')
        self.trash_dir = TrashDirectory('sandbox', '/')
        self.logger = Mock()
        self.trash_dir.logger = self.logger


    def test_should_list_a_trashinfo(self):
        write_file('sandbox/info/foo.trashinfo')

        result = self.list_trashinfos()

        assert_equals(['sandbox/info/foo.trashinfo'], result)

    def test_should_list_multiple_trashinfo(self):
        write_file('sandbox/info/foo.trashinfo')
        write_file('sandbox/info/bar.trashinfo')
        write_file('sandbox/info/baz.trashinfo')

        result = self.list_trashinfos()

        assert_items_equal(['sandbox/info/foo.trashinfo',
                            'sandbox/info/baz.trashinfo',
                            'sandbox/info/bar.trashinfo'], result)

    def test_should_ignore_non_trashinfo(self):
        write_file('sandbox/info/not-a-trashinfo')

        result = self.list_trashinfos()

        assert_equals([], result)

    def test_non_trashinfo_should_reported_as_a_warn(self):
        write_file('sandbox/info/not-a-trashinfo')

        self.list_trashinfos()

        self.logger.warning.assert_called_with('Non .trashinfo file in info dir')

    def list_trashinfos(self):
        return list(self.trash_dir.all_info_files())
예제 #6
0
파일: test_persist.py 프로젝트: ahua/python
 def setUp(self):
     self.trashdirectory_base_dir = os.path.realpath("./sandbox/testTrashDirectory")
     require_empty_dir(self.trashdirectory_base_dir)
     
     self.instance=TrashDirectory(self.trashdirectory_base_dir, "/")
 def setUp(self):
     require_empty_dir('sandbox')
     self.trash_dir = TrashDirectory('sandbox', '/')
     self.logger = Mock()
     self.trash_dir.logger = self.logger
예제 #8
0
파일: test_trash.py 프로젝트: ahua/python
 def test_calc_original_location_when_relative(self) :
     instance = TrashDirectory( "/mnt/disk/.Trash-123", "/mnt/disk")
     
     assert_equals("/mnt/disk/foo", instance._calc_original_location("foo"))
예제 #9
0
파일: test_trash.py 프로젝트: ahua/python
 def test_calc_original_location_when_absolute(self) :
     instance = TrashDirectory( "/mnt/disk/.Trash-123", volume_of("/mnt/disk"))
     
     assert_equals("/foo", instance._calc_original_location("/foo"))
예제 #10
0
파일: test_trash.py 프로젝트: ahua/python
 def test_calc_id(self):
     trash_info_file = "/home/user/.local/share/Trash/info/foo.trashinfo"
     self.assertEquals('foo',TrashDirectory.calc_id(trash_info_file))
예제 #11
0
 def test_path(self):
     trash_dir = TrashDirectory('/Trash-501', '/')
     assert_equals('/Trash-501', trash_dir.path)
예제 #12
0
 def setUp(self):
     require_empty_dir('sandbox')
     self.trash_dir = TrashDirectory('sandbox', '/')
     self.logger = Mock()
     self.trash_dir.logger = self.logger
예제 #13
0
 def setUp(self):
     self.trashdirectory_base_dir = Path(os.path.realpath("./sandbox/testTrashDirectory"))
     self.trashdirectory_base_dir.remove()
     
     self.instance=TrashDirectory(self.trashdirectory_base_dir, Volume(Path("/")))
 def setUp(self):
     require_empty_dir("sandbox")
     self.trash_dir = TrashDirectory("sandbox", "/")
     self.logger = Mock()
     self.trash_dir.logger = self.logger