From 3179bcaea3b8faed2355a645f8889b7fe563715b Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn@redhat.com>
Date: Jan 26 2019 12:35:46 +0000
Subject: [PATCH 1/4] pyhbac-test: Do not use assertEquals


src/tests/pyhbac-test.py:163: DeprecationWarning: Please use assertEqual instead.
  self.assertEquals(el.__repr__(), u'<category 0 names [] groups []>')
src/tests/pyhbac-test.py:169: DeprecationWarning: Please use assertEqual instead.
  u'<category 1 names [foo] groups [bar, baz]>')

Merges: https://pagure.io/SSSD/sssd/pull-request/3927

---

diff --git a/src/tests/pyhbac-test.py b/src/tests/pyhbac-test.py
index 2b7e033..06163af 100755
--- a/src/tests/pyhbac-test.py
+++ b/src/tests/pyhbac-test.py
@@ -160,13 +160,13 @@ class PyHbacRuleElementTest(unittest.TestCase):
 
     def testRepr(self):
         el = pyhbac.HbacRuleElement()
-        self.assertEquals(el.__repr__(), u'<category 0 names [] groups []>')
+        self.assertEqual(el.__repr__(), u'<category 0 names [] groups []>')
 
         el.category.add(pyhbac.HBAC_CATEGORY_ALL)
         el.names = ['foo']
         el.groups = ['bar, baz']
-        self.assertEquals(el.__repr__(),
-                          u'<category 1 names [foo] groups [bar, baz]>')
+        self.assertEqual(el.__repr__(),
+                         u'<category 1 names [foo] groups [bar, baz]>')
 
 
 class PyHbacRuleTest(unittest.TestCase):

From 1cc55d90f74411ef6979ddee42711e4ec4532444 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn@redhat.com>
Date: Jan 26 2019 12:35:46 +0000
Subject: [PATCH 2/4] SSSDConfigTest: Do not use assertEquals


src/config/SSSDConfigTest.py:88: DeprecationWarning: Please use assertEqual instead.
  self.assertEquals(new_options['debug_level'][0], int)
src/config/SSSDConfigTest.py:91: DeprecationWarning: Please use assertEqual instead.
  self.assertEquals(new_options['command'][0], str)
src/config/SSSDConfigTest.py:94: DeprecationWarning: Please use assertEqual instead.
  self.assertEquals(new_options['reconnection_retries'][0], int)

+ many more

Merges: https://pagure.io/SSSD/sssd/pull-request/3927

---

diff --git a/src/config/SSSDConfigTest.py b/src/config/SSSDConfigTest.py
index 3bcb965..8b5a167 100755
--- a/src/config/SSSDConfigTest.py
+++ b/src/config/SSSDConfigTest.py
@@ -85,36 +85,36 @@ class SSSDConfigTestValid(unittest.TestCase):
         new_options = new_sssd_service.list_options();
 
         self.assertTrue('debug_level' in new_options)
-        self.assertEquals(new_options['debug_level'][0], int)
+        self.assertEqual(new_options['debug_level'][0], int)
 
         self.assertTrue('command' in new_options)
-        self.assertEquals(new_options['command'][0], str)
+        self.assertEqual(new_options['command'][0], str)
 
         self.assertTrue('reconnection_retries' in new_options)
-        self.assertEquals(new_options['reconnection_retries'][0], int)
+        self.assertEqual(new_options['reconnection_retries'][0], int)
 
         self.assertTrue('services' in new_options)
-        self.assertEquals(new_options['debug_level'][0], int)
+        self.assertEqual(new_options['debug_level'][0], int)
 
         self.assertTrue('domains' in new_options)
-        self.assertEquals(new_options['domains'][0], list)
-        self.assertEquals(new_options['domains'][1], str)
+        self.assertEqual(new_options['domains'][0], list)
+        self.assertEqual(new_options['domains'][1], str)
 
         self.assertTrue('sbus_timeout' in new_options)
-        self.assertEquals(new_options['sbus_timeout'][0], int)
+        self.assertEqual(new_options['sbus_timeout'][0], int)
 
         self.assertTrue('re_expression' in new_options)
-        self.assertEquals(new_options['re_expression'][0], str)
+        self.assertEqual(new_options['re_expression'][0], str)
 
         self.assertTrue('full_name_format' in new_options)
-        self.assertEquals(new_options['full_name_format'][0], str)
+        self.assertEqual(new_options['full_name_format'][0], str)
 
         self.assertTrue('default_domain_suffix' in new_options)
-        self.assertEquals(new_options['default_domain_suffix'][0], str)
+        self.assertEqual(new_options['default_domain_suffix'][0], str)
 
         self.assertTrue('domain_resolution_order' in new_options)
-        self.assertEquals(new_options['domain_resolution_order'][0], list)
-        self.assertEquals(new_options['domain_resolution_order'][1], str)
+        self.assertEqual(new_options['domain_resolution_order'][0], list)
+        self.assertEqual(new_options['domain_resolution_order'][1], str)
 
         del sssdconfig
 
