Thursday, April 5, 2012

Porting PTest from Python 2.6 to Python 3.0


work-in-progress ... experiment porting my python automation test framework from Python 2.6 to Python 3.0 (on Windows 7, it should be noted)

python.org/ftp/python/3.2.2

---------------------
import changes
---------------------
  import httplib becomes import http.client as httplib
  import urllib2 becomes import urllib as urllib2
  import urllib also becomes import urllib as urllib

  import MySQLdb - no such module. download pymsql instead and, after installing, import pymysql

  lxml
   from http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml, lxml-2.3.4.win-amd64-py3.2.‌exe
    failed to install - couldn't find python3.2 in the freaking registry
  so ... not using lxml  (BeautifulSoup is way better anyway)

  import thread becomes import _thread

BeautifulSoup 4 - https://groups.google.com/forum/#!msg/beautifulsoup/VpNNflJ1rPI/sum07jmEwvgJ
and after installing
from BeautifulSoup import BeautifulSoup becomes   from bs4 import BeautifulSoup

import Queue becomes import queue

--------------------------
execution changes
--------------------------


#set the right TEST_HOME
set TEST_HOME=C:\Users\tlichtenberg\workspace\tlichtenberg_win\QA\ptest3

# use the right python
c:\python32\python ptest3.py -c api_config.json -t test_api

---------------------
code changes
---------------------

print statements are now functions
     print "this is my statement"
becomes
     print("this is my statement")

 MySQLdb.Connection(... = pymysql.connect(...

thread.get_ident() becomes _thread.get_ident()

http response.read() returns a bytes object, not a string. so it needs to be
response.read().decode() to turn it into a string

for k,v in dict.iteritems():
   print k,v
becomes
for (k,v) in dict.items():
    print(k,v)


--------------
unicode
________


all text is unicode
  u"\xe9" no longer supported
  backslashes in strings are now just backslashes, not escapes

? not sure about this yet ...
instead of u'\x80abc'.encode('utf-8')
                  b'\x80abc'.decode("utf-8", "replace")




No comments:

Post a Comment