[PATCH 1 of 1 Elasticsearch cube] Migrate cube to Python3

Nsukami Patrick ptrck at nskm.xyz
Mon Oct 14 14:18:31 CEST 2019


# HG changeset patch
# User Nsukami Patrick <ptrck at nskm dot xyz>
# Date 1571055427 0
#      Mon Oct 14 12:17:07 2019 +0000
# Node ID 657f15bab8a600bb9136b826da0e736ffe30a47c
# Parent  c0284229c8821000fe7e1c2d2471ec6abd80495a
Migrate cube to Python3

- Update tox.ini, add py36 env

- Fix errors:
  - TypeError: 'float' object cannot be interpreted as an integer
  - ModuleNotFoundError: No module named 'httplib'

- Fix deprecation warnings:
  - DeprecationWarning: Please use assertEqual instead
  - DeprecationWarning: Please use assertTrue instead

diff --git a/cubicweb_elasticsearch/testutils.py b/cubicweb_elasticsearch/testutils.py
--- a/cubicweb_elasticsearch/testutils.py
+++ b/cubicweb_elasticsearch/testutils.py
@@ -1,5 +1,5 @@
 import unittest
-import httplib
+import http.client
 
 from elasticsearch_dsl.connections import connections
 
@@ -34,7 +34,7 @@
     @classmethod
     def setUpClass(cls):
         try:
-            httplib.HTTPConnection('localhost:9200').request('GET', '/')
+            http.client.HTTPConnection('localhost:9200').request('GET', '/')
         except:  # noqa
             raise unittest.SkipTest(
                 'No ElasticSearch on localhost, skipping test')
diff --git a/cubicweb_elasticsearch/views.py b/cubicweb_elasticsearch/views.py
--- a/cubicweb_elasticsearch/views.py
+++ b/cubicweb_elasticsearch/views.py
@@ -228,7 +228,7 @@
                             href=xml_escape(self._cw.build_url(**url_params)))))
             else:
                 ul(t.li(t.a(self.previous_link)))
-            total_pages = min((response.hits.total / 10) + 2, 1000)
+            total_pages = min((response.hits.total // 10) + 2, 1000)
             page_padding = 3
 
             if current_page > page_padding:
diff --git a/test/test_elastic_search.py b/test/test_elastic_search.py
--- a/test/test_elastic_search.py
+++ b/test/test_elastic_search.py
@@ -64,7 +64,7 @@
             ccplugin.IndexInES(None).main_run(cmd)
         finally:
             sys.stdout = sys.__stdout__
-        self.assertEquals('', out.getvalue())
+        self.assertEqual('', out.getvalue())
         create.assert_not_called()
         bulk.assert_not_called()
 
@@ -78,7 +78,7 @@
         finally:
             sys.stdout = sys.__stdout__
         with self.admin_access.repo_cnx() as cnx:
-            self.assert_(cnx.execute('Any X WHERE X is %(etype)s' %
+            self.assertTrue(cnx.execute('Any X WHERE X is %(etype)s' %
                                      {'etype': self.tested_etype}))
         # TODO - put this somewhere where it tests on the first get_connection
         # create.assert_called_with(ignore=400,
diff --git a/tox.ini b/tox.ini
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py27,flake8
+envlist = py27,py36,flake8
 
 [tox:jenkins]
 envlist = py27,flake8-jenkins



More information about the cubicweb-devel mailing list