@@ -1127,15 +1127,15 @@ class SSSDConfigTestSSSDDomain(unittest.TestCase):
         domain.set_option('krb5_realm', 'EXAMPLE.COM')
         domain.set_option('ldap_uri', 'ldap://ldap.example.com')
 
-        self.assertEquals(domain.get_option('krb5_realm'),
-                          'EXAMPLE.COM')
-        self.assertEquals(domain.get_option('ldap_uri'),
-                          'ldap://ldap.example.com')
+        self.assertEqual(domain.get_option('krb5_realm'),
+                         'EXAMPLE.COM')
+        self.assertEqual(domain.get_option('ldap_uri'),
+                         'ldap://ldap.example.com')
 
         # Remove the LDAP provider and verify that krb5_realm remains
         domain.remove_provider('id')
-        self.assertEquals(domain.get_option('krb5_realm'),
-                  'EXAMPLE.COM')
+        self.assertEqual(domain.get_option('krb5_realm'),
+                         'EXAMPLE.COM')
         self.assertFalse('ldap_uri' in domain.options)
 
         # Put the LOCAL provider back
@@ -1914,7 +1914,7 @@ class SSSDConfigTestSSSDConfig(unittest.TestCase):
         self.assertFalse('example.com' in sssdconfig.list_active_domains())
         self.assertFalse('example.com' in sssdconfig.list_inactive_domains())
         self.assertFalse(sssdconfig.has_section('domain/example.com'))
-        self.assertEquals(domain.oldname, None)
+        self.assertEqual(domain.oldname, None)
 
         # Positive test - Set the domain inactive and save it
         activelist = sssdconfig.list_active_domains()
@@ -1926,10 +1926,10 @@ class SSSDConfigTestSSSDConfig(unittest.TestCase):
         self.assertFalse('example.com2' in sssdconfig.list_active_domains())
         self.assertTrue('example.com2' in sssdconfig.list_inactive_domains())
 
-        self.assertEquals(len(sssdconfig.list_active_domains()),
-                          len(activelist)-1)
-        self.assertEquals(len(sssdconfig.list_inactive_domains()),
-                          len(inactivelist)+1)
+        self.assertEqual(len(sssdconfig.list_active_domains()),
+                         len(activelist)-1)
+        self.assertEqual(len(sssdconfig.list_inactive_domains()),
+                         len(inactivelist)+1)
 
         # Positive test - Set the domain active and save it
         activelist = sssdconfig.list_active_domains()
@@ -1940,10 +1940,10 @@ class SSSDConfigTestSSSDConfig(unittest.TestCase):
         self.assertTrue('example.com2' in sssdconfig.list_active_domains())
         self.assertFalse('example.com2' in sssdconfig.list_inactive_domains())
 
-        self.assertEquals(len(sssdconfig.list_active_domains()),
-                          len(activelist)+1)
-        self.assertEquals(len(sssdconfig.list_inactive_domains()),
-                          len(inactivelist)-1)
+        self.assertEqual(len(sssdconfig.list_active_domains()),
+                         len(activelist)+1)
+        self.assertEqual(len(sssdconfig.list_inactive_domains()),
+                         len(inactivelist)-1)
 
         # Positive test - Set the domain inactive and save it
         activelist = sssdconfig.list_active_domains()
@@ -1954,10 +1954,10 @@ class SSSDConfigTestSSSDConfig(unittest.TestCase):
         self.assertFalse('example.com2' in sssdconfig.list_active_domains())
         self.assertTrue('example.com2' in sssdconfig.list_inactive_domains())
 
-        self.assertEquals(len(sssdconfig.list_active_domains()),
-                          len(activelist)-1)
-        self.assertEquals(len(sssdconfig.list_inactive_domains()),
-                          len(inactivelist)+1)
+        self.assertEqual(len(sssdconfig.list_active_domains()),
+                         len(activelist)-1)
+        self.assertEqual(len(sssdconfig.list_inactive_domains()),
+                         len(inactivelist)+1)
 
         # Positive test - Set the domain active and save it
         activelist = sssdconfig.list_active_domains()
@@ -1968,10 +1968,10 @@ class SSSDConfigTestSSSDConfig(unittest.TestCase):
         self.assertTrue('example.com2' in sssdconfig.list_active_domains())
         self.assertFalse('example.com2' in sssdconfig.list_inactive_domains())
 
-        self.assertEquals(len(sssdconfig.list_active_domains()),
-                          len(activelist)+1)
-        self.assertEquals(len(sssdconfig.list_inactive_domains()),
-                          len(inactivelist)-1)
+        self.assertEqual(len(sssdconfig.list_active_domains()),
+                         len(activelist)+1)
+        self.assertEqual(len(sssdconfig.list_inactive_domains()),
+                         len(inactivelist)-1)
 
         # Positive test - Ensure that saved domains retain values
         domain.set_option('ldap_krb5_init_creds', True)

From 9e3368e38edd01265b97bed4882a153cbae66104 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn@redhat.com>
Date: Jan 26 2019 12:35:46 +0000
Subject: [PATCH 3/4] SSSDConfig: Fix ResourceWarning unclosed file


