From 27fa7c281be26d10a354b08b533c98c69bbcc6dd Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Mon, 8 Jul 2024 15:53:58 +0800 Subject: [PATCH 1/2] Fix E501 E266 E712 F821(change deprecated basestring to str) in test_validate, test_validators, runcontrol, test_commands.py --- regolith/runcontrol.py | 4 ++-- tests/test_commands.py | 6 ------ tests/test_validate.py | 4 ++-- tests/test_validators.py | 3 ++- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/regolith/runcontrol.py b/regolith/runcontrol.py index 597d45532..c3c3e1163 100644 --- a/regolith/runcontrol.py +++ b/regolith/runcontrol.py @@ -203,7 +203,7 @@ def _validate(self, key, value): def flatten(iterable): """Generator which returns flattened version of nested sequences.""" for el in iterable: - if isinstance(el, basestring): + if isinstance(el, str): yield el elif isinstance(el, Iterable): for subel in flatten(el): @@ -220,7 +220,7 @@ def flatten(iterable): def ishashable(x): """Tests if a value is hashable.""" if isinstance(x, Hashable): - if isinstance(x, basestring): + if isinstance(x, str): return True elif isinstance(x, Iterable): return all(map(ishashable, x)) diff --git a/tests/test_commands.py b/tests/test_commands.py index 308056ad3..f94278fa0 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -38,9 +38,6 @@ def test_mongo_to_fs_python(make_mongo_to_fs_backup_db, make_mongodb): main(["mongo-to-fs"]) except Exception as e: print(e) - assert True == False - else: - assert True == True replace_rc_dbs(repo) os.chdir(repo) rc = copy.copy(DEFAULT_RC) @@ -66,9 +63,6 @@ def test_fs_to_mongo_python(make_fs_to_mongo_migration_db, make_mongodb): main(["fs-to-mongo"]) except Exception as e: print(e) - assert True == False - else: - assert True == True replace_rc_dbs(repo) os.chdir(repo) rc = copy.copy(DEFAULT_RC) diff --git a/tests/test_validate.py b/tests/test_validate.py index 45812e977..1dccde75f 100644 --- a/tests/test_validate.py +++ b/tests/test_validate.py @@ -28,8 +28,8 @@ def test_validate_python_single_col(make_db): """ repo = make_db os.chdir(repo) - ## to see what is failing, comment out the rows that capture and restore the - ## sys.stdout. + #to see what is failing, comment out the rows that capture and restore the + # sys.stdout. backup = sys.stdout sys.stdout = StringIO() main(["validate", "--collection", "projecta"]) diff --git a/tests/test_validators.py b/tests/test_validators.py index 263151fa4..c4ee88f3a 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -77,5 +77,6 @@ def test_mongo_invalid_insertion(make_mongodb): rc.client.insert_one(only_database_in_test, "projecta", BAD_PROJECTUM) except ValueError as e: result = e.args[0] - expected = "ERROR in sb_firstprojectum:\n{'lead': ['required field'], 'status': ['required field']}\nNone\nNone\n---------------\n" + expected = ("ERROR in sb_firstprojectum:\n{'lead': ['required field'], 'status': ['required field']}" + "\nNone\nNone\n---------------\n") assert result == expected From 57c6a171a715ed8f938e79df9468664a12627d38 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Mon, 8 Jul 2024 21:18:50 +0800 Subject: [PATCH 2/2] Add assertion back and pass both flake8 test and regolith test. --- tests/test_commands.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_commands.py b/tests/test_commands.py index f94278fa0..b8a81454b 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -38,6 +38,9 @@ def test_mongo_to_fs_python(make_mongo_to_fs_backup_db, make_mongodb): main(["mongo-to-fs"]) except Exception as e: print(e) + assert False + else: + assert True replace_rc_dbs(repo) os.chdir(repo) rc = copy.copy(DEFAULT_RC) @@ -63,6 +66,9 @@ def test_fs_to_mongo_python(make_fs_to_mongo_migration_db, make_mongodb): main(["fs-to-mongo"]) except Exception as e: print(e) + assert False + else: + assert True replace_rc_dbs(repo) os.chdir(repo) rc = copy.copy(DEFAULT_RC)