From: Waldemar Kozaczuk <[email protected]>
Committer: Waldemar Kozaczuk <[email protected]>
Branch: master

scripts: upgrade to python 3 - part 2

This is the second batch of the python 3 upgrade changes.
This one focuces on httpserver API unit tests and most changes
revolve around changes to urllib.* modules.

The scripts have been tested by runnin following tests in
the root of the modules/httpserver-api directory:

- make check-http
- make check-ssl

Ref #1056

Signed-off-by: Waldemar Kozaczuk <[email protected]>

---
diff --git a/modules/httpserver-api/json2code.py 
b/modules/httpserver-api/json2code.py
--- a/modules/httpserver-api/json2code.py
+++ b/modules/httpserver-api/json2code.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 import json
 import sys
 import re
diff --git a/modules/httpserver-api/tests/api/testenv.py 
b/modules/httpserver-api/tests/api/testenv.py
--- a/modules/httpserver-api/tests/api/testenv.py
+++ b/modules/httpserver-api/tests/api/testenv.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 import basetest
 
 class testenv(basetest.Basetest):
diff --git a/modules/httpserver-api/tests/api/testfile.py 
b/modules/httpserver-api/tests/api/testfile.py
--- a/modules/httpserver-api/tests/api/testfile.py
+++ b/modules/httpserver-api/tests/api/testfile.py
@@ -1,6 +1,6 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 import os
-import urllib
+import urllib.request, urllib.parse, urllib.error
 import basetest
 import subprocess
 
@@ -45,10 +45,10 @@ def test_file_status_cmd(self):
 
     def test_put_file_cmd(self):
         path = "/file"
-        self.curl(path + 
"/etc/hosts?op=COPY&destination="+urllib.quote("/etc/hosts1"), method='PUT')
+        self.curl(path + 
"/etc/hosts?op=COPY&destination="+urllib.parse.quote("/etc/hosts1"), 
method='PUT')
         hosts = self.curl(path + "/etc/hosts1?op=GETFILESTATUS")
         self.assertEqual(hosts["type"], "FILE")
-        self.curl(path + 
"/etc/hosts1?op=RENAME&destination="+urllib.quote("/etc/hosts2"), method='PUT')
+        self.curl(path + 
"/etc/hosts1?op=RENAME&destination="+urllib.parse.quote("/etc/hosts2"), 
method='PUT')
         hosts = self.curl(path + "/etc/hosts2?op=GETFILESTATUS")
         self.assertEqual(hosts["type"], "FILE")
         self.assertHttpError(path + "/etc/hosts1?op=GETFILESTATUS")
diff --git a/modules/httpserver-api/tests/api/testfs.py 
b/modules/httpserver-api/tests/api/testfs.py
--- a/modules/httpserver-api/tests/api/testfs.py
+++ b/modules/httpserver-api/tests/api/testfs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 import basetest
 
 class testfs(basetest.Basetest):
diff --git a/modules/httpserver-api/tests/api/testjolokia.py 
b/modules/httpserver-api/tests/api/testjolokia.py
--- a/modules/httpserver-api/tests/api/testjolokia.py
+++ b/modules/httpserver-api/tests/api/testjolokia.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 import basetest
 import json
 
diff --git a/modules/httpserver-api/tests/api/testjvm.py 
b/modules/httpserver-api/tests/api/testjvm.py
--- a/modules/httpserver-api/tests/api/testjvm.py
+++ b/modules/httpserver-api/tests/api/testjvm.py
@@ -1,7 +1,7 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 import time
 import basetest
-import urllib
+import urllib.request, urllib.parse, urllib.error
 
 class testjvm(basetest.Basetest):
     def test_jvm_version(self):
