Changeset 1503:9d08fbe3c750


Ignore:
Timestamp:
Jun 7, 2014, 9:47:35 AM (7 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Refactored `walk` tests to avoid duplicated code.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test_real_ftp.py

    r1494 r1503  
    307307class TestWalk(RealFTPTest):
    308308
     309    def _walk_test(self, expected_result, **walk_kwargs):
     310        """Walk the directory and test results."""
     311        # Collect data using `walk`.
     312        actual_result = []
     313        for items in self.host.walk(**walk_kwargs):
     314            actual_result.append(items)
     315        # Compare with expected results.
     316        self.assertEqual(len(actual_result), len(expected_result))
     317        for index, _ in enumerate(actual_result):
     318            self.assertEqual(actual_result[index], expected_result[index])
     319
    309320    def test_walk_topdown(self):
    310321        # Preparation: build tree in directory `walk_test`.
    311         host = self.host
    312         expected = [
     322        expected_result = [
    313323          ("walk_test",
    314324           ["dir1", "dir2", "dir3"],
     
    343353           []),
    344354          ]
    345         # Collect data using `walk`.
    346         actual = []
    347         for items in host.walk("walk_test"):
    348             actual.append(items)
    349         # Compare with expected results.
    350         self.assertEqual(len(actual), len(expected))
    351         for index, _ in enumerate(actual):
    352             self.assertEqual(actual[index], expected[index])
     355        self._walk_test(expected_result, top="walk_test")
    353356
    354357    def test_walk_depth_first(self):
    355358        # Preparation: build tree in directory `walk_test`
    356         host = self.host
    357         expected = [
     359        expected_result = [
    358360          ("walk_test/dir1/dir11",
    359361           [],
     
    388390           ["file4"])
    389391          ]
    390         # Collect data using `walk`.
    391         actual = []
    392         for items in host.walk("walk_test", topdown=False):
    393             actual.append(items)
    394         # Compare with expected results.
    395         self.assertEqual(len(actual), len(expected))
    396         for index, _ in enumerate(actual):
    397             self.assertEqual(actual[index], expected[index])
     392        self._walk_test(expected_result, top="walk_test", topdown=False)
    398393
    399394
Note: See TracChangeset for help on using the changeset viewer.