/usr/lib64/python3.7/unittest/case.py:763:
    ResourceWarning: unclosed file <_io.TextIOWrapper name='src/config/testconfigs/sssd-invalid.conf'
                                    mode='r' encoding='UTF-8'>
  context = None
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/usr/lib64/python3.7/unittest/case.py:763:
    ResourceWarning: unclosed file <_io.TextIOWrapper name='src/config/testconfigs/noparse.api.conf'
                                    mode='r' encoding='UTF-8'>
  context = None
ResourceWarning: Enable tracemalloc to get the object allocation traceback

Merges: https://pagure.io/SSSD/sssd/pull-request/3927

---

diff --git a/src/config/SSSDConfig/__init__.py.in b/src/config/SSSDConfig/__init__.py.in
index a20157c..5651a40 100644
--- a/src/config/SSSDConfig/__init__.py.in
+++ b/src/config/SSSDConfig/__init__.py.in
@@ -500,16 +500,14 @@ class SSSDConfigSchema(SSSDChangeConf):
             schemaplugindir = '@datadir@/sssd/sssd.api.d'
 
         try:
-            #Read the primary config file
-            fd = open(schemafile, 'r')
-            self.readfp(fd)
-            fd.close()
+            # Read the primary config file
+            with open(schemafile, 'r') as fd:
+                self.readfp(fd)
             # Read in the provider files
             for file in filter(lambda f: re.search(r'^sssd-.*\.conf$', f),
                                          os.listdir(schemaplugindir)):
-                fd = open(schemaplugindir+ "/" + file)
-                self.readfp(fd)
-                fd.close()
+                with open(schemaplugindir+ "/" + file) as fd:
+                    self.readfp(fd)
         except IOError:
             raise
         except SyntaxError: # can be raised with readfp
@@ -1452,14 +1450,12 @@ class SSSDConfig(SSSDChangeConf):
             #TODO: get this from a global setting
             configfile = '@sysconfdir@/sssd/sssd.conf'
         # open will raise an IOError if it fails
-        fd = open(configfile, 'r')
-
-        try:
-            self.readfp(fd)
-        except:
-            raise ParsingError
+        with open(configfile, 'r') as fd:
+            try:
+                self.readfp(fd)
+            except:
+                raise ParsingError
 
-        fd.close()
         self.configfile = configfile
         self.initialized = True
 
@@ -1523,10 +1519,9 @@ class SSSDConfig(SSSDChangeConf):
 
         # open() will raise IOError if it fails
         old_umask = os.umask(0o177)
-        of = open(outputfile, "wb")
-        output = self.dump(self.opts).encode('utf-8')
-        of.write(output)
-        of.close()
+        with open(outputfile, "wb") as of:
+            output = self.dump(self.opts).encode('utf-8')
+            of.write(output)
         os.umask(old_umask)
 
     def list_active_services(self):

From 283ebce0ff0f518a9afee05ee071a704e7265245 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn@redhat.com>
Date: Jan 26 2019 12:35:46 +0000
Subject: [PATCH 4/4] SSSDConfigTest: Remove usage of failUnless


src/config/SSSDConfigTest.py:1855: DeprecationWarning: Please use assertTrue instead.
  self.failUnless(domain.get_name() in sssdconfig.list_domains())
src/config/SSSDConfigTest.py:1856: DeprecationWarning: Please use assertTrue instead.
  self.failUnless(domain.get_name() in sssdconfig.list_inactive_domains())
src/config/SSSDConfigTest.py:1585: DeprecationWarning: Please use assertTrue instead.
  self.failUnless(service.get_name() in sssdconfig.list_services())

Merges: https://pagure.io/SSSD/sssd/pull-request/3927

---

diff --git a/src/config/SSSDConfigTest.py b/src/config/SSSDConfigTest.py
index 8b5a167..727df71 100755
--- a/src/config/SSSDConfigTest.py
+++ b/src/config/SSSDConfigTest.py
@@ -1582,7 +1582,7 @@ class SSSDConfigTestSSSDConfig(unittest.TestCase):
         # First need to remove the existing service
         sssdconfig.delete_service('sssd')
         service = sssdconfig.new_service('sssd')
-        self.failUnless(service.get_name() in sssdconfig.list_services())
+        self.assertTrue(service.get_name() in sssdconfig.list_services())
 
         # TODO: check that the values of this new service
         # are set to the defaults from the schema
@@ -1852,8 +1852,8 @@ class SSSDConfigTestSSSDConfig(unittest.TestCase):
         # Positive Test
         domain = sssdconfig.new_domain('example.com')
         self.assertTrue(isinstance(domain, SSSDConfig.SSSDDomain))
-        self.failUnless(domain.get_name() in sssdconfig.list_domains())
-        self.failUnless(domain.get_name() in sssdconfig.list_inactive_domains())
+        self.assertTrue(domain.get_name() in sssdconfig.list_domains())
+        self.assertTrue(domain.get_name() in sssdconfig.list_inactive_domains())
 
         # TODO: check that the values of this new domain
         # are set to the defaults from the schema

