>From 4acc241b2d820bba97dbfe9cbb490885e201449f Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Tue, 4 Aug 2015 13:27:22 +0200 Subject: [PATCH 1/2] intg: Modernize 'except' clauses The 'as' syntax works from Python 2 on, and Python 3 dropped the "comma" syntax. --- src/tests/intg/ds_openldap.py | 2 +- src/tests/intg/ent.py | 16 +++++----- src/tests/intg/ent_test.py | 74 +++++++++++++++++++++---------------------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/tests/intg/ds_openldap.py b/src/tests/intg/ds_openldap.py index c58e53a2a76f2134eef0800634a7c8d4d1d451b5..42a2c9003af77cb4b6eb27673f626903b57c7fbe 100644 --- a/src/tests/intg/ds_openldap.py +++ b/src/tests/intg/ds_openldap.py @@ -271,7 +271,7 @@ class DSOpenLDAP(DS): if ++attempt > 30: raise Exception("Failed to stop slapd") time.sleep(1) - except IOError, e: + except IOError as e: if e.errno != errno.ENOENT: raise diff --git a/src/tests/intg/ent.py b/src/tests/intg/ent.py index 13feaaf040f2c9a207d106709fd54198b8161cac..b3c412122179127e997d295573e7a582dfcd5f40 100644 --- a/src/tests/intg/ent.py +++ b/src/tests/intg/ent.py @@ -206,7 +206,7 @@ def assert_passwd_by_name(name, pattern): """Assert a passwd entry, retrieved by name, matches a pattern.""" try: ent = get_passwd_by_name(name) - except KeyError, err: + except KeyError as err: assert False, err d = _diff(ent, pattern) assert not d, d @@ -215,7 +215,7 @@ def assert_passwd_by_uid(uid, pattern): """Assert a passwd entry, retrieved by UID, matches a pattern.""" try: ent = get_passwd_by_uid(uid) - except KeyError, err: + except KeyError as err: assert False, err d = _diff(ent, pattern) assert not d, d @@ -241,7 +241,7 @@ def _diff_each_passwd_by_name(pattern_dict): """ try: ent = dict((k, get_passwd_by_name(k)) for k in pattern_dict.keys()) - except KeyError, err: + except KeyError as err: return str(err) return _diff(ent, pattern_dict, _PASSWD_LIST_DESC) @@ -252,7 +252,7 @@ def _diff_each_passwd_by_uid(pattern_dict): """ try: ent = dict((k, get_passwd_by_uid(k)) for k in pattern_dict.keys()) - except KeyError, err: + except KeyError as err: return str(err) return _diff(ent, pattern_dict, _PASSWD_LIST_DESC) @@ -349,7 +349,7 @@ def assert_group_by_name(name, pattern): """Assert a group entry, retrieved by name, matches a pattern.""" try: ent = get_group_by_name(name) - except KeyError, err: + except KeyError as err: assert False, err d = _diff(ent, pattern, _GROUP_DESC) assert not d, d @@ -358,7 +358,7 @@ def assert_group_by_gid(gid, pattern): """Assert a group entry, retrieved by GID, matches a pattern.""" try: ent = get_group_by_gid(gid) - except KeyError, err: + except KeyError as err: assert False, err d = _diff(ent, pattern, _GROUP_DESC) assert not d, d @@ -384,7 +384,7 @@ def _diff_each_group_by_name(pattern_dict): """ try: ent = dict((k, get_group_by_name(k)) for k in pattern_dict.keys()) - except KeyError, err: + except KeyError as err: return str(err) return _diff(ent, pattern_dict, _GROUP_LIST_DESC) @@ -395,7 +395,7 @@ def _diff_each_group_by_gid(pattern_dict): """ try: ent = dict((k, get_group_by_gid(k)) for k in pattern_dict.keys()) - except KeyError, err: + except KeyError as err: return str(err) return _diff(ent, pattern_dict, _GROUP_LIST_DESC) diff --git a/src/tests/intg/ent_test.py b/src/tests/intg/ent_test.py index 896fcbe14f4663675577eee803ed80e2ce09cee3..a50e82dd56a9d94c3be74db96a963cf39496c5b5 100644 --- a/src/tests/intg/ent_test.py +++ b/src/tests/intg/ent_test.py @@ -102,13 +102,13 @@ def test_assert_passwd_by_name(users_and_groups): try: ent.assert_passwd_by_name("user3", {}) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'getpwnam(): name not found: user3'" try: ent.assert_passwd_by_name("user2", dict(name="user1")) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'name' mismatch: 'user1' != 'user2'" def test_assert_passwd_by_uid(users_and_groups): @@ -119,13 +119,13 @@ def test_assert_passwd_by_uid(users_and_groups): try: ent.assert_passwd_by_uid(1003, {}) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'getpwuid(): uid not found: 1003'" try: ent.assert_passwd_by_uid(1002, dict(name="user1")) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'name' mismatch: 'user1' != 'user2'" @@ -136,13 +136,13 @@ def test_assert_passwd_list(users_and_groups): try: ent.assert_passwd_list(ent.contains_only()) assert False - except AssertionError, e: + except AssertionError as e: assert not re.search("expected users not found:", str(e)) assert re.search("unexpected users found:", str(e)) try: ent.assert_passwd_list(ent.contains(dict(name="non_existent"))) assert False - except AssertionError, e: + except AssertionError as e: assert re.search("expected users not found:", str(e)) assert not re.search("unexpected users found:", str(e)) @@ -153,12 +153,12 @@ def test_assert_each_passwd_by_name(users_and_groups): try: ent.assert_each_passwd_by_name(dict(user3={})) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'getpwnam(): name not found: user3'" try: ent.assert_each_passwd_by_name(dict(user1=dict(name="user2"))) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == \ "user 'user1' mismatch: 'name' mismatch: 'user2' != 'user1'" @@ -169,12 +169,12 @@ def test_assert_each_passwd_by_uid(users_and_groups): try: ent.assert_each_passwd_by_uid({1003:{}}) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'getpwuid(): uid not found: 1003'" try: ent.assert_each_passwd_by_uid({1001:dict(uid=1002)}) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == \ "user 1001 mismatch: 'uid' mismatch: 1002 != 1001" @@ -185,12 +185,12 @@ def test_assert_each_passwd_with_name(users_and_groups): try: ent.assert_each_passwd_with_name([dict(name="user3")]) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'getpwnam(): name not found: user3'" try: ent.assert_each_passwd_with_name([dict(name="user1", uid=1002)]) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == \ "user 'user1' mismatch: 'uid' mismatch: 1002 != 1001" @@ -201,12 +201,12 @@ def test_assert_each_passwd_with_uid(users_and_groups): try: ent.assert_each_passwd_with_uid([dict(uid=1003)]) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'getpwuid(): uid not found: 1003'" try: ent.assert_each_passwd_with_uid([dict(name="user2", uid=1001)]) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == \ "user 1001 mismatch: 'name' mismatch: 'user2' != 'user1'" @@ -217,14 +217,14 @@ def test_assert_passwd(users_and_groups): try: ent.assert_passwd(ent.contains(dict(name="user3", uid=1003))) assert False - except AssertionError, e: + except AssertionError as e: assert re.search("list mismatch:", str(e)) assert re.search("expected users not found:", str(e)) assert not re.search("unexpected users found:", str(e)) try: ent.assert_passwd(ent.contains_only(USER1)) assert False - except AssertionError, e: + except AssertionError as e: assert re.search("list mismatch:", str(e)) assert not re.search("expected users not found:", str(e)) assert re.search("unexpected users found:", str(e)) @@ -235,7 +235,7 @@ def test_group_member_matching(users_and_groups): try: ent.assert_group_by_name("empty_group", dict(mem=ent.contains("user1"))) - except AssertionError, e: + except AssertionError as e: assert re.search("member list mismatch:", str(e)) assert re.search("expected members not found:", str(e)) @@ -247,21 +247,21 @@ def test_group_member_matching(users_and_groups): try: ent.assert_group_by_name("one_user_group1", dict(mem=ent.contains_only())) - except AssertionError, e: + except AssertionError as e: assert re.search("member list mismatch:", str(e)) assert re.search("unexpected members found:", str(e)) assert not re.search("expected members not found:", str(e)) try: ent.assert_group_by_name("one_user_group1", dict(mem=ent.contains_only("user3"))) - except AssertionError, e: + except AssertionError as e: assert re.search("member list mismatch:", str(e)) assert re.search("unexpected members found:", str(e)) assert re.search("expected members not found:", str(e)) try: ent.assert_group_by_name("one_user_group1", dict(mem=ent.contains("user3"))) - except AssertionError, e: + except AssertionError as e: assert re.search("member list mismatch:", str(e)) assert not re.search("unexpected members found:", str(e)) assert re.search("expected members not found:", str(e)) @@ -276,7 +276,7 @@ def test_group_member_matching(users_and_groups): try: ent.assert_group_by_name("two_user_group", dict(mem=ent.contains_only("user1"))) - except AssertionError, e: + except AssertionError as e: assert re.search("member list mismatch:", str(e)) assert re.search("unexpected members found:", str(e)) assert not re.search("expected members not found:", str(e)) @@ -289,13 +289,13 @@ def test_assert_group_by_name(users_and_groups): try: ent.assert_group_by_name("group3", {}) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'getgrnam(): name not found: group3'" try: ent.assert_group_by_name("group2", dict(name="group1")) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'name' mismatch: 'group1' != 'group2'" def test_assert_group_by_gid(users_and_groups): @@ -306,13 +306,13 @@ def test_assert_group_by_gid(users_and_groups): try: ent.assert_group_by_gid(2003, {}) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'getgrgid(): gid not found: 2003'" try: ent.assert_group_by_gid(2002, dict(name="group1")) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'name' mismatch: 'group1' != 'group2'" @@ -323,13 +323,13 @@ def test_assert_group_list(users_and_groups): try: ent.assert_group_list(ent.contains_only()) assert False - except AssertionError, e: + except AssertionError as e: assert not re.search("expected groups not found:", str(e)) assert re.search("unexpected groups found:", str(e)) try: ent.assert_group_list(ent.contains(dict(name="non_existent"))) assert False - except AssertionError, e: + except AssertionError as e: assert re.search("expected groups not found:", str(e)) assert not re.search("unexpected groups found:", str(e)) @@ -340,12 +340,12 @@ def test_assert_each_group_by_name(users_and_groups): try: ent.assert_each_group_by_name(dict(group3={})) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'getgrnam(): name not found: group3'" try: ent.assert_each_group_by_name(dict(group1=dict(name="group2"))) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "group 'group1' mismatch: " + \ "'name' mismatch: 'group2' != 'group1'" @@ -356,12 +356,12 @@ def test_assert_each_group_by_gid(users_and_groups): try: ent.assert_each_group_by_gid({2003:{}}) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'getgrgid(): gid not found: 2003'" try: ent.assert_each_group_by_gid({2001:dict(gid=2002)}) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == \ "group 2001 mismatch: 'gid' mismatch: 2002 != 2001" @@ -372,12 +372,12 @@ def test_assert_each_group_with_name(users_and_groups): try: ent.assert_each_group_with_name([dict(name="group3")]) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'getgrnam(): name not found: group3'" try: ent.assert_each_group_with_name([dict(name="group1", gid=2002)]) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == \ "group 'group1' mismatch: 'gid' mismatch: 2002 != 2001" @@ -388,12 +388,12 @@ def test_assert_each_group_with_gid(users_and_groups): try: ent.assert_each_group_with_gid([dict(gid=2003)]) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == "'getgrgid(): gid not found: 2003'" try: ent.assert_each_group_with_gid([dict(name="group2", gid=2001)]) assert False - except AssertionError, e: + except AssertionError as e: assert str(e) == \ "group 2001 mismatch: 'name' mismatch: 'group2' != 'group1'" @@ -404,14 +404,14 @@ def test_assert_group(users_and_groups): try: ent.assert_group(ent.contains(dict(name="group3", gid=2003))) assert False - except AssertionError, e: + except AssertionError as e: assert re.search("list mismatch:", str(e)) assert re.search("expected groups not found:", str(e)) assert not re.search("unexpected groups found:", str(e)) try: ent.assert_group(ent.contains_only(GROUP1)) assert False - except AssertionError, e: + except AssertionError as e: assert re.search("list mismatch:", str(e)) assert not re.search("expected groups not found:", str(e)) assert re.search("unexpected groups found:", str(e)) -- 2.5.0