Tuesday, April 10, 2012

Pytaf

My new open source project - PYTAF (Python Test Automation Framework) - is in the process of being announced on Freecode.com. The project can be accessed directly through GitHub. It's a distillation of the various test harnesses I've developed over the past several years, beginning in Java, polished in Ruby, until finally fully formed in Python. This version is actually in Python 3, which I'm not using yet in everyday work. It's not much different, but developing this project was partly a mechanism for learning about it.


I'm happy to put it out there in the world, as happy as putting out any of my ebooks or earlier open-source projects. If one person finds it useful, that will be 'abundance'.

announcement also here on opencode

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")