Skip to content

Commit

Permalink
Refactor: compatibility with pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
andreafrancia committed Dec 17, 2020
1 parent 79c0b3a commit 64bbb30
Show file tree
Hide file tree
Showing 29 changed files with 205 additions and 213 deletions.
4 changes: 3 additions & 1 deletion integration_tests/restore/test_trash_directory.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import unittest

from trashcli.restore import TrashDirectory

from integration_tests.files import require_empty_dir
Expand All @@ -7,7 +9,7 @@
from mock import Mock


class TestTrashDirectory:
class TestTrashDirectory(unittest.TestCase):
def setUp(self):
require_empty_dir('sandbox')
self.trash_dir = TrashDirectory()
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/test_file_descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from .files import require_empty_dir, make_empty_file
from nose.tools import assert_equal
import os
import unittest

class TestDescritions:
class TestDescritions(unittest.TestCase):
def setUp(self):
require_empty_dir('sandbox')

Expand Down
3 changes: 2 additions & 1 deletion integration_tests/test_filesystem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (C) 2008-2011 Andrea Francia Trivolzio(PV) Italy
import unittest

from trashcli.fs import FileSystemReader
from trashcli.fs import mkdirs
Expand Down Expand Up @@ -32,7 +33,7 @@ def setUp(self):
require_empty_dir('sandbox')

is_sticky_dir=FileSystemReader().is_sticky_dir
class Test_is_sticky_dir:
class Test_is_sticky_dir(unittest.TestCase):

def test_dir_non_sticky(self):
mkdirs('sandbox/dir'); assert not is_sticky_dir('sandbox/dir')
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/test_persist.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (C) 2008-2012 Andrea Francia Trivolzio(PV) Italy

import os
import unittest

from nose.tools import assert_equal, assert_true

Expand All @@ -10,7 +11,7 @@

join = os.path.join

class TestTrashDirectory_persit_trash_info:
class TestTrashDirectory_persit_trash_info(unittest.TestCase):
def setUp(self):
self.trashdirectory_base_dir = os.path.realpath(
"./sandbox/testTrashDirectory")
Expand Down
21 changes: 10 additions & 11 deletions integration_tests/test_trash_empty.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (C) 2011 Andrea Francia Trivolzio(PV) Italy
import unittest

from nose.tools import assert_equal, istest
from nose.tools import assert_equal
from unit_tests.tools import assert_items_equal
from trashcli.empty import EmptyCmd

Expand Down Expand Up @@ -57,7 +58,8 @@ def test_the_core_of_failures_for_issue_48(self):
os.chmod('unreadable-dir', 0o700)
shutil.rmtree('unreadable-dir')

class TestWhenCalledWithoutArguments:

class TestWhenCalledWithoutArguments(unittest.TestCase):

def setUp(self):
require_empty_dir('XDG_DATA_HOME')
Expand Down Expand Up @@ -156,8 +158,7 @@ def having_orphan_file_in_files_dir(self):
make_empty_file(complete_path)
assert os.path.exists(complete_path)

@istest
class When_invoked_with_N_days_as_argument:
class TestWhen_invoked_with_N_days_as_argument(unittest.TestCase):
def setUp(self):
require_empty_dir('XDG_DATA_HOME')
self.xdg_data_home = 'XDG_DATA_HOME'
Expand Down Expand Up @@ -185,26 +186,23 @@ def date(yyyy_mm_dd):
from datetime import datetime
return datetime.strptime(yyyy_mm_dd, '%Y-%m-%d')

@istest
def it_should_keep_files_newer_than_N_days(self):
def test_it_should_keep_files_newer_than_N_days(self):
self.having_a_trashed_file('foo', '2000-01-01')
self.set_clock_at('2000-01-01')

self.user_run_trash_empty('2')

self.file_should_have_been_kept_in_trashcan('foo')

@istest
def it_should_remove_files_older_than_N_days(self):
def test_it_should_remove_files_older_than_N_days(self):
self.having_a_trashed_file('foo', '1999-01-01')
self.set_clock_at('2000-01-01')

self.user_run_trash_empty('2')

self.file_should_have_been_removed_from_trashcan('foo')