@@ -31,14 +31,14 @@ def test_get_mbeans(self):
 
     def test_get_mbean(self):
         mbean = self.curl(self.path_by_nick(self.jvm_api, "getMbeanList") +
-                       urllib.quote("java.lang:name=PS Old 
Gen,type=MemoryPool"))
+                       urllib.parse.quote("java.lang:name=PS Old 
Gen,type=MemoryPool"))
         self.assertGreaterEqual(len(mbean), 15)
         self.assert_key_in("type", mbean[0])
         self.assert_key_in("name", mbean[0])
         self.assert_key_in("value", mbean[0])
 
     def test_set_mbean(self):
-        path = self.path_by_nick(self.jvm_api, "getMbeanList") + 
urllib.quote("java.lang:name=PS Old Gen,type=MemoryPool")
+        path = self.path_by_nick(self.jvm_api, "getMbeanList") + 
urllib.parse.quote("java.lang:name=PS Old Gen,type=MemoryPool")
         mbean = self.curl(path)
         usage = next((item for item in mbean if item["name"] == 
"UsageThreshold"), None)
         self.assertTrue(usage != None)
diff --git a/modules/httpserver-api/tests/api/testnetwork.py 
b/modules/httpserver-api/tests/api/testnetwork.py
--- a/modules/httpserver-api/tests/api/testnetwork.py
+++ b/modules/httpserver-api/tests/api/testnetwork.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 import time
 import basetest
 
diff --git a/modules/httpserver-api/tests/api/testos.py 
b/modules/httpserver-api/tests/api/testos.py
--- a/modules/httpserver-api/tests/api/testos.py
+++ b/modules/httpserver-api/tests/api/testos.py
@@ -1,11 +1,11 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 import time
 import basetest
 
 class testos(basetest.Basetest):
     def test_os_version(self):
         path = self.path_by_nick(self.os_api, "os_version")
-        self.assertRegexpMatches(self.curl(path), 
r"v0\.\d+(-rc\d+)?(-\d+-[0-9a-z]+)?" , path)
+        self.assertRegex(self.curl(path), r"v0\.\d+(-rc\d+)?(-\d+-[0-9a-z]+)?" 
, path)
 
     def test_vendor(self):
         self.validate_path(self.os_api, "os_vendor", "Cloudius Systems")
@@ -18,8 +18,8 @@ def test_os_uptime(self):
 
     def test_os_date(self):
         path = self.path_by_nick(self.os_api, "os_date")
-        val = self.curl(path).encode('ascii', 'ignore')
-        self.assertRegexpMatches(val, 
"...\\s+...\\s+\\d+\\s+\\d\\d:\\d\\d:\\d\\d\\s+UTC\\s+20..", path)
+        val = self.curl(path)
+        self.assertRegex(val, 
"...\\s+...\\s+\\d+\\s+\\d\\d:\\d\\d:\\d\\d\\s+UTC\\s+20..", path)
 
     def test_os_total_memory(self):
         path = self.path_by_nick(self.os_api, "os_memory_total")
diff --git a/modules/httpserver-api/tests/api/testtrace.py 
b/modules/httpserver-api/tests/api/testtrace.py
--- a/modules/httpserver-api/tests/api/testtrace.py
+++ b/modules/httpserver-api/tests/api/testtrace.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 import basetest
 
 class testtrace(basetest.Basetest):
@@ -17,14 +17,12 @@ def check_status_list(self, list):
 
     def test_get_status(self):
         status = self.curl(self.path + "/status")
-        self.assertGreaterEqual(status, 0)
         self.check_status_list(status)
 
     def test_set_status(self):
         for bt in [True, False]:
             for en in [True, False]:
                 status = self.curl(self.path + '/status?enabled=' + str(en) + 
'&backtrace=' + str(bt), method='POST')
-                self.assertGreaterEqual(status, 0)
                 self.check_status_list(status)
                 status = self.curl(self.path + "/status")
                 for s in status:
diff --git a/modules/httpserver-api/tests/basetest.py 
b/modules/httpserver-api/tests/basetest.py
--- a/modules/httpserver-api/tests/basetest.py
+++ b/modules/httpserver-api/tests/basetest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 import json
 import os
 import subprocess
@@ -33,7 +33,7 @@ def get_json_api(cls, name):
 
     @classmethod
     def get_json_api_from_directory(cls, directory, name):
-       json_data = open(os.path.join(directory, name))
+        json_data = open(os.path.join(directory, name))
         data = json.load(json_data)
         json_data.close()
         return data
@@ -83,7 +83,7 @@ def validate_path(self, api_definition, nickname, value):
 
     def validate_path_regex(self, api_definition, nickname, expr):
         path = self.path_by_nick(api_definition, nickname)
-        self.assertRegexpMatches(self.curl(path), expr)
+        self.assertRegex(self.curl(path), expr)
 
     def assertHttpError(self, url, code=404):
         try:
diff --git a/modules/httpserver-api/tests/testhttpserver-api.py 
b/modules/httpserver-api/tests/testhttpserver-api.py
--- a/modules/httpserver-api/tests/testhttpserver-api.py
+++ b/modules/httpserver-api/tests/testhttpserver-api.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 import sys
 import argparse
 import os

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/0000000000009ac28b059f19e3fd%40google.com.

Reply via email to