@@ -0,0 +1,1814 @@
+# -*- coding: utf-8 -*-%0A%0Aimport unittest%0Aimport os%0A%0Afrom utils.web_parser import PageHandler%0A%0A%0Aclass TestWebParser(unittest.TestCase):%0A%0A    def clean_tmp_dir(self, path):%0A        os.remove(path)%0A        os.removedirs(os.path.dirname(path))%0A%0A    def test_save_file_without_dir(self):%0A        filename = 'test.txt'%0A        dirname = 'tmp'%0A        path = os.path.join(os.path.abspath('.'), dirname, filename)%0A        if os.path.exists(path):%0A            os.remove(path)%0A        if os.path.exists(os.path.dirname(path)):%0A            os.removedirs(os.path.dirname(path))%0A        test_ph = PageHandler()%0A        text = 'test save file without dir'%0A        test_ph._save_file(path, text)%0A        self.assertTrue(os.path.exists(path))%0A        self.clean_tmp_dir(path)%0A%0A    def test_save_file_without_file(self):%0A        filename = 'test.txt'%0A        dirname = 'tmp'%0A        path = os.path.join(os.path.abspath('.'), dirname, filename)%0A        if os.path.exists(path):%0A            os.remove(path)%0A        if not os.path.exists(os.path.dirname(path)):%0A            os.mkdir(os.path.dirname(path))%0A        test_ph = PageHandler()%0A        text = 'test save file without file'%0A        test_ph._save_file(path, text)%0A        self.assertTrue(os.path.exists(path))%0A        self.clean_tmp_dir(path)%0A%0A    def test_save_file_with_file_exists(self):%0A        filename = 'test.txt'%0A        dirname = 'tmp'%0A        path = os.path.join(os.path.abspath('.'), dirname, filename)%0A        if not os.path.exists(path):%0A            os.mknod(path)%0A        if not os.path.exists(os.path.dirname(path)):%0A            os.mkdir(os.path.dirname(path))%0A        test_ph = PageHandler()%0A        text = 'test save file with file exists'%0A        test_ph._save_file(path, text)%0A        self.assertTrue(os.path.exists(path))%0A        self.clean_tmp_dir(path)%0A%0A

test save_file in web_parser