From 58adeb78bf4149ea2025a41dcf75294edb1f01cb Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sat, 1 May 2021 19:44:08 +0530 Subject: [PATCH] Fix build break --- buku | 39 +++++++++++++++++---------------------- tests/test_bukuDb.py | 11 +++++++---- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/buku b/buku index ec586e6..b075871 100755 --- a/buku +++ b/buku @@ -2219,28 +2219,23 @@ class BukuDb: print('%s exported' % count) return True - try: - outfp = open(filepath, mode='w', encoding='utf-8') - except Exception as e: - LOGERR(e) - return False - - res = {} # type: Dict - if filepath.endswith('.md'): - res = convert_bookmark_set(resultset, 'markdown') - count += res['count'] - outfp.write(res['data']) - elif filepath.endswith('.org'): - res = convert_bookmark_set(resultset, 'org') - count += res['count'] - outfp.write(res['data']) - else: - res = convert_bookmark_set(resultset, 'html') - count += res['count'] - outfp.write(res['data']) - outfp.close() - print('%s exported' % count) - return True + with open(filepath, mode='w', encoding='utf-8') as outfp: + res = {} # type: Dict + if filepath.endswith('.md'): + res = convert_bookmark_set(resultset, 'markdown') + count += res['count'] + outfp.write(res['data']) + elif filepath.endswith('.org'): + res = convert_bookmark_set(resultset, 'org') + count += res['count'] + outfp.write(res['data']) + else: + res = convert_bookmark_set(resultset, 'html') + count += res['count'] + outfp.write(res['data']) + print('%s exported' % count) + return True + return False def traverse_bm_folder(self, sublist, unique_tag, folder_name, add_parent_folder_as_tag): """Traverse bookmark folders recursively and find bookmarks. diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index 377548e..9962f8b 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -31,8 +31,11 @@ logging.basicConfig() # you need to initialize logging, otherwise you will not vcr_log = logging.getLogger("vcr") vcr_log.setLevel(logging.INFO) -TEST_TEMP_DIR_OBJ = TemporaryDirectory(prefix="bukutest_") -TEST_TEMP_DIR_PATH = TEST_TEMP_DIR_OBJ.name +def get_temp_dir_path(): + with TemporaryDirectory(prefix="bukutest_") as dir_obj: + return dir_obj + +TEST_TEMP_DIR_PATH = get_temp_dir_path() TEST_TEMP_DBDIR_PATH = os.path.join(TEST_TEMP_DIR_PATH, "buku") TEST_TEMP_DBFILE_PATH = os.path.join(TEST_TEMP_DBDIR_PATH, "bookmarks.db") MAX_SQLITE_INT = int(math.pow(2, 63) - 1) @@ -1311,8 +1314,8 @@ def firefox_db(tmpdir): tmp_zip.strpath, "wb" ) as out_file: shutil.copyfileobj(response, out_file) - zip_obj = zipfile.ZipFile(tmp_zip.strpath) - zip_obj.extractall(path=os.path.join(dir_path, "test_bukuDb")) + with zipfile.ZipFile(tmp_zip.strpath) as zip_obj: + zip_obj.extractall(path=os.path.join(dir_path, "test_bukuDb")) return ff_db_path, res_yaml_file, res_nopt_yaml_file