From: Artem Bityutskiy Date: Wed, 3 Jul 2013 15:03:48 +0000 (+0300) Subject: tests: also comply with PEP8 for multiline comments X-Git-Tag: v2.5~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ad66b1798756a540fc5d055453bcac074136c309;p=tools%2Fbmap-tools.git tests: also comply with PEP8 for multiline comments Change-Id: Ie43d8f4e682e5b8d83aa29aeb563ce81291bd707 Signed-off-by: Artem Bityutskiy --- diff --git a/tests/helpers.py b/tests/helpers.py index 22a72fc..54c1c85 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -1,5 +1,7 @@ -""" This module contains independent functions shared between various -tests. """ +""" +This module contains independent functions shared between various +tests. +""" # Disable the following pylint recommendations: # * Too many statements (R0915) @@ -11,21 +13,24 @@ import itertools from bmaptools import BmapHelpers def _create_random_sparse_file(file_obj, size): - """ Create a sparse file with randomly distributed holes. The mapped areas - are filled with semi-random data. Returns a tuple containing 2 lists: + """ + Create a sparse file with randomly distributed holes. The mapped areas are + filled with semi-random data. Returns a tuple containing 2 lists: 1. a list of mapped block ranges, same as 'Fiemap.get_mapped_ranges()' 2. a list of unmapped block ranges (holes), same as - 'Fiemap.get_unmapped_ranges()' """ + 'Fiemap.get_unmapped_ranges()' + """ file_obj.truncate(0) block_size = BmapHelpers.get_block_size(file_obj) blocks_cnt = (size + block_size - 1) / block_size def process_block(block): - """ This is a helper function which processes a block. It randomly - decides whether the block should be filled with random data or should - become a hole. Returns 'True' if the block was mapped and 'False' - otherwise. """ + """ + This is a helper function which processes a block. It randomly decides + whether the block should be filled with random data or should become a + hole. Returns 'True' if the block was mapped and 'False' otherwise. + """ map_the_block = random.getrandbits(1) @@ -63,8 +68,9 @@ def _create_random_sparse_file(file_obj, size): return (mapped, unmapped) def _create_random_file(file_obj, size): - """ Fill the 'file_obj' file object with semi-random data up to the size - 'size'. """ + """ + Fill the 'file_obj' file object with semi-random data up to the size 'size'. + """ chunk_size = 1024 * 1024 written = 0 @@ -80,10 +86,11 @@ def _create_random_file(file_obj, size): def generate_test_files(max_size = 4 * 1024 * 1024, directory = None, delete = True): - """ This is a generator which yields files which other tests use as the - input for the testing. The generator tries to yield "interesting" files - which cover various corner-cases. For example, a large hole file, a file - with no holes, files of unaligned length, etc. + """ + This is a generator which yields files which other tests use as the input + for the testing. The generator tries to yield "interesting" files which + cover various corner-cases. For example, a large hole file, a file with + no holes, files of unaligned length, etc. The 'directory' argument specifies the directory path where the yielded test files should be created. The 'delete' argument specifies whether the @@ -94,7 +101,8 @@ def generate_test_files(max_size = 4 * 1024 * 1024, directory = None, 2. file size in bytes 3. a list of mapped block ranges, same as 'Fiemap.get_mapped_ranges()' 4. a list of unmapped block ranges (holes), same as - 'Fiemap.get_unmapped_ranges()' """ + 'Fiemap.get_unmapped_ranges()' + """ # # Generate sparse files with one single hole spanning the entire file diff --git a/tests/test_api_base.py b/tests/test_api_base.py index fd3ff96..1788d2c 100644 --- a/tests/test_api_base.py +++ b/tests/test_api_base.py @@ -1,7 +1,9 @@ -""" This test verifies the base bmap creation and copying API functionality. It +""" +This test verifies the base bmap creation and copying API functionality. It generates a random sparse file, then creates a bmap fir this file and copies it to a different file using the bmap. Then it compares the original random sparse -file and the copy and verifies that they are identical. """ +file and the copy and verifies that they are identical. +""" # Disable the following pylint recommendations: # * Too many public methods - R0904 @@ -20,13 +22,14 @@ import tests.helpers from bmaptools import BmapCreate, BmapCopy, Fiemap, TransRead class Error(Exception): - """ A class for exceptions generated by this test. """ + """A class for exceptions generated by this test.""" pass def _compare_holes(file1, file2): - """ Make sure that files 'file1' and 'file2' have holes at the same places. - The 'file1' and 'file2' arguments may be full file paths or file - objects. """ + """ + Make sure that files 'file1' and 'file2' have holes at the same places. + The 'file1' and 'file2' arguments may be full file paths or file objects. + """ fiemap1 = Fiemap.Fiemap(file1) fiemap2 = Fiemap.Fiemap(file2) @@ -41,11 +44,13 @@ def _compare_holes(file1, file2): % (range1[0], range1[1], range2[0], range2[1])) def _generate_compressed_files(file_obj, delete = True): - """ This is a generator which yields compressed versions of a file - represented by a file object 'file_obj'. + """ + This is a generator which yields compressed versions of a file represented + by a file object 'file_obj'. The 'delete' argument specifies whether the compressed files that this - generator yields have to be automatically deleted. """ + generator yields have to be automatically deleted. + """ import bz2 import gzip @@ -111,8 +116,9 @@ def _generate_compressed_files(file_obj, delete = True): tmp_file_obj.close() def _calculate_sha1(file_obj): - """ Calculates SHA1 checksum for the contents of file object - 'file_obj'. """ + """ + Calculates SHA1 checksum for the contents of file object 'file_obj'. + """ file_obj.seek(0) hash_obj = hashlib.new("sha1") @@ -128,8 +134,9 @@ def _calculate_sha1(file_obj): return hash_obj.hexdigest() def _copy_image(image, f_dest, f_bmap, image_sha1, image_size): - """ Copy image 'image' using bmap 'f_bmap' to the destination file - 'f_dest'. """ + """ + Copy image 'image' using bmap 'f_bmap' to the destination file 'f_dest'. + """ if hasattr(image, "read"): f_image = image @@ -155,14 +162,16 @@ def _copy_image(image, f_dest, f_bmap, image_sha1, image_size): f_image.close() def _do_test(f_image, image_size, delete = True): - """" A basic test for the bmap creation and copying functionality. It first + """ + A basic test for the bmap creation and copying functionality. It first generates a bmap for file object 'f_image', and then copies the sparse file to a different file, and then checks that the original file and the copy are identical. The 'image_size' argument is size of the image in bytes. The 'delete' argument specifies whether the temporary files that this function creates - have to be automatically deleted. """ + have to be automatically deleted. + """ # Make sure the temporary files start with the same name as 'f_image' in # order to simplify debugging. @@ -253,13 +262,17 @@ def _do_test(f_image, image_size, delete = True): f_bmap2.close() class TestCreateCopy(unittest.TestCase): - """ The test class for this unit tests. Basically executes the '_do_test()' - function for different sparse files. """ + """ + The test class for this unit tests. Basically executes the '_do_test()' + function for different sparse files. + """ @staticmethod def test(): - """ The test entry point. Executes the '_do_test()' function for files - of different sizes, holes distribution and format. """ + """ + The test entry point. Executes the '_do_test()' function for files of + different sizes, holes distribution and format. + """ # Delete all the test-related temporary files automatically delete = True diff --git a/tests/test_fiemap.py b/tests/test_fiemap.py index f4c6f5b..e25eaaa 100644 --- a/tests/test_fiemap.py +++ b/tests/test_fiemap.py @@ -1,5 +1,7 @@ -""" This test verifies Fiemap module functionality. It generates random sparse -files and makes sure FIEMAP returns correct information about the holes. """ +""" +This test verifies Fiemap module functionality. It generates random sparse +files and makes sure FIEMAP returns correct information about the holes. +""" # Disable the following pylint recommendations: # * Too many public methods - R0904 @@ -16,17 +18,19 @@ import tests.helpers from bmaptools import Fiemap class Error(Exception): - """ A class for exceptions generated by this test. """ + """A class for exceptions generated by this test.""" pass def _check_ranges(f_image, fiemap, first_block, blocks_cnt, ranges, ranges_type): - """ This is a helper function for '_do_test()' which compares the correct + """ + This is a helper function for '_do_test()' which compares the correct 'ranges' list of mapped or unmapped blocks ranges for file object 'f_image' with what the Fiemap module reports. The 'ranges_type' argument defines whether the 'ranges' list is a list of mapped or unmapped blocks. The 'first_block' and 'blocks_cnt' define the subset of blocks in 'f_image' - that should be verified by this function. """ + that should be verified by this function. + """ if ranges_type is "mapped": fiemap_iterator = fiemap.get_mapped_ranges(first_block, blocks_cnt) @@ -66,10 +70,12 @@ def _check_ranges(f_image, fiemap, first_block, blocks_cnt, check[0], check[1])) def _do_test(f_image, mapped, unmapped, buf_size = Fiemap.DEFAULT_BUFFER_SIZE): - """ Verify that Fiemap reports the correct mapped and unmapped areas for - the 'f_image' file object. The 'mapped' and 'unmapped' lists contain the + """ + Verify that Fiemap reports the correct mapped and unmapped areas for the + 'f_image' file object. The 'mapped' and 'unmapped' lists contain the correct ranges. The 'buf_size' argument specifies the internal buffer size - of the 'Fiemap' class. """ + of the 'Fiemap' class. + """ # Make sure that Fiemap's get_mapped_ranges() returns the same ranges as # we have in the 'mapped' list. @@ -93,13 +99,17 @@ def _do_test(f_image, mapped, unmapped, buf_size = Fiemap.DEFAULT_BUFFER_SIZE): "unmapped") class TestCreateCopy(unittest.TestCase): - """ The test class for this unit tests. Basically executes the '_do_test()' - function for different sparse files. """ + """ + The test class for this unit tests. Basically executes the '_do_test()' + function for different sparse files. + """ @staticmethod def test(): - """ The test entry point. Executes the '_do_test()' function for files - of different sizes, holes distribution and format. """ + """ + The test entry point. Executes the '_do_test()' function for files of + different sizes, holes distribution and format. + """ # Delete all the test-related temporary files automatically delete = True