[PATCH V2] Organize python imports

Follow this rule: 1) Import common modules import ... import ... from ... import ... from ... import ... 2) Import kimchi modules import kimchi.<mod> import kimchi.<mod> from kimchi import ... from kimchi import ... Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- plugins/sample/__init__.py | 8 ++++++-- plugins/sample/model.py | 2 +- src/kimchi/model.py | 4 ++-- src/kimchi/server.py | 2 +- src/kimchi/sslcert.py | 2 +- tests/test_exception.py | 8 +++++--- tests/test_mockmodel.py | 6 ++++-- tests/test_model.py | 19 +++++++++++-------- tests/test_networkxml.py | 4 +++- tests/test_osinfo.py | 5 ++++- tests/test_plugin.py | 6 +++++- tests/test_rest.py | 12 +++++++++--- tests/test_server.py | 4 ++-- tests/test_vmtemplate.py | 4 +++- tests/utils.py | 15 +++++++++------ 15 files changed, 66 insertions(+), 35 deletions(-) diff --git a/plugins/sample/__init__.py b/plugins/sample/__init__.py index a20f5e6..7064904 100644 --- a/plugins/sample/__init__.py +++ b/plugins/sample/__init__.py @@ -22,12 +22,16 @@ import json import os + + from cherrypy import expose -from kimchi.controller import Resource, Collection + + +from kimchi.controller import Collection, Resource from model import Model -model = Model() +model = Model() class Drawings(Resource): def __init__(self): diff --git a/plugins/sample/model.py b/plugins/sample/model.py index f6da5d0..9a2f22f 100644 --- a/plugins/sample/model.py +++ b/plugins/sample/model.py @@ -20,7 +20,7 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -from kimchi.exception import NotFoundError, InvalidOperation +from kimchi.exception import InvalidOperation, NotFoundError class Model(object): diff --git a/src/kimchi/model.py b/src/kimchi/model.py index 3bc5d6d..d5d0dd8 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -42,9 +42,9 @@ import time import uuid -from collections import defaultdict from cherrypy.process.plugins import BackgroundTask from cherrypy.process.plugins import SimplePlugin +from collections import defaultdict from xml.etree import ElementTree @@ -69,7 +69,7 @@ from kimchi.networkxml import to_network_xml from kimchi.objectstore import ObjectStore from kimchi.scan import Scanner from kimchi.screenshot import VMScreenshot -from kimchi.utils import kimchi_log, is_digit, get_enabled_plugins +from kimchi.utils import get_enabled_plugins, is_digit, kimchi_log from kimchi.vmtemplate import VMTemplate diff --git a/src/kimchi/server.py b/src/kimchi/server.py index 6ff6fa0..114a3a0 100644 --- a/src/kimchi/server.py +++ b/src/kimchi/server.py @@ -33,7 +33,7 @@ from kimchi import config from kimchi import model from kimchi import mockmodel from kimchi.root import Root -from kimchi.utils import import_class, get_enabled_plugins +from kimchi.utils import get_enabled_plugins, import_class LOGGING_LEVEL = {"debug": logging.DEBUG, diff --git a/src/kimchi/sslcert.py b/src/kimchi/sslcert.py index 70441f2..529699d 100644 --- a/src/kimchi/sslcert.py +++ b/src/kimchi/sslcert.py @@ -28,7 +28,7 @@ import time -from M2Crypto import X509, EVP, RSA, ASN1 +from M2Crypto import ASN1, EVP, RSA, X509 class SSLCert(object): diff --git a/tests/test_exception.py b/tests/test_exception.py index 9b5355a..df1f507 100644 --- a/tests/test_exception.py +++ b/tests/test_exception.py @@ -20,13 +20,15 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import unittest -import os import json +import os +import unittest + import kimchi.mockmodel import kimchi.server -from utils import * +from utils import get_free_port, patch_auth, request, run_server + test_server = None model = None diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py index b819172..5a3c73e 100644 --- a/tests/test_mockmodel.py +++ b/tests/test_mockmodel.py @@ -20,15 +20,17 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import unittest import cherrypy import json import os +import time +import unittest + import kimchi.mockmodel import kimchi.controller +from utils import get_free_port, patch_auth, request, run_server -from utils import * #utils.silence_server() test_server = None diff --git a/tests/test_model.py b/tests/test_model.py index fb7d6dd..e19364f 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -21,21 +21,24 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import unittest -import threading import os -import time -import tempfile -import psutil import platform +import psutil +import tempfile +import threading +import time +import unittest import uuid + +import iso_gen import kimchi.model import kimchi.objectstore -from kimchi.exception import * -from kimchi import netinfo import utils -import iso_gen +from kimchi import netinfo +from kimchi.exception import InvalidOperation, InvalidParameter +from kimchi.exception import NotFoundError, OperationFailed + class ModelTests(unittest.TestCase): def setUp(self): diff --git a/tests/test_networkxml.py b/tests/test_networkxml.py index 4eeeaa2..3073bce 100644 --- a/tests/test_networkxml.py +++ b/tests/test_networkxml.py @@ -20,10 +20,12 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +import ipaddr import unittest + + import kimchi.networkxml as nxml from kimchi.xmlutils import xpath_get_text -import ipaddr class NetworkXmlTests(unittest.TestCase): diff --git a/tests/test_osinfo.py b/tests/test_osinfo.py index f92567d..fda8ada 100644 --- a/tests/test_osinfo.py +++ b/tests/test_osinfo.py @@ -21,7 +21,10 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import unittest -from kimchi.osinfo import * + + +from kimchi.osinfo import lookup + class OSInfoTests(unittest.TestCase): def test_default_lookup(self): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 20cc598..42c87a9 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -20,17 +20,21 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import unittest import json import os import sys +import unittest + + from functools import partial + import kimchi.mockmodel import kimchi.server import utils from kimchi import config + test_server = None model = None host = None diff --git a/tests/test_rest.py b/tests/test_rest.py index f597796..73946c0 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -20,16 +20,22 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import unittest +import base64 import json -import time import os +import time +import unittest + + from functools import partial + import kimchi.mockmodel import kimchi.server -from utils import * from kimchi.asynctask import AsyncTask +from utils import fake_user, get_free_port, https_request, patch_auth, request +from utils import RollbackContext, run_server + test_server = None model = None diff --git a/tests/test_server.py b/tests/test_server.py index 9bb0034..734a618 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -20,12 +20,12 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import unittest import json import os +import unittest -import utils +import utils import kimchi.mockmodel #utils.silence_server() diff --git a/tests/test_vmtemplate.py b/tests/test_vmtemplate.py index 81382c7..7f032e7 100644 --- a/tests/test_vmtemplate.py +++ b/tests/test_vmtemplate.py @@ -23,9 +23,11 @@ import unittest import uuid -from kimchi.vmtemplate import * + +from kimchi.vmtemplate import VMTemplate from kimchi.xmlutils import xpath_get_text + class VMTemplateTests(unittest.TestCase): def test_minimal_construct(self): fields = (('name', 'test'), ('os_distro', 'unknown'), diff --git a/tests/utils.py b/tests/utils.py index c114813..a7596e8 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -21,16 +21,19 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # -import httplib +import base64 import cherrypy -import threading -import time +import httplib import os -import sys import socket -from contextlib import closing +import sys +import threading +import time import unittest -import base64 + + +from contextlib import closing + import kimchi.server import kimchi.model -- 1.8.1.4

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 12/20/2013 07:07 PM, Rodrigo Trujillo wrote:
Follow this rule: 1) Import common modules import ... import ... from ... import ... from ... import ...
2) Import kimchi modules import kimchi.<mod> import kimchi.<mod> from kimchi import ... from kimchi import ...
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- plugins/sample/__init__.py | 8 ++++++-- plugins/sample/model.py | 2 +- src/kimchi/model.py | 4 ++-- src/kimchi/server.py | 2 +- src/kimchi/sslcert.py | 2 +- tests/test_exception.py | 8 +++++--- tests/test_mockmodel.py | 6 ++++-- tests/test_model.py | 19 +++++++++++-------- tests/test_networkxml.py | 4 +++- tests/test_osinfo.py | 5 ++++- tests/test_plugin.py | 6 +++++- tests/test_rest.py | 12 +++++++++--- tests/test_server.py | 4 ++-- tests/test_vmtemplate.py | 4 +++- tests/utils.py | 15 +++++++++------ 15 files changed, 66 insertions(+), 35 deletions(-)
diff --git a/plugins/sample/__init__.py b/plugins/sample/__init__.py index a20f5e6..7064904 100644 --- a/plugins/sample/__init__.py +++ b/plugins/sample/__init__.py @@ -22,12 +22,16 @@
import json import os + + from cherrypy import expose -from kimchi.controller import Resource, Collection + + +from kimchi.controller import Collection, Resource from model import Model
-model = Model()
+model = Model()
class Drawings(Resource): def __init__(self): diff --git a/plugins/sample/model.py b/plugins/sample/model.py index f6da5d0..9a2f22f 100644 --- a/plugins/sample/model.py +++ b/plugins/sample/model.py @@ -20,7 +20,7 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-from kimchi.exception import NotFoundError, InvalidOperation +from kimchi.exception import InvalidOperation, NotFoundError
class Model(object): diff --git a/src/kimchi/model.py b/src/kimchi/model.py index 3bc5d6d..d5d0dd8 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -42,9 +42,9 @@ import time import uuid
-from collections import defaultdict from cherrypy.process.plugins import BackgroundTask from cherrypy.process.plugins import SimplePlugin +from collections import defaultdict from xml.etree import ElementTree
@@ -69,7 +69,7 @@ from kimchi.networkxml import to_network_xml from kimchi.objectstore import ObjectStore from kimchi.scan import Scanner from kimchi.screenshot import VMScreenshot -from kimchi.utils import kimchi_log, is_digit, get_enabled_plugins +from kimchi.utils import get_enabled_plugins, is_digit, kimchi_log from kimchi.vmtemplate import VMTemplate
diff --git a/src/kimchi/server.py b/src/kimchi/server.py index 6ff6fa0..114a3a0 100644 --- a/src/kimchi/server.py +++ b/src/kimchi/server.py @@ -33,7 +33,7 @@ from kimchi import config from kimchi import model from kimchi import mockmodel from kimchi.root import Root -from kimchi.utils import import_class, get_enabled_plugins +from kimchi.utils import get_enabled_plugins, import_class
LOGGING_LEVEL = {"debug": logging.DEBUG, diff --git a/src/kimchi/sslcert.py b/src/kimchi/sslcert.py index 70441f2..529699d 100644 --- a/src/kimchi/sslcert.py +++ b/src/kimchi/sslcert.py @@ -28,7 +28,7 @@ import time
-from M2Crypto import X509, EVP, RSA, ASN1 +from M2Crypto import ASN1, EVP, RSA, X509
class SSLCert(object): diff --git a/tests/test_exception.py b/tests/test_exception.py index 9b5355a..df1f507 100644 --- a/tests/test_exception.py +++ b/tests/test_exception.py @@ -20,13 +20,15 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest -import os import json +import os +import unittest +
import kimchi.mockmodel import kimchi.server -from utils import * +from utils import get_free_port, patch_auth, request, run_server +
test_server = None model = None diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py index b819172..5a3c73e 100644 --- a/tests/test_mockmodel.py +++ b/tests/test_mockmodel.py @@ -20,15 +20,17 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest import cherrypy import json import os +import time +import unittest +
import kimchi.mockmodel import kimchi.controller +from utils import get_free_port, patch_auth, request, run_server
-from utils import *
#utils.silence_server() test_server = None diff --git a/tests/test_model.py b/tests/test_model.py index fb7d6dd..e19364f 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -21,21 +21,24 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest -import threading import os -import time -import tempfile -import psutil import platform +import psutil +import tempfile +import threading +import time +import unittest import uuid
+ +import iso_gen import kimchi.model import kimchi.objectstore -from kimchi.exception import * -from kimchi import netinfo import utils -import iso_gen +from kimchi import netinfo +from kimchi.exception import InvalidOperation, InvalidParameter +from kimchi.exception import NotFoundError, OperationFailed +
class ModelTests(unittest.TestCase): def setUp(self): diff --git a/tests/test_networkxml.py b/tests/test_networkxml.py index 4eeeaa2..3073bce 100644 --- a/tests/test_networkxml.py +++ b/tests/test_networkxml.py @@ -20,10 +20,12 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import ipaddr import unittest + + import kimchi.networkxml as nxml from kimchi.xmlutils import xpath_get_text -import ipaddr
class NetworkXmlTests(unittest.TestCase): diff --git a/tests/test_osinfo.py b/tests/test_osinfo.py index f92567d..fda8ada 100644 --- a/tests/test_osinfo.py +++ b/tests/test_osinfo.py @@ -21,7 +21,10 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import unittest -from kimchi.osinfo import * + + +from kimchi.osinfo import lookup +
class OSInfoTests(unittest.TestCase): def test_default_lookup(self): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 20cc598..42c87a9 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -20,17 +20,21 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest import json import os import sys +import unittest + + from functools import partial
+ import kimchi.mockmodel import kimchi.server import utils from kimchi import config
+ test_server = None model = None host = None diff --git a/tests/test_rest.py b/tests/test_rest.py index f597796..73946c0 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -20,16 +20,22 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest +import base64 import json -import time import os +import time +import unittest + + from functools import partial
+ import kimchi.mockmodel import kimchi.server -from utils import * from kimchi.asynctask import AsyncTask +from utils import fake_user, get_free_port, https_request, patch_auth, request +from utils import RollbackContext, run_server +
test_server = None model = None diff --git a/tests/test_server.py b/tests/test_server.py index 9bb0034..734a618 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -20,12 +20,12 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest import json import os +import unittest
-import utils
+import utils import kimchi.mockmodel
#utils.silence_server() diff --git a/tests/test_vmtemplate.py b/tests/test_vmtemplate.py index 81382c7..7f032e7 100644 --- a/tests/test_vmtemplate.py +++ b/tests/test_vmtemplate.py @@ -23,9 +23,11 @@ import unittest import uuid
-from kimchi.vmtemplate import * + +from kimchi.vmtemplate import VMTemplate from kimchi.xmlutils import xpath_get_text
+ class VMTemplateTests(unittest.TestCase): def test_minimal_construct(self): fields = (('name', 'test'), ('os_distro', 'unknown'), diff --git a/tests/utils.py b/tests/utils.py index c114813..a7596e8 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -21,16 +21,19 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #
-import httplib +import base64 import cherrypy -import threading -import time +import httplib import os -import sys import socket -from contextlib import closing +import sys +import threading +import time import unittest -import base64 + + +from contextlib import closing +
import kimchi.server import kimchi.model

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Commit e467b32 brings a whitespace, fix it. Also fix pep8. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- Makefile.am | 1 + tests/test_mockmodel.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Makefile.am b/Makefile.am index 0fd92c8..1b51e46 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,6 +48,7 @@ PEP8_WHITELIST = \ plugins/__init__.py \ plugins/sample/__init__.py \ plugins/sample/model.py \ + tests/test_mockmodel.py \ tests/test_plugin.py \ $(NULL) diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py index 5a3c73e..023567b 100644 --- a/tests/test_mockmodel.py +++ b/tests/test_mockmodel.py @@ -18,7 +18,7 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import cherrypy import json @@ -29,7 +29,7 @@ import unittest import kimchi.mockmodel import kimchi.controller -from utils import get_free_port, patch_auth, request, run_server +from utils import get_free_port, patch_auth, request, run_server #utils.silence_server() @@ -38,6 +38,7 @@ model = None host = None port = None + class MockModelTests(unittest.TestCase): def setUp(self): global port, host, model, test_server @@ -99,19 +100,23 @@ class MockModelTests(unittest.TestCase): self.assertEquals(200, resp.status) self.assertEquals('image/png', resp.getheader('content-type')) resp1 = request(host, port, '/vms/test-vm') - rspBody=resp1.read() - testvm_Data=json.loads(rspBody) + rspBody = resp1.read() + testvm_Data = json.loads(rspBody) screenshotURL = testvm_Data['screenshot'] time.sleep(5) resp2 = request(host, port, screenshotURL) self.assertEquals(200, resp2.status) - self.assertEquals(resp2.getheader('content-type'), resp.getheader('content-type')) - self.assertEquals(resp2.getheader('content-length'), resp.getheader('content-length')) - self.assertEquals(resp2.getheader('last-modified'), resp.getheader('last-modified')) + self.assertEquals(resp2.getheader('content-type'), + resp.getheader('content-type')) + self.assertEquals(resp2.getheader('content-length'), + resp.getheader('content-length')) + self.assertEquals(resp2.getheader('last-modified'), + resp.getheader('last-modified')) def test_vm_list_sorted(self): req = json.dumps({'name': 'test', 'cdrom': '/nonexistent.iso'}) request(host, port, '/templates', req, 'POST') + def add_vm(name): # Create a VM @@ -126,8 +131,9 @@ class MockModelTests(unittest.TestCase): self.assertEqual(model.vms_get_list(), ['abc', 'bca', 'cab', 'xba']) def test_vm_info(self): - tmpl = model.templates_create({'name': u'test', 'cdrom': '/nonexistent.iso'}) - vm = model.vms_create({'name': u'test', 'template': '/templates/test'}) + model.templates_create({'name': u'test', + 'cdrom': '/nonexistent.iso'}) + model.vms_create({'name': u'test', 'template': '/templates/test'}) vms = model.vms_get_list() self.assertEquals(1, len(vms)) self.assertEquals(u'test', vms[0]) -- 1.8.4.2

On 12/27/2013 07:08 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Commit e467b32 brings a whitespace, fix it. Also fix pep8.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- Makefile.am | 1 + tests/test_mockmodel.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/Makefile.am b/Makefile.am index 0fd92c8..1b51e46 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,6 +48,7 @@ PEP8_WHITELIST = \ plugins/__init__.py \ plugins/sample/__init__.py \ plugins/sample/model.py \ + tests/test_mockmodel.py \ tests/test_plugin.py \ $(NULL)
diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py index 5a3c73e..023567b 100644 --- a/tests/test_mockmodel.py +++ b/tests/test_mockmodel.py @@ -18,7 +18,7 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import cherrypy import json @@ -29,7 +29,7 @@ import unittest
import kimchi.mockmodel import kimchi.controller -from utils import get_free_port, patch_auth, request, run_server +from utils import get_free_port, patch_auth, request, run_server
#utils.silence_server()
I think we can remove the above comment
@@ -38,6 +38,7 @@ model = None host = None port = None
+ class MockModelTests(unittest.TestCase): def setUp(self): global port, host, model, test_server @@ -99,19 +100,23 @@ class MockModelTests(unittest.TestCase): self.assertEquals(200, resp.status) self.assertEquals('image/png', resp.getheader('content-type')) resp1 = request(host, port, '/vms/test-vm') - rspBody=resp1.read() - testvm_Data=json.loads(rspBody) + rspBody = resp1.read() + testvm_Data = json.loads(rspBody) screenshotURL = testvm_Data['screenshot'] time.sleep(5) resp2 = request(host, port, screenshotURL) self.assertEquals(200, resp2.status) - self.assertEquals(resp2.getheader('content-type'), resp.getheader('content-type')) - self.assertEquals(resp2.getheader('content-length'), resp.getheader('content-length')) - self.assertEquals(resp2.getheader('last-modified'), resp.getheader('last-modified')) + self.assertEquals(resp2.getheader('content-type'), + resp.getheader('content-type')) + self.assertEquals(resp2.getheader('content-length'), + resp.getheader('content-length')) + self.assertEquals(resp2.getheader('last-modified'), + resp.getheader('last-modified'))
def test_vm_list_sorted(self): req = json.dumps({'name': 'test', 'cdrom': '/nonexistent.iso'}) request(host, port, '/templates', req, 'POST') + def add_vm(name):
# Create a VM @@ -126,8 +131,9 @@ class MockModelTests(unittest.TestCase): self.assertEqual(model.vms_get_list(), ['abc', 'bca', 'cab', 'xba'])
def test_vm_info(self): - tmpl = model.templates_create({'name': u'test', 'cdrom': '/nonexistent.iso'}) - vm = model.vms_create({'name': u'test', 'template': '/templates/test'}) + model.templates_create({'name': u'test', + 'cdrom': '/nonexistent.iso'}) + model.vms_create({'name': u'test', 'template': '/templates/test'}) vms = model.vms_get_list() self.assertEquals(1, len(vms)) self.assertEquals(u'test', vms[0])

On 12/21/2013 05:07 AM, Rodrigo Trujillo wrote:
Follow this rule: 1) Import common modules import ... import ... from ... import ... from ... import ...
2) Import kimchi modules import kimchi.<mod> import kimchi.<mod> from kimchi import ... from kimchi import ...
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- plugins/sample/__init__.py | 8 ++++++-- plugins/sample/model.py | 2 +- src/kimchi/model.py | 4 ++-- src/kimchi/server.py | 2 +- src/kimchi/sslcert.py | 2 +- tests/test_exception.py | 8 +++++--- tests/test_mockmodel.py | 6 ++++-- tests/test_model.py | 19 +++++++++++-------- tests/test_networkxml.py | 4 +++- tests/test_osinfo.py | 5 ++++- tests/test_plugin.py | 6 +++++- tests/test_rest.py | 12 +++++++++--- tests/test_server.py | 4 ++-- tests/test_vmtemplate.py | 4 +++- tests/utils.py | 15 +++++++++------ 15 files changed, 66 insertions(+), 35 deletions(-)
diff --git a/plugins/sample/__init__.py b/plugins/sample/__init__.py index a20f5e6..7064904 100644 --- a/plugins/sample/__init__.py +++ b/plugins/sample/__init__.py @@ -22,12 +22,16 @@
import json import os + + from cherrypy import expose -from kimchi.controller import Resource, Collection + + +from kimchi.controller import Collection, Resource from model import Model
-model = Model()
+model = Model()
class Drawings(Resource): def __init__(self): diff --git a/plugins/sample/model.py b/plugins/sample/model.py index f6da5d0..9a2f22f 100644 --- a/plugins/sample/model.py +++ b/plugins/sample/model.py @@ -20,7 +20,7 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-from kimchi.exception import NotFoundError, InvalidOperation +from kimchi.exception import InvalidOperation, NotFoundError
class Model(object): diff --git a/src/kimchi/model.py b/src/kimchi/model.py index 3bc5d6d..d5d0dd8 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -42,9 +42,9 @@ import time import uuid
-from collections import defaultdict from cherrypy.process.plugins import BackgroundTask from cherrypy.process.plugins import SimplePlugin +from collections import defaultdict from xml.etree import ElementTree
@@ -69,7 +69,7 @@ from kimchi.networkxml import to_network_xml from kimchi.objectstore import ObjectStore from kimchi.scan import Scanner from kimchi.screenshot import VMScreenshot -from kimchi.utils import kimchi_log, is_digit, get_enabled_plugins +from kimchi.utils import get_enabled_plugins, is_digit, kimchi_log from kimchi.vmtemplate import VMTemplate
diff --git a/src/kimchi/server.py b/src/kimchi/server.py index 6ff6fa0..114a3a0 100644 --- a/src/kimchi/server.py +++ b/src/kimchi/server.py @@ -33,7 +33,7 @@ from kimchi import config from kimchi import model from kimchi import mockmodel from kimchi.root import Root -from kimchi.utils import import_class, get_enabled_plugins +from kimchi.utils import get_enabled_plugins, import_class
LOGGING_LEVEL = {"debug": logging.DEBUG, diff --git a/src/kimchi/sslcert.py b/src/kimchi/sslcert.py index 70441f2..529699d 100644 --- a/src/kimchi/sslcert.py +++ b/src/kimchi/sslcert.py @@ -28,7 +28,7 @@ import time
-from M2Crypto import X509, EVP, RSA, ASN1 +from M2Crypto import ASN1, EVP, RSA, X509
class SSLCert(object): diff --git a/tests/test_exception.py b/tests/test_exception.py index 9b5355a..df1f507 100644 --- a/tests/test_exception.py +++ b/tests/test_exception.py @@ -20,13 +20,15 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest -import os import json +import os +import unittest +
import kimchi.mockmodel import kimchi.server -from utils import * +from utils import get_free_port, patch_auth, request, run_server +
test_server = None model = None diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py index b819172..5a3c73e 100644 --- a/tests/test_mockmodel.py +++ b/tests/test_mockmodel.py @@ -20,15 +20,17 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest import cherrypy import json import os +import time +import unittest +
import kimchi.mockmodel import kimchi.controller +from utils import get_free_port, patch_auth, request, run_server Today I pull the repository, I find a whitespace after run_server
whitespace is not easy to find by eye. You can use git-fix-whitespace to fix whitespace. Automatically fix whitespace errors https://github.com/RichardBronosky/git-fix-whitespace
-from utils import *
#utils.silence_server() test_server = None diff --git a/tests/test_model.py b/tests/test_model.py index fb7d6dd..e19364f 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -21,21 +21,24 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest -import threading import os -import time -import tempfile -import psutil import platform +import psutil +import tempfile +import threading +import time +import unittest import uuid
+ +import iso_gen import kimchi.model import kimchi.objectstore -from kimchi.exception import * -from kimchi import netinfo import utils -import iso_gen +from kimchi import netinfo +from kimchi.exception import InvalidOperation, InvalidParameter +from kimchi.exception import NotFoundError, OperationFailed +
class ModelTests(unittest.TestCase): def setUp(self): diff --git a/tests/test_networkxml.py b/tests/test_networkxml.py index 4eeeaa2..3073bce 100644 --- a/tests/test_networkxml.py +++ b/tests/test_networkxml.py @@ -20,10 +20,12 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import ipaddr import unittest + + import kimchi.networkxml as nxml from kimchi.xmlutils import xpath_get_text -import ipaddr
class NetworkXmlTests(unittest.TestCase): diff --git a/tests/test_osinfo.py b/tests/test_osinfo.py index f92567d..fda8ada 100644 --- a/tests/test_osinfo.py +++ b/tests/test_osinfo.py @@ -21,7 +21,10 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import unittest -from kimchi.osinfo import * + + +from kimchi.osinfo import lookup +
class OSInfoTests(unittest.TestCase): def test_default_lookup(self): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 20cc598..42c87a9 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -20,17 +20,21 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest import json import os import sys +import unittest + + from functools import partial
+ import kimchi.mockmodel import kimchi.server import utils from kimchi import config
+ test_server = None model = None host = None diff --git a/tests/test_rest.py b/tests/test_rest.py index f597796..73946c0 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -20,16 +20,22 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest +import base64 import json -import time import os +import time +import unittest + + from functools import partial
+ import kimchi.mockmodel import kimchi.server -from utils import * from kimchi.asynctask import AsyncTask +from utils import fake_user, get_free_port, https_request, patch_auth, request +from utils import RollbackContext, run_server +
test_server = None model = None diff --git a/tests/test_server.py b/tests/test_server.py index 9bb0034..734a618 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -20,12 +20,12 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest import json import os +import unittest
-import utils
+import utils import kimchi.mockmodel
#utils.silence_server() diff --git a/tests/test_vmtemplate.py b/tests/test_vmtemplate.py index 81382c7..7f032e7 100644 --- a/tests/test_vmtemplate.py +++ b/tests/test_vmtemplate.py @@ -23,9 +23,11 @@ import unittest import uuid
-from kimchi.vmtemplate import * + +from kimchi.vmtemplate import VMTemplate from kimchi.xmlutils import xpath_get_text
+ class VMTemplateTests(unittest.TestCase): def test_minimal_construct(self): fields = (('name', 'test'), ('os_distro', 'unknown'), diff --git a/tests/utils.py b/tests/utils.py index c114813..a7596e8 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -21,16 +21,19 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #
-import httplib +import base64 import cherrypy -import threading -import time +import httplib import os -import sys import socket -from contextlib import closing +import sys +import threading +import time import unittest -import base64 + + +from contextlib import closing +
import kimchi.server import kimchi.model
-- Sheldon Feng(???)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

Thanks for the tip Sheldon :) On 12/27/2013 07:16 AM, Sheldon wrote:
On 12/21/2013 05:07 AM, Rodrigo Trujillo wrote:
Follow this rule: 1) Import common modules import ... import ... from ... import ... from ... import ...
2) Import kimchi modules import kimchi.<mod> import kimchi.<mod> from kimchi import ... from kimchi import ...
Signed-off-by: Rodrigo Trujillo<rodrigo.trujillo@linux.vnet.ibm.com> --- plugins/sample/__init__.py | 8 ++++++-- plugins/sample/model.py | 2 +- src/kimchi/model.py | 4 ++-- src/kimchi/server.py | 2 +- src/kimchi/sslcert.py | 2 +- tests/test_exception.py | 8 +++++--- tests/test_mockmodel.py | 6 ++++-- tests/test_model.py | 19 +++++++++++-------- tests/test_networkxml.py | 4 +++- tests/test_osinfo.py | 5 ++++- tests/test_plugin.py | 6 +++++- tests/test_rest.py | 12 +++++++++--- tests/test_server.py | 4 ++-- tests/test_vmtemplate.py | 4 +++- tests/utils.py | 15 +++++++++------ 15 files changed, 66 insertions(+), 35 deletions(-)
diff --git a/plugins/sample/__init__.py b/plugins/sample/__init__.py index a20f5e6..7064904 100644 --- a/plugins/sample/__init__.py +++ b/plugins/sample/__init__.py @@ -22,12 +22,16 @@
import json import os + + from cherrypy import expose -from kimchi.controller import Resource, Collection + + +from kimchi.controller import Collection, Resource from model import Model
-model = Model()
+model = Model()
class Drawings(Resource): def __init__(self): diff --git a/plugins/sample/model.py b/plugins/sample/model.py index f6da5d0..9a2f22f 100644 --- a/plugins/sample/model.py +++ b/plugins/sample/model.py @@ -20,7 +20,7 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-from kimchi.exception import NotFoundError, InvalidOperation +from kimchi.exception import InvalidOperation, NotFoundError
class Model(object): diff --git a/src/kimchi/model.py b/src/kimchi/model.py index 3bc5d6d..d5d0dd8 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -42,9 +42,9 @@ import time import uuid
-from collections import defaultdict from cherrypy.process.plugins import BackgroundTask from cherrypy.process.plugins import SimplePlugin +from collections import defaultdict from xml.etree import ElementTree
@@ -69,7 +69,7 @@ from kimchi.networkxml import to_network_xml from kimchi.objectstore import ObjectStore from kimchi.scan import Scanner from kimchi.screenshot import VMScreenshot -from kimchi.utils import kimchi_log, is_digit, get_enabled_plugins +from kimchi.utils import get_enabled_plugins, is_digit, kimchi_log from kimchi.vmtemplate import VMTemplate
diff --git a/src/kimchi/server.py b/src/kimchi/server.py index 6ff6fa0..114a3a0 100644 --- a/src/kimchi/server.py +++ b/src/kimchi/server.py @@ -33,7 +33,7 @@ from kimchi import config from kimchi import model from kimchi import mockmodel from kimchi.root import Root -from kimchi.utils import import_class, get_enabled_plugins +from kimchi.utils import get_enabled_plugins, import_class
LOGGING_LEVEL = {"debug": logging.DEBUG, diff --git a/src/kimchi/sslcert.py b/src/kimchi/sslcert.py index 70441f2..529699d 100644 --- a/src/kimchi/sslcert.py +++ b/src/kimchi/sslcert.py @@ -28,7 +28,7 @@ import time
-from M2Crypto import X509, EVP, RSA, ASN1 +from M2Crypto import ASN1, EVP, RSA, X509
class SSLCert(object): diff --git a/tests/test_exception.py b/tests/test_exception.py index 9b5355a..df1f507 100644 --- a/tests/test_exception.py +++ b/tests/test_exception.py @@ -20,13 +20,15 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest -import os import json +import os +import unittest +
import kimchi.mockmodel import kimchi.server -from utils import * +from utils import get_free_port, patch_auth, request, run_server +
test_server = None model = None diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py index b819172..5a3c73e 100644 --- a/tests/test_mockmodel.py +++ b/tests/test_mockmodel.py @@ -20,15 +20,17 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest import cherrypy import json import os +import time +import unittest +
import kimchi.mockmodel import kimchi.controller +from utils import get_free_port, patch_auth, request, run_server Today I pull the repository, I find a whitespace after run_server
whitespace is not easy to find by eye. You can use git-fix-whitespace to fix whitespace. Automatically fix whitespace errors https://github.com/RichardBronosky/git-fix-whitespace
-from utils import *
#utils.silence_server() test_server = None diff --git a/tests/test_model.py b/tests/test_model.py index fb7d6dd..e19364f 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -21,21 +21,24 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest -import threading import os -import time -import tempfile -import psutil import platform +import psutil +import tempfile +import threading +import time +import unittest import uuid
+ +import iso_gen import kimchi.model import kimchi.objectstore -from kimchi.exception import * -from kimchi import netinfo import utils -import iso_gen +from kimchi import netinfo +from kimchi.exception import InvalidOperation, InvalidParameter +from kimchi.exception import NotFoundError, OperationFailed +
class ModelTests(unittest.TestCase): def setUp(self): diff --git a/tests/test_networkxml.py b/tests/test_networkxml.py index 4eeeaa2..3073bce 100644 --- a/tests/test_networkxml.py +++ b/tests/test_networkxml.py @@ -20,10 +20,12 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import ipaddr import unittest + + import kimchi.networkxml as nxml from kimchi.xmlutils import xpath_get_text -import ipaddr
class NetworkXmlTests(unittest.TestCase): diff --git a/tests/test_osinfo.py b/tests/test_osinfo.py index f92567d..fda8ada 100644 --- a/tests/test_osinfo.py +++ b/tests/test_osinfo.py @@ -21,7 +21,10 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import unittest -from kimchi.osinfo import * + + +from kimchi.osinfo import lookup +
class OSInfoTests(unittest.TestCase): def test_default_lookup(self): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 20cc598..42c87a9 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -20,17 +20,21 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest import json import os import sys +import unittest + + from functools import partial
+ import kimchi.mockmodel import kimchi.server import utils from kimchi import config
+ test_server = None model = None host = None diff --git a/tests/test_rest.py b/tests/test_rest.py index f597796..73946c0 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -20,16 +20,22 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest +import base64 import json -import time import os +import time +import unittest + + from functools import partial
+ import kimchi.mockmodel import kimchi.server -from utils import * from kimchi.asynctask import AsyncTask +from utils import fake_user, get_free_port, https_request, patch_auth, request +from utils import RollbackContext, run_server +
test_server = None model = None diff --git a/tests/test_server.py b/tests/test_server.py index 9bb0034..734a618 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -20,12 +20,12 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import unittest import json import os +import unittest
-import utils
+import utils import kimchi.mockmodel
#utils.silence_server() diff --git a/tests/test_vmtemplate.py b/tests/test_vmtemplate.py index 81382c7..7f032e7 100644 --- a/tests/test_vmtemplate.py +++ b/tests/test_vmtemplate.py @@ -23,9 +23,11 @@ import unittest import uuid
-from kimchi.vmtemplate import * + +from kimchi.vmtemplate import VMTemplate from kimchi.xmlutils import xpath_get_text
+ class VMTemplateTests(unittest.TestCase): def test_minimal_construct(self): fields = (('name', 'test'), ('os_distro', 'unknown'), diff --git a/tests/utils.py b/tests/utils.py index c114813..a7596e8 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -21,16 +21,19 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #
-import httplib +import base64 import cherrypy -import threading -import time +import httplib import os -import sys import socket -from contextlib import closing +import sys +import threading +import time import unittest -import base64 + + +from contextlib import closing +
import kimchi.server import kimchi.model
-- Sheldon Feng(???)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
participants (4)
-
Aline Manera
-
Rodrigo Trujillo
-
shaohef@linux.vnet.ibm.com
-
Sheldon