How to use Send2Trash - 10 common examples

To help you get started, we’ve selected a few Send2Trash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github onicagroup / runway / integration_tests / test_parallelism / test_parallelism.py View on Github external
def clean(self):
        """Clean up fixture test directory."""
        file_types = ('*.yaml', '*.yml')
        templates = []
        for file_type in file_types:
            templates.extend(glob.glob(os.path.join(
                self.parallelism_test_dir,
                file_type
            )))
        for template in templates:
            if os.path.isfile(template):
                self.logger.debug('send2trash: "%s"', template)
                send2trash(template)
        folders = ['sampleapp.cfn']
        for folder in folders:
            folder_path = os.path.join(self.parallelism_test_dir, folder)
            if os.path.isdir(folder_path):
                self.logger.debug('send2trash: "%s"', folder_path)
                send2trash(folder_path)
github hsoft / send2trash / tests / test_plat_other.py View on Github external
def test_trash(self):
        s2t(op.join(self.slDir, self.fileName))
        self.assertFalse(op.exists(self.filePath))
        self.assertTrue(op.exists(op.join(self.trashTopdir, '.Trash-' + str(os.getuid()), 'files', self.fileName)))
github hsoft / send2trash / tests / test_plat_other.py View on Github external
def test_trash_bytes(self):
        s2t(self.file)
        assert not op.exists(self.file)
github hsoft / send2trash / tests / test_plat_other.py View on Github external
def test_trash_unicode(self):
        s2t(self.file.decode(sys.getfilesystemencoding()))
        assert not op.exists(self.file)
github hsoft / send2trash / tests / test_plat_other.py View on Github external
def test_trash(self):
        s2t(self.filePath)
        self.assertFalse(op.exists(self.filePath))
        self.assertTrue(op.exists(op.join(self.trashDir, str(os.getuid()), 'files', self.fileName)))
        self.assertTrue(op.exists(op.join(self.trashDir, str(os.getuid()), 'info', self.fileName + '.trashinfo')))
        # info relative path (if another test is added, with the same fileName/Path,
        # then it gets renamed etc.)
        cfg = ConfigParser()
        cfg.read(op.join(self.trashDir, str(os.getuid()), 'info', self.fileName + '.trashinfo'))
        self.assertEqual(self.fileName, cfg.get('Trash Info', 'Path', raw=True))
github hsoft / send2trash / tests / test_plat_other.py View on Github external
def test_trash(self):
        s2t(self.file.name)
        self.assertFalse(op.exists(self.file.name))
github hsoft / send2trash / tests / test_plat_other.py View on Github external
self.old_ismount = old_ismount = op.ismount
        self.old_getdev = send2trash.plat_other.get_dev
        def s_getdev(path):
            from send2trash.plat_other import is_parent
            st = os.lstat(path)
            if is_parent(self.trashTopdir, path):
                return 'dev'
            return st.st_dev
        def s_ismount(path):
            if op.realpath(path) in (op.realpath(self.trashTopdir), op.realpath(trashTopdir_b)):
                return True
            return old_ismount(path)

        send2trash.plat_other.os.path.ismount = s_ismount
        send2trash.plat_other.get_dev = s_getdev
github hsoft / send2trash / tests / test_plat_other.py View on Github external
from os import path as op
import send2trash.plat_other
from send2trash.plat_other import send2trash as s2t
from send2trash.compat import PY3
try:
    from configparser import ConfigParser
except ImportError:
    # py2
    from ConfigParser import ConfigParser
from tempfile import mkdtemp, NamedTemporaryFile, mktemp
import shutil
import stat
import sys
# Could still use cleaning up. But no longer relies on ramfs.

HOMETRASH = send2trash.plat_other.HOMETRASH

def touch(path):
    with open(path, 'a'):
        os.utime(path, None)

class TestHomeTrash(unittest.TestCase):
    def setUp(self):
        self.file = NamedTemporaryFile(
            dir=op.expanduser("~"), prefix='send2trash_test', delete=False)

    def test_trash(self):
        s2t(self.file.name)
        self.assertFalse(op.exists(self.file.name))

    def tearDown(self):
        name = op.basename(self.file.name)
github hsoft / send2trash / tests / test_plat_other.py View on Github external
touch(self.filePath)

        self.old_ismount = old_ismount = op.ismount
        self.old_getdev = send2trash.plat_other.get_dev
        def s_getdev(path):
            from send2trash.plat_other import is_parent
            st = os.lstat(path)
            if is_parent(self.trashTopdir, path):
                return 'dev'
            return st.st_dev
        def s_ismount(path):
            if op.realpath(path) in (op.realpath(self.trashTopdir), op.realpath(trashTopdir_b)):
                return True
            return old_ismount(path)

        send2trash.plat_other.os.path.ismount = s_ismount
        send2trash.plat_other.get_dev = s_getdev
github hsoft / send2trash / tests / test_plat_other.py View on Github external
def setUp(self):
        self.trashTopdir = mkdtemp(prefix='s2t')
        if PY3:
            trashTopdir_b = os.fsencode(self.trashTopdir)
        else:
            trashTopdir_b = self.trashTopdir
        self.fileName = 'test.txt'
        self.filePath = op.join(self.trashTopdir, self.fileName)
        touch(self.filePath)

        self.old_ismount = old_ismount = op.ismount
        self.old_getdev = send2trash.plat_other.get_dev
        def s_getdev(path):
            from send2trash.plat_other import is_parent
            st = os.lstat(path)
            if is_parent(self.trashTopdir, path):
                return 'dev'
            return st.st_dev
        def s_ismount(path):
            if op.realpath(path) in (op.realpath(self.trashTopdir), op.realpath(trashTopdir_b)):
                return True
            return old_ismount(path)

        send2trash.plat_other.os.path.ismount = s_ismount
        send2trash.plat_other.get_dev = s_getdev