コード例 #1
0
    def test_write_index_file(self):
        """
        http://stackoverflow.com/questions/977491/comparing-2-txt-files-using-difflib-in-python
        http://doughellmann.com/2007/10/pymotw-difflib.html
        """
        img_urls = logpuzzle.read_urls('animal_code.google.com')
        dest_dir = './puzzle_images'
        logpuzzle.download_images(img_urls, dest_dir)

        logpuzzle.write_index_file(dest_dir)

        index_file = open('./index.html', 'r')
        result_lines = index_file.readlines()
        index_file.close()

        index_expected_file = open('./index_expected.html', 'r')
        expected_result_lines = index_expected_file.readlines()
        index_expected_file.close()

        # put expected_result_lines first, to make diff +- clearer
        diff_unified = difflib.unified_diff(expected_result_lines, result_lines, lineterm='')
        result = ('\n'.join(list(diff_unified)))
        expected_result = ''
        self.assertEqual(expected_result, result,
                             'write_index_file() expected {} but got {}'.format(expected_result, result))
        self.clean_up_image_dir()
コード例 #2
0
    def test_z_download_images(self):
        """ Choose test name alphabetically after test_write_index_file to run after it.
        """
        #img_urls = logpuzzle.read_urls('place_code.google.com')
        img_urls = logpuzzle.read_urls('animal_code.google.com')
        dest_dir = './puzzle_images'
        logpuzzle.download_images(img_urls, dest_dir)

        result = os.listdir(dest_dir)
        expected_result = ['img0.jpg', 'img1.jpg', 'img10.jpg', 'img11.jpg', 'img12.jpg', 'img13.jpg', 'img14.jpg', 'img15.jpg', 'img16.jpg', 'img17.jpg', 'img18.jpg', 'img19.jpg', 'img2.jpg', 'img3.jpg', 'img4.jpg', 'img5.jpg', 'img6.jpg', 'img7.jpg', 'img8.jpg', 'img9.jpg']
        self.assertEqual(expected_result, result,
                             'write_index_file() expected {} but got {}'.format(expected_result, result))