File: test_script_main.py

package info (click to toggle)
send2trash 1.6.0~b1%2Bgit20210122.2eb3242-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 184 kB
  • sloc: python: 737; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 1,004 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# encoding: utf-8
import os
import unittest
from tempfile import NamedTemporaryFile
from os import path as op

from send2trash.__main__ import main as trash_main
from tests.test_plat_other import HOMETRASH


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

    def test_trash(self):
        trash_main(['-v', self.file.name])
        self.assertFalse(op.exists(self.file.name))

    def test_no_args(self):
        self.assertRaises(SystemExit, trash_main, [])
        self.assertRaises(SystemExit, trash_main, ['-v'])
        self.assertTrue(op.exists(self.file.name))
        trash_main([self.file.name])  # Trash the file so tearDown runs properly

    def tearDown(self):
        name = op.basename(self.file.name)
        os.remove(op.join(HOMETRASH, 'files', name))
        os.remove(op.join(HOMETRASH, 'info', name + '.trashinfo'))


if __name__ == '__main__':
    unittest.main()