def test_ls_with_type_file(self): files_in_current_folder = self.files["total"][:] files_in_current_folder = gt._natural_sort(files_in_current_folder) results = gt.list_elements(self.path_to_playground, type_="file", sort="natural") self.assertEqual(results, files_in_current_folder)
def test_ls_with_extensions(self): files_in_current_folder = self.files[".py"] files_in_current_folder = gt._natural_sort(files_in_current_folder) results = gt.list_elements(self.path_to_playground, sort="natural", extension=".py") self.assertEqual(results, files_in_current_folder)
def test_ls_with_exception(self): files_in_current_folder = self.total_elements[:] files_in_current_folder = gt._natural_sort(files_in_current_folder) exception = random.sample(files_in_current_folder, len(files_in_current_folder) // 5) files_in_current_folder = [ x for x in files_in_current_folder if x not in exception ] results = gt.list_elements(self.path_to_playground, sort="natural", exception=exception) self.assertEqual(results, files_in_current_folder)
def test_not_alphabetical(self): list_ = [str(i) for i in range(1000)] random.shuffle(list_) not_expected = list_[:] not_expected.sort() self.assertNotEqual(gt._natural_sort(list_), not_expected)
def test_on_numbers(self): expected = [str(i) for i in range(1000)] list_ = expected[:] random.shuffle(list_) self.assertEqual(gt._natural_sort(list_), expected)
def test_on_a_sentence(self): list_ = ["How", "do", "you", "know", "she", "is", "a", "witch", "?"] expected = ["?", "a", "do", "How", "is", "know", "she", "witch", "you"] self.assertEqual(gt._natural_sort(list_), expected)
def test_ls_with_type_dir(self): dirs_in_current_folder = self.dirs dirs_in_current_folder = gt._natural_sort(dirs_in_current_folder) results = gt.list_elements(self.path_to_playground, type_="dir") self.assertEqual(results, dirs_in_current_folder)
def test_sorted_ls(self): files_in_current_folder = self.total_elements[:] files_in_current_folder = gt._natural_sort(files_in_current_folder) results = gt.list_elements(self.path_to_playground, sort="natural") self.assertEqual(results, files_in_current_folder)