@istest
def it_should_kept_files_with_invalid_deletion_date(self):
def test_it_should_kept_files_with_invalid_deletion_date(self):
self.having_a_trashed_file('foo', 'Invalid Date')
self.set_clock_at('2000-01-01')

Expand All @@ -226,7 +224,8 @@ def file_should_have_been_kept_in_trashcan(self, trashinfo_name):
def file_should_have_been_removed_from_trashcan(self, trashinfo_name):
assert not os.path.exists(self.trashinfo(trashinfo_name))

class TestEmptyCmdWithMultipleVolumes:

class TestEmptyCmdWithMultipleVolumes(unittest.TestCase):
def setUp(self):
require_empty_dir('topdir')
self.empty=EmptyCmd(
Expand Down
64 changes: 24 additions & 40 deletions integration_tests/test_trash_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from trashcli.list import ListCmd
from .files import (require_empty_dir, make_sticky_dir, make_unsticky_dir)
from nose.tools import istest
from .output_collector import OutputCollector
from .fake_trash_dir import (
a_trashinfo_without_date,
Expand All @@ -15,8 +14,10 @@
from textwrap import dedent
from trashcli.fs import FileSystemReader
from .asserts import assert_equals_with_unidiff
import unittest

class Setup(object):

class Setup(unittest.TestCase):
def setUp(self):
self.xdg_data_home = tempfile.mkdtemp()
require_empty_dir('topdir')
Expand All @@ -27,11 +28,9 @@ def tearDown(self):
def sort_lines(lines):
return "".join(sorted(lines.splitlines(True)))

@istest
class describe_trash_list(Setup):
class Test_describe_trash_list(Setup):

@istest
def should_output_the_help_message(self):
def test_should_output_the_help_message(self):

self.user.run_trash_list('--help')

Expand All @@ -47,15 +46,13 @@ def should_output_the_help_message(self):
Report bugs to https://github.com/andreafrancia/trash-cli/issues
"""), self.user.output())

@istest
def should_output_nothing_when_trashcan_is_empty(self):
def test_should_output_nothing_when_trashcan_is_empty(self):

self.user.run_trash_list()

assert_equals_with_unidiff('', self.user.output())

@istest
def should_output_deletion_date_and_path(self):
def test_should_output_deletion_date_and_path(self):
self.user.home_trashdir.add_trashinfo2('/aboslute/path',
'2001-02-03T23:55:59')

Expand All @@ -64,8 +61,7 @@ def should_output_deletion_date_and_path(self):
assert_equals_with_unidiff("2001-02-03 23:55:59 /aboslute/path\n",
self.user.output())

@istest
def should_output_info_for_multiple_files(self):
def test_should_output_info_for_multiple_files(self):
self.user.home_trashdir.add_trashinfo2("/file1", "2000-01-01T00:00:01")
self.user.home_trashdir.add_trashinfo2("/file2", "2000-01-01T00:00:02")
self.user.home_trashdir.add_trashinfo2("/file3", "2000-01-01T00:00:03")
Expand All @@ -78,26 +74,23 @@ def should_output_info_for_multiple_files(self):
"2000-01-01 00:00:03 /file3\n",
sort_lines(output))

@istest
def should_output_unknown_dates_with_question_marks(self):
def test_should_output_unknown_dates_with_question_marks(self):
self.user.home_trashdir.add_trashinfo(a_trashinfo_without_date())

self.user.run_trash_list()

assert_equals_with_unidiff("????-??-?? ??:??:?? /path\n",
self.user.output())

@istest
def should_output_invalid_dates_using_question_marks(self):
def test_should_output_invalid_dates_using_question_marks(self):
self.user.home_trashdir.add_trashinfo(a_trashinfo_with_invalid_date())

self.user.run_trash_list()

assert_equals_with_unidiff("????-??-?? ??:??:?? /path\n",
self.user.output())

@istest
def should_warn_about_empty_trashinfos(self):
def test_should_warn_about_empty_trashinfos(self):
self.user.home_trashdir.add_trashinfo('', 'empty')

self.user.run_trash_list()
Expand All @@ -107,8 +100,7 @@ def should_warn_about_empty_trashinfos(self):
"Unable to parse Path.\n" % {"XDG_DATA_HOME":self.xdg_data_home},
self.user.error())

@istest
def should_warn_about_unreadable_trashinfo(self):
def test_should_warn_about_unreadable_trashinfo(self):
self.user.home_trashdir.add_unreadable_trashinfo('unreadable')

self.user.run_trash_list()
Expand All @@ -120,8 +112,7 @@ def should_warn_about_unreadable_trashinfo(self):
},
self.user.error())

@istest
def should_warn_about_unexistent_path_entry(self):
def test_should_warn_about_unexistent_path_entry(self):
self.user.home_trashdir.add_trashinfo(a_trashinfo_without_path())

self.user.run_trash_list()
Expand All @@ -132,16 +123,14 @@ def should_warn_about_unexistent_path_entry(self):
self.user.error())
assert_equals_with_unidiff('', self.user.output())

@istest
class with_a_top_trash_dir(Setup):
class Test_with_a_top_trash_dir(Setup):
def setUp(self):
super(type(self),self).setUp()
self.top_trashdir1 = FakeTrashDir('topdir/.Trash/123')
self.user.set_fake_uid(123)
self.user.add_volume('topdir')

@istest
def should_list_its_contents_if_parent_is_sticky(self):
def test_should_list_its_contents_if_parent_is_sticky(self):
make_sticky_dir('topdir/.Trash')
self.and_contains_a_valid_trashinfo()

Expand All @@ -150,8 +139,7 @@ def should_list_its_contents_if_parent_is_sticky(self):
assert_equals_with_unidiff("2000-01-01 00:00:00 topdir/file1\n",
self.user.output())

@istest
def and_should_warn_if_parent_is_not_sticky(self):
def test_and_should_warn_if_parent_is_not_sticky(self):
make_unsticky_dir('topdir/.Trash')
self.and_dir_exists('topdir/.Trash/123')

Expand All @@ -162,35 +150,31 @@ def and_should_warn_if_parent_is_not_sticky(self):
self.user.error()
)

@istest
def but_it_should_not_warn_when_the_parent_is_unsticky_but_there_is_no_trashdir(self):
def test_but_it_should_not_warn_when_the_parent_is_unsticky_but_there_is_no_trashdir(self):
make_unsticky_dir('topdir/.Trash')
self.but_does_not_exists_any('topdir/.Trash/123')

self.user.run_trash_list()

assert_equals_with_unidiff("", self.user.error())

@istest
def should_ignore_trash_from_a_unsticky_topdir(self):
def test_should_ignore_trash_from_a_unsticky_topdir(self):
make_unsticky_dir('topdir/.Trash')
self.and_contains_a_valid_trashinfo()

self.user.run_trash_list()

assert_equals_with_unidiff('', self.user.output())

@istest
def it_should_ignore_Trash_is_a_symlink(self):
def test_it_should_ignore_Trash_is_a_symlink(self):
self.when_is_a_symlink_to_a_dir('topdir/.Trash')
self.and_contains_a_valid_trashinfo()

self.user.run_trash_list()

assert_equals_with_unidiff('', self.user.output())

@istest
def and_should_warn_about_it(self):
def test_and_should_warn_about_it(self):
self.when_is_a_symlink_to_a_dir('topdir/.Trash')
self.and_contains_a_valid_trashinfo()

Expand All @@ -214,10 +198,10 @@ def when_is_a_symlink_to_a_dir(self, path):
rel_dest = os.path.basename(dest)
os.symlink(rel_dest, path)

@istest
class describe_when_a_file_is_in_alternate_top_trashdir(Setup):
@istest
def should_list_contents_of_alternate_trashdir(self):

class Test_describe_when_a_file_is_in_alternate_top_trashdir(Setup):

def test_should_list_contents_of_alternate_trashdir(self):
self.user.set_fake_uid(123)
self.user.add_volume('topdir')
self.top_trashdir2 = FakeTrashDir('topdir/.Trash-123')
Expand Down
Loading

0 comments on commit 64bbb30

Please sign in to comment.