diff --git a/integration_tests/restore/test_trash_directory.py b/integration_tests/restore/test_trash_directory.py index 5bb80a7c..731368ec 100644 --- a/integration_tests/restore/test_trash_directory.py +++ b/integration_tests/restore/test_trash_directory.py @@ -1,3 +1,5 @@ +import unittest + from trashcli.restore import TrashDirectory from integration_tests.files import require_empty_dir @@ -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() diff --git a/integration_tests/test_file_descriptions.py b/integration_tests/test_file_descriptions.py index 4873c721..86be8592 100644 --- a/integration_tests/test_file_descriptions.py +++ b/integration_tests/test_file_descriptions.py @@ -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') diff --git a/integration_tests/test_filesystem.py b/integration_tests/test_filesystem.py index 0c764e8c..f7c3670e 100644 --- a/integration_tests/test_filesystem.py +++ b/integration_tests/test_filesystem.py @@ -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 @@ -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') diff --git a/integration_tests/test_persist.py b/integration_tests/test_persist.py index ea92f022..8fc5084e 100644 --- a/integration_tests/test_persist.py +++ b/integration_tests/test_persist.py @@ -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 @@ -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") diff --git a/integration_tests/test_trash_empty.py b/integration_tests/test_trash_empty.py index 7dfce023..aec818fe 100644 --- a/integration_tests/test_trash_empty.py +++ b/integration_tests/test_trash_empty.py @@ -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 @@ -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') @@ -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' @@ -185,8 +186,7 @@ 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') @@ -194,8 +194,7 @@ def it_should_keep_files_newer_than_N_days(self): 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') @@ -203,8 +202,7 @@ def it_should_remove_files_older_than_N_days(self): 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') @@ -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( diff --git a/integration_tests/test_trash_list.py b/integration_tests/test_trash_list.py index 6410bc96..9d38f931 100644 --- a/integration_tests/test_trash_list.py +++ b/integration_tests/test_trash_list.py @@ -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, @@ -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') @@ -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') @@ -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') @@ -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") @@ -78,8 +74,7 @@ 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() @@ -87,8 +82,7 @@ def should_output_unknown_dates_with_question_marks(self): 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() @@ -96,8 +90,7 @@ def should_output_invalid_dates_using_question_marks(self): 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() @@ -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() @@ -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() @@ -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() @@ -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') @@ -162,8 +150,7 @@ 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') @@ -171,8 +158,7 @@ def but_it_should_not_warn_when_the_parent_is_unsticky_but_there_is_no_trashdir( 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() @@ -180,8 +166,7 @@ def should_ignore_trash_from_a_unsticky_topdir(self): 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() @@ -189,8 +174,7 @@ def it_should_ignore_Trash_is_a_symlink(self): 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() @@ -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') diff --git a/integration_tests/test_trash_put.py b/integration_tests/test_trash_put.py index c0ee0f63..9c1cf418 100644 --- a/integration_tests/test_trash_put.py +++ b/integration_tests/test_trash_put.py @@ -4,7 +4,7 @@ import os from os.path import exists as file_exists from datetime import datetime -from nose.tools import istest, assert_equal, assert_not_equal +from nose.tools import assert_equal, assert_not_equal from nose.tools import assert_in from .files import make_empty_file, require_empty_dir @@ -13,8 +13,10 @@ from trashcli.fs import remove_file from trashcli.put import parent_path, RealFs from .asserts import assert_line_in_text +import unittest -class TestPath: + +class TestPath(unittest.TestCase): def setUp(self): self.base = os.path.realpath(os.getcwd()) @@ -56,7 +58,7 @@ def test4(self): remove_file('foo') remove_file('bar') -class TrashPutTest: +class TrashPutTest(unittest.TestCase): def setUp(self): self.prepare_fixture() @@ -92,50 +94,43 @@ def run_trashput(self, *argv): self.exit_code = cmd.run(list(argv)) self.stderr = self.err.getvalue() -@istest -class when_deleting_an_existing_file(TrashPutTest): + +class Test_when_deleting_an_existing_file(TrashPutTest): def setUp2(self): make_empty_file('sandbox/foo') self.run_trashput('trash-put', 'sandbox/foo') - @istest - def it_should_remove_the_file(self): + def test_it_should_remove_the_file(self): assert not file_exists('sandbox/foo') - @istest - def it_should_remove_it_silently(self): + def test_it_should_remove_it_silently(self): self.output_should_be('') - @istest - def a_trashinfo_file_should_have_been_created(self): + def test_a_trashinfo_file_should_have_been_created(self): open('sandbox/XDG_DATA_HOME/Trash/info/foo.trashinfo').read() -@istest -class when_deleting_an_existing_file_in_verbose_mode(TrashPutTest): +class Test_when_deleting_an_existing_file_in_verbose_mode(TrashPutTest): def setUp2(self): make_empty_file('sandbox/foo') self.run_trashput('trash-put', '-v', 'sandbox/foo') - @istest - def should_tell_where_a_file_is_trashed(self): + def test_should_tell_where_a_file_is_trashed(self): assert_in("trash-put: 'sandbox/foo' trashed in sandbox/XDG_DATA_HOME/Trash", self.stderr.splitlines()) - @istest - def should_be_succesfull(self): + def test_should_be_succesfull(self): assert_equal(0, self.exit_code) -@istest -class when_deleting_a_non_existing_file(TrashPutTest): + +class Test_when_deleting_a_non_existing_file(TrashPutTest): def setUp2(self): self.run_trashput('trash-put', '-v', 'non-existent') - @istest - def should_be_succesfull(self): + def test_should_be_succesfull(self): assert_not_equal(0, self.exit_code) -@istest -class when_fed_with_dot_arguments(TrashPutTest): + +class Test_when_fed_with_dot_arguments(TrashPutTest): def setUp2(self): require_empty_dir('sandbox/') @@ -191,7 +186,7 @@ def test_dot_dot_argument_is_skipped_even_in_subdirs(self): assert not file_exists('other_argument') assert file_exists('sandbox') -@istest + class TestUnsecureTrashDirMessages(TrashPutTest): def setUp(self): TrashPutTest.setUp(self) @@ -199,8 +194,7 @@ def setUp(self): self.fstab.add_mount('fake-vol') make_empty_file('fake-vol/foo') - @istest - def when_is_unsticky(self): + def test_when_is_unsticky(self): require_empty_dir('fake-vol/.Trash') self.run_trashput('trash-put', '-v', 'fake-vol/foo') @@ -209,8 +203,7 @@ def when_is_unsticky(self): 'trash-put: found unsecure .Trash dir (should be sticky): ' 'fake-vol/.Trash', self.stderr) - @istest - def when_it_is_not_a_dir(self): + def test_when_it_is_not_a_dir(self): make_empty_file('fake-vol/.Trash') self.run_trashput('trash-put', '-v', 'fake-vol/foo') @@ -219,8 +212,7 @@ def when_it_is_not_a_dir(self): 'trash-put: found unusable .Trash dir (should be a dir): ' 'fake-vol/.Trash', self.stderr) - @istest - def when_is_a_symlink(self): + def test_when_is_a_symlink(self): make_sticky_dir('fake-vol/link-destination') os.symlink('link-destination', 'fake-vol/.Trash') diff --git a/integration_tests/test_trash_rm.py b/integration_tests/test_trash_rm.py index 64ee14ee..f5654835 100644 --- a/integration_tests/test_trash_rm.py +++ b/integration_tests/test_trash_rm.py @@ -1,3 +1,5 @@ +import unittest + from unit_tests.myStringIO import StringIO from mock import Mock, ANY from nose.tools import assert_false, assert_equal @@ -5,8 +7,10 @@ from .files import require_empty_dir, make_file from trashcli.rm import RmCmd, ListTrashinfos from .fake_trash_dir import a_trashinfo_with_path, a_trashinfo_without_path +from trashcli.fs import FileSystemReader -class TestTrashRm: + +class TestTrashRm(unittest.TestCase): def test_issue69(self): self.add_invalid_trashinfo_without_path(1) @@ -50,8 +54,8 @@ def assert_trashinfo_has_been_deleted(self, index): assert_false(os.path.exists(filename), 'File "%s" still exists' % filename) -from trashcli.fs import FileSystemReader -class TestListing: + +class TestListing(unittest.TestCase): def setUp(self): require_empty_dir('sandbox') self.out = Mock() @@ -99,6 +103,3 @@ def _trashinfo_path(self, trashdir): path = '%s/info/%s.trashinfo' % (trashdir, self.index) self.index +=1 return path - - - diff --git a/integration_tests/test_trash_rm_script.py b/integration_tests/test_trash_rm_script.py index 42a44910..148bc8b5 100644 --- a/integration_tests/test_trash_rm_script.py +++ b/integration_tests/test_trash_rm_script.py @@ -1,8 +1,10 @@ -from nose.tools import istest, assert_equal, assert_in +import unittest + +from nose.tools import assert_equal, assert_in from subprocess import PIPE, Popen import sys -class TestScriptsSmoke: +class TestScriptsSmoke(unittest.TestCase): def test_trash_rm_works(self): self.run_script('trash-rm') assert_in("Usage:", self.stderr.splitlines()) diff --git a/unit_tests/test_check_release_installation.py b/unit_tests/test_check_release_installation.py index 7e183863..96647187 100644 --- a/unit_tests/test_check_release_installation.py +++ b/unit_tests/test_check_release_installation.py @@ -1,10 +1,13 @@ +import unittest + from check_release_installation import (CheckInstallation, Pip3Installation, PipInstallation) from nose.tools import assert_equal from mock import call -class TestCheckBothInstallations: + +class TestCheckBothInstallations(unittest.TestCase): def setUp(self): self.calls = [] outer = self @@ -69,4 +72,3 @@ def test_pip2_installation(self): call().run_checked('trash-empty --version'), call().run_checked('trash-restore --version'), call().run_checked('trash --version')], self.calls) - diff --git a/unit_tests/test_empty.py b/unit_tests/test_empty.py index 1cf47f43..761c1455 100644 --- a/unit_tests/test_empty.py +++ b/unit_tests/test_empty.py @@ -1,8 +1,11 @@ +import unittest + from trashcli.empty import EmptyCmd from mock import Mock, call from nose.tools import assert_equal -class TestTrashEmptyCmd: + +class TestTrashEmptyCmd(unittest.TestCase): def setUp(self): self.empty_all_trashdirs = Mock() self.empty_trashdir = Mock() @@ -22,4 +25,3 @@ def test(self): assert_equal([], self.empty_all_trashdirs.mock_calls) assert_equal([call('specific')], self.empty_trashdir.mock_calls) - diff --git a/unit_tests/test_fake_fstab.py b/unit_tests/test_fake_fstab.py index e920715a..9ab39b1e 100644 --- a/unit_tests/test_fake_fstab.py +++ b/unit_tests/test_fake_fstab.py @@ -1,8 +1,11 @@ +import unittest + from trashcli.fstab import FakeFstab from nose.tools import assert_equal -class TestFakeFstab: + +class TestFakeFstab(unittest.TestCase): def setUp(self): self.fstab = FakeFstab() @@ -21,4 +24,3 @@ def test_something(self): def filter_only_mount_points(self, *supposed_mount_points): return [mp for mp in supposed_mount_points if mp == self.fstab.volume_of(mp)] - diff --git a/unit_tests/test_fake_ismount.py b/unit_tests/test_fake_ismount.py index 2fdea969..19c4bcd2 100644 --- a/unit_tests/test_fake_ismount.py +++ b/unit_tests/test_fake_ismount.py @@ -1,60 +1,54 @@ +import unittest + from trashcli.fstab import FakeIsMount -from nose.tools import istest from nose.tools import assert_false from nose.tools import assert_true -@istest -class OnDefault: + +class TestOnDefault(unittest.TestCase): def setUp(self): self.ismount = FakeIsMount() - @istest - def by_default_root_is_mount(self): + def test_by_default_root_is_mount(self): assert_true(self.ismount('/')) - @istest - def while_by_default_any_other_is_not_a_mount_point(self): + def test_while_by_default_any_other_is_not_a_mount_point(self): assert_false(self.ismount('/any/other')) -@istest -class WhenOneFakeVolumeIsDefined: +class WhenOneFakeVolumeIsDefined(unittest.TestCase): def setUp(self): self.ismount = FakeIsMount() self.ismount.add_mount('/fake-vol') - @istest - def accept_fake_mount_point(self): + def test_accept_fake_mount_point(self): assert_true(self.ismount('/fake-vol')) - @istest - def other_still_are_not_mounts(self): + def test_other_still_are_not_mounts(self): assert_false(self.ismount('/other')) - @istest - def dont_get_confused_by_traling_slash(self): + def test_dont_get_confused_by_traling_slash(self): assert_true(self.ismount('/fake-vol/')) -@istest -class WhenMultipleFakesMountPoints: + +class TestWhenMultipleFakesMountPoints(unittest.TestCase): def setUp(self): self.ismount = FakeIsMount() self.ismount.add_mount('/vol1') self.ismount.add_mount('/vol2') - @istest - def recognize_both(self): + def test_recognize_both(self): assert_true(self.ismount('/vol1')) assert_true(self.ismount('/vol2')) assert_false(self.ismount('/other')) -@istest -def should_handle_relative_volumes(): + +def test_should_handle_relative_volumes(): ismount = FakeIsMount() ismount.add_mount('fake-vol') assert_true(ismount('fake-vol')) diff --git a/unit_tests/test_global_trashcan.py b/unit_tests/test_global_trashcan.py index b9476328..4e0c8b70 100644 --- a/unit_tests/test_global_trashcan.py +++ b/unit_tests/test_global_trashcan.py @@ -1,5 +1,7 @@ +import unittest + from mock import Mock, call -from nose.tools import istest, assert_equal +from nose.tools import assert_equal from datetime import datetime from trashcli.put import GlobalTrashCan @@ -42,7 +44,8 @@ def test(self): call('', '/volume/.Trash-uid') ], reporter.file_has_been_trashed_in_as.mock_calls) -class TestGlobalTrashCan: + +class TestGlobalTrashCan(unittest.TestCase): def setUp(self): self.reporter = Mock() self.fs = Mock() @@ -65,23 +68,20 @@ def test_log_volume(self): self.reporter.volume_of_file.assert_called_with('/') - @istest - def should_report_when_trash_fail(self): + def test_should_report_when_trash_fail(self): self.fs.move.side_effect = IOError self.trashcan.trash('non-existent') self.reporter.unable_to_trash_file.assert_called_with('non-existent') - @istest - def should_not_delete_a_dot_entru(self): + def test_should_not_delete_a_dot_entru(self): self.trashcan.trash('.') self.reporter.unable_to_trash_dot_entries.assert_called_with('.') - @istest - def bug(self): + def test_bug(self): self.fs.mock_add_spec([ 'move', 'atomic_write', diff --git a/unit_tests/test_home_fallback.py b/unit_tests/test_home_fallback.py index 480ec963..6a5e8c97 100644 --- a/unit_tests/test_home_fallback.py +++ b/unit_tests/test_home_fallback.py @@ -1,3 +1,5 @@ +import unittest + from mock import Mock, call, ANY from trashcli.fstab import FakeFstab @@ -6,7 +8,8 @@ from datetime import datetime import os -class TestHomeFallback: + +class TestHomeFallback(unittest.TestCase): def setUp(self): self.reporter = Mock() mount_points = ['/', 'sandbox/other_partition'] diff --git a/unit_tests/test_issues_message.py b/unit_tests/test_issues_message.py index 06ee2456..dd3c5b75 100644 --- a/unit_tests/test_issues_message.py +++ b/unit_tests/test_issues_message.py @@ -1,8 +1,11 @@ +import unittest + from nose.tools import assert_equal from unit_tests.myStringIO import StringIO -class TestTrashPutIssueMessage: + +class TestTrashPutIssueMessage(unittest.TestCase): def setUp(self): self.out = StringIO() diff --git a/unit_tests/test_list_all_trashinfo_contents.py b/unit_tests/test_list_all_trashinfo_contents.py index f58367d1..5add6cb0 100644 --- a/unit_tests/test_list_all_trashinfo_contents.py +++ b/unit_tests/test_list_all_trashinfo_contents.py @@ -1,7 +1,9 @@ +import unittest + from mock import Mock, call from unit_tests.tools import assert_items_equal -class TestListing: +class TestListing(unittest.TestCase): def setUp(self): self.trashdir = Mock() self.trashinfo_reader = Mock() @@ -15,7 +17,8 @@ def test_it_should_read_all_trashinfo_from_home_dir(self): trashdir='/path/to/trash_dir', list_to=self.trashinfo_reader) -class TestTrashDirReader: + +class TestTrashDirReader(unittest.TestCase): def test_should_list_all_trashinfo_found(self): def files(path): yield 'file1'; yield 'file2' os_listdir = Mock(side_effect=files) @@ -28,7 +31,7 @@ def files(path): yield 'file1'; yield 'file2' call(trashinfo='/path/file2')], out.mock_calls) -class TrashDirReader: +class TrashDirReader(unittest.TestCase): def __init__(self, os_listdir): self.os_listdir = os_listdir def list_trashinfos(self, trashdir, list_to): diff --git a/unit_tests/test_make_script.py b/unit_tests/test_make_script.py index b8ce3f9c..11397d67 100644 --- a/unit_tests/test_make_script.py +++ b/unit_tests/test_make_script.py @@ -1,10 +1,11 @@ +import unittest from textwrap import dedent from nose.tools import assert_equal import mock from mock import Mock from setup import Scripts -class TestMakeScript: +class TestMakeScript(unittest.TestCase): def setUp(self): self.make_file_executable = Mock() self.write_file = Mock() @@ -39,7 +40,7 @@ def test_the_script_should_call_the_right_function_from_the_right_module(self): "Actual :\n---\n%s---\n" % (expected, contents)) -class TestListOfCreatedScripts: +class TestListOfCreatedScripts(unittest.TestCase): def setUp(self): self.bindir = Scripts( make_file_executable = Mock(), diff --git a/unit_tests/test_method1_security_check.py b/unit_tests/test_method1_security_check.py index 13497a34..183331db 100644 --- a/unit_tests/test_method1_security_check.py +++ b/unit_tests/test_method1_security_check.py @@ -1,9 +1,11 @@ +import unittest + from mock import Mock from integration_tests.files import require_empty_dir from trashcli.put import TopTrashDirWriteRules -class TestMethod1VolumeTrashDirectory: +class TestMethod1VolumeTrashDirectory(unittest.TestCase): def setUp(self): require_empty_dir('sandbox') self.fs = Mock() diff --git a/unit_tests/test_parser.py b/unit_tests/test_parser.py index dbbd62ed..c7564969 100644 --- a/unit_tests/test_parser.py +++ b/unit_tests/test_parser.py @@ -1,8 +1,11 @@ +import unittest + from trashcli.trash import Parser from mock import MagicMock, call -from nose.tools import istest, assert_equal +from nose.tools import assert_equal + -class TestParser(): +class TestParser(unittest.TestCase): def setUp(self): self.invalid_option_callback = MagicMock() self.on_raw = MagicMock() diff --git a/unit_tests/test_parsing_trashinfo_contents.py b/unit_tests/test_parsing_trashinfo_contents.py index c6412e3e..1201aa81 100644 --- a/unit_tests/test_parsing_trashinfo_contents.py +++ b/unit_tests/test_parsing_trashinfo_contents.py @@ -1,17 +1,15 @@ # Copyright (C) 2011 Andrea Francia Trivolzio(PV) Italy +import unittest from nose.tools import assert_equal, assert_raises -from nose.tools import istest - from datetime import datetime from mock import MagicMock from trashcli.trash import ParseTrashInfo -@istest -class describe_ParseTrashInfo2: - @istest - def it_should_parse_date(self): + +class Test_describe_ParseTrashInfo2(unittest.TestCase): + def test_it_should_parse_date(self): out = MagicMock() parse = ParseTrashInfo(on_deletion_date = out) @@ -21,8 +19,7 @@ def it_should_parse_date(self): out.assert_called_with(datetime(1970,1,1,0,0,0)) - @istest - def it_should_parse_path(self): + def test_it_should_parse_path(self): out = MagicMock() self.parse = ParseTrashInfo(on_path = out) @@ -44,21 +41,21 @@ def test_how_to_parse_date_from_trashinfo(): from trashcli.trash import maybe_parse_deletion_date UNKNOWN_DATE='????-??-?? ??:??:??' -@istest -class describe_maybe_parse_deletion_date: - @istest - def on_trashinfo_without_date_parse_to_unknown_date(self): + + +class Test_describe_maybe_parse_deletion_date(unittest.TestCase): + def test_on_trashinfo_without_date_parse_to_unknown_date(self): assert_equal(UNKNOWN_DATE, maybe_parse_deletion_date(a_trashinfo_without_deletion_date())) - @istest - def on_trashinfo_with_date_parse_to_date(self): + + def test_on_trashinfo_with_date_parse_to_date(self): from datetime import datetime example_date_as_string='2001-01-01T00:00:00' same_date_as_datetime=datetime(2001,1,1) assert_equal(same_date_as_datetime, maybe_parse_deletion_date(make_trashinfo(example_date_as_string))) - @istest - def on_trashinfo_with_invalid_date_parse_to_unknown_date(self): + + def test_on_trashinfo_with_invalid_date_parse_to_unknown_date(self): invalid_date='A long time ago' assert_equal(UNKNOWN_DATE, maybe_parse_deletion_date(make_trashinfo(invalid_date))) @@ -71,13 +68,13 @@ def test_how_to_parse_original_path(): from trashcli.restore import TrashInfoParser from trashcli.trash import ParseError -class TestParsing: +class TestParsing(unittest.TestCase): def test_1(self): parser = TrashInfoParser("[Trash Info]\n" "Path=/foo.txt\n", volume_path = '/') assert_equal('/foo.txt', parser.original_location()) -class TestTrashInfoParser_with_empty_trashinfo: +class TestTrashInfoParser_with_empty_trashinfo(unittest.TestCase): def setUp(self): self.parser = TrashInfoParser(contents=an_empty_trashinfo(), volume_path='/') @@ -96,6 +93,3 @@ def make_trashinfo(date): "DeletionDate=%s" % date) def an_empty_trashinfo(): return '' - - - diff --git a/unit_tests/test_restore_cmd.py b/unit_tests/test_restore_cmd.py index daa5c68a..eb378376 100644 --- a/unit_tests/test_restore_cmd.py +++ b/unit_tests/test_restore_cmd.py @@ -9,8 +9,7 @@ from trashcli import restore import datetime from mock import Mock -from integration_tests.files import make_file, require_empty_dir, make_empty_file -from trashcli.fs import remove_file, contents_of +from integration_tests.files import make_file, require_empty_dir from trashcli.fs import remove_file from trashcli.fs import contents_of @@ -30,7 +29,7 @@ def test_show_version(self): args = restore.parse_args(['', '--version'], None) self.assertEqual(True, args.version) -class TestListingInRestoreCmd: +class TestListingInRestoreCmd(unittest.TestCase): def setUp(self): trash_directories = make_trash_directories() trashed_files = TrashedFiles(trash_directories, None, contents_of) @@ -86,7 +85,8 @@ def __repr__(self): return ('FakeTrashedFile(\'%s\', ' % self.deletion_date + '\'%s\')' % self.original_location) -class TestTrashRestoreCmd: + +class TestTrashRestoreCmd(unittest.TestCase): def setUp(self): self.stdout = StringIO() self.stderr = StringIO() @@ -166,7 +166,7 @@ def test_when_user_reply_with_an_out_of_range_number(self): from trashcli.restore import TrashedFile from nose.tools import assert_raises, assert_true import os -class TestTrashedFileRestoreIntegration: +class TestTrashedFileRestoreIntegration(unittest.TestCase): def setUp(self): remove_file_if_exists('parent/path') remove_dir_if_exists('parent') @@ -217,7 +217,7 @@ def test_restore_create_needed_directories(self): assert os.path.exists("sandbox/foo/bar") -class TestTrashedFiles: +class TestTrashedFiles(unittest.TestCase): def setUp(self): self.trash_directories = Mock(spec=['trash_directories_or_user']) self.trash_directory = Mock(spec=['all_info_files']) @@ -245,7 +245,7 @@ def test_something(self): self.trash_directories.mock_calls) -class TestTrashedFilesIntegration: +class TestTrashedFilesIntegration(unittest.TestCase): def setUp(self): self.trash_directories = Mock(spec=['trash_directories_or_user']) self.trash_directory = Mock(spec=['all_info_files']) diff --git a/unit_tests/test_shrink_user.py b/unit_tests/test_shrink_user.py index aba4b7a5..a08d325e 100644 --- a/unit_tests/test_shrink_user.py +++ b/unit_tests/test_shrink_user.py @@ -1,7 +1,9 @@ +import unittest + from nose.tools import assert_equal from trashcli.put import shrinkuser -class TestTrashDirectoryName: +class TestTrashDirectoryName(unittest.TestCase): def setUp(self): self.environ = {} diff --git a/unit_tests/test_trash_dirs_listing.py b/unit_tests/test_trash_dirs_listing.py index 3fc1e3df..d8a20eb5 100644 --- a/unit_tests/test_trash_dirs_listing.py +++ b/unit_tests/test_trash_dirs_listing.py @@ -1,36 +1,37 @@ # Copyright (C) 2011 Andrea Francia Trivolzio(PV) Italy +import unittest from trashcli.trash import TrashDirs -from nose.tools import istest, assert_in, assert_not_in +from nose.tools import assert_in, assert_not_in from mock import Mock +from nose.tools import assert_equal +from mock import MagicMock +from trashcli.trash import TopTrashDirRules + + +class TestTrashDirs_listing(unittest.TestCase): -@istest -class TestTrashDirs_listing: - @istest - def the_method_2_is_always_in(self): + def test_the_method_2_is_always_in(self): self.uid = 123 self.volumes = ['/usb'] assert_in('/usb/.Trash-123', self.trashdirs()) - @istest - def the_method_1_is_in_if_it_is_a_sticky_dir(self): + def test_the_method_1_is_in_if_it_is_a_sticky_dir(self): self.uid = 123 self.volumes = ['/usb'] self.having_sticky_Trash_dir() assert_in('/usb/.Trash/123', self.trashdirs()) - @istest - def the_method_1_is_not_considered_if_not_sticky_dir(self): + def test_the_method_1_is_not_considered_if_not_sticky_dir(self): self.uid = 123 self.volumes = ['/usb'] self.having_non_sticky_Trash_dir() assert_not_in('/usb/.Trash/123', self.trashdirs()) - @istest - def should_return_home_trashcan_when_XDG_DATA_HOME_is_defined(self): + def test_should_return_home_trashcan_when_XDG_DATA_HOME_is_defined(self): self.environ['XDG_DATA_HOME'] = '~/.local/share' assert_in('~/.local/share/Trash', self.trashdirs()) @@ -72,11 +73,8 @@ def having_non_sticky_Trash_dir(self): self.Trash_dir_is_sticky = False def not_important_for_now(): None -from nose.tools import assert_equal -from mock import MagicMock -from trashcli.trash import TopTrashDirRules -@istest -class Describe_AvailableTrashDirs_when_parent_is_unsticky: + +class TestDescribe_AvailableTrashDirs_when_parent_is_unsticky(unittest.TestCase): def setUp(self): self.fs = MagicMock() self.dirs = TrashDirs(environ = {}, @@ -106,8 +104,8 @@ def test_it_shouldnot_care_about_non_existent(self): assert_equal([], self.dirs.on_trashdir_skipped_because_parent_not_sticky.mock_calls) -@istest -class Describe_AvailableTrashDirs_when_parent_is_symlink: + +class TestDescribe_AvailableTrashDirs_when_parent_is_symlink(unittest.TestCase): def setUp(self): self.fs = MagicMock() self.dirs = TrashDirs(environ = {}, diff --git a/unit_tests/test_trash_put_reporter.py b/unit_tests/test_trash_put_reporter.py index ea968664..7d55d05d 100644 --- a/unit_tests/test_trash_put_reporter.py +++ b/unit_tests/test_trash_put_reporter.py @@ -1,10 +1,11 @@ +import unittest + from nose.tools import assert_equal -from nose.tools import istest from trashcli.put import TrashPutReporter -class TestTrashPutReporter: - @istest - def it_should_record_failures(self): + +class TestTrashPutReporter(unittest.TestCase): + def test_it_should_record_failures(self): reporter = TrashPutReporter(self) assert_equal(False, reporter.some_file_has_not_be_trashed) diff --git a/unit_tests/test_trash_rm.py b/unit_tests/test_trash_rm.py index 6bf6d2f4..dfc0b928 100644 --- a/unit_tests/test_trash_rm.py +++ b/unit_tests/test_trash_rm.py @@ -1,11 +1,14 @@ -from nose.tools import istest, assert_equal +import unittest + +from nose.tools import assert_equal from unit_tests.tools import assert_items_equal from mock import Mock, call from trashcli.rm import Filter from unit_tests.myStringIO import StringIO -class TestTrashRmCmdRun: + +class TestTrashRmCmdRun(unittest.TestCase): def test_without_arguments(self): from trashcli.rm import RmCmd cmd = RmCmd(None, None, None, None, None) @@ -30,7 +33,7 @@ def test_without_pattern_argument(self): assert_equal('', cmd.stderr.getvalue()) -class TestTrashRmCmd: +class TestTrashRmCmd(unittest.TestCase): def test_a_star_matches_all(self): self.cmd.use_pattern('*') diff --git a/unit_tests/test_trashdir.py b/unit_tests/test_trashdir.py index b22f9bc4..6879b1be 100644 --- a/unit_tests/test_trashdir.py +++ b/unit_tests/test_trashdir.py @@ -1,9 +1,10 @@ # Copyright (C) 2011 Andrea Francia Trivolzio(PV) Italy +import unittest from nose.tools import assert_equal from trashcli.trash import TrashDir -class TestTrashDir_finding_orphans: +class TestTrashDir_finding_orphans(unittest.TestCase): def test(self): self.fs.create_fake_file('/info/foo.trashinfo') @@ -44,7 +45,7 @@ def create_fake_file(self, path, contents=''): def create_fake_dir(self, dir_path, *dir_entries): self.dirs[dir_path] = dir_entries -class TestFakeFileSystem: +class TestFakeFileSystem(unittest.TestCase): def setUp(self): self.fs = FakeFileSystem() def test_you_can_read_from_files(self): diff --git a/unit_tests/test_trashing_a_file.py b/unit_tests/test_trashing_a_file.py index 917f3a0f..49db71c1 100644 --- a/unit_tests/test_trashing_a_file.py +++ b/unit_tests/test_trashing_a_file.py @@ -1,10 +1,11 @@ +import unittest + from trashcli.put import TrashDirectoryForPut from trashcli.put import TopDirRelativePaths from mock import Mock -from nose.tools import istest, assert_equal from mock import ANY -class TestTrashing: +class TestTrashing(unittest.TestCase): def setUp(self): self.now = Mock() self.fs = Mock() @@ -15,15 +16,13 @@ def setUp(self): self.trashdir.path_maker = path_maker self.logger = Mock(['debug']) - @istest - def the_file_should_be_moved_in_trash_dir(self): + def test_the_file_should_be_moved_in_trash_dir(self): self.trashdir.trash2('foo', self.now, self.logger) self.fs.move.assert_called_with('foo', '~/.Trash/files/foo') self.logger.debug.assert_called_with('.trashinfo created as ~/.Trash/info/foo.trashinfo.') - @istest def test_should_create_a_trashinfo(self): self.trashdir.trash2('foo', self.now, self.logger) @@ -31,8 +30,7 @@ def test_should_create_a_trashinfo(self): self.fs.atomic_write.assert_called_with('~/.Trash/info/foo.trashinfo', ANY) self.logger.debug.assert_called_with('.trashinfo created as ~/.Trash/info/foo.trashinfo.') - @istest - def trashinfo_should_contains_original_location_and_deletion_date(self): + def test_trashinfo_should_contains_original_location_and_deletion_date(self): from datetime import datetime self.now.return_value = datetime(2012, 9, 25, 21, 47, 39) @@ -44,8 +42,7 @@ def trashinfo_should_contains_original_location_and_deletion_date(self): b'DeletionDate=2012-09-25T21:47:39\n') self.logger.debug.assert_called_with('.trashinfo created as ~/.Trash/info/foo.trashinfo.') - @istest - def should_rollback_trashinfo_creation_on_problems(self): + def test_should_rollback_trashinfo_creation_on_problems(self): self.fs.move.side_effect = IOError try: self.trashdir.trash2('foo', self.now, self.logger) diff --git a/unit_tests/test_volume_of.py b/unit_tests/test_volume_of.py index b8ba8eab..49a0d7e0 100644 --- a/unit_tests/test_volume_of.py +++ b/unit_tests/test_volume_of.py @@ -1,27 +1,25 @@ +import unittest + from trashcli.fstab import VolumeOf from trashcli.fstab import FakeIsMount -from nose.tools import assert_equal, istest +from nose.tools import assert_equal import os -@istest -class TestVolumeOf: + +class TestVolumeOf(unittest.TestCase): def setUp(self): self.ismount = FakeIsMount() self.volume_of = VolumeOf(self.ismount, os.path.normpath) - @istest - def return_the_containing_volume(self): + def test_return_the_containing_volume(self): self.ismount.add_mount('/fake-vol') assert_equal('/fake-vol', self.volume_of('/fake-vol/foo')) - @istest - def with_file_that_are_outside(self): + def test_with_file_that_are_outside(self): self.ismount.add_mount('/fake-vol') assert_equal('/', self.volume_of('/foo')) - @istest - def it_work_also_with_relative_mount_point(self): + def test_it_work_also_with_relative_mount_point(self): self.ismount.add_mount('relative-fake-vol') assert_equal('relative-fake-vol', self.volume_of('relative-fake-vol/foo')) -