2012-09-22

python faqts, "style" surprises, testing sw

7.15: news.cyb/dev.py/help at faqts.com:
Python Knowledge Base
[defunct]: www.faqts.com has a lot of
example code using dictionaries.
http://www.faqts.com/knowledge-base/index.phtml/fid/541
http://www.faqts.com/knowledge_base/index.phtml/fid/199
. here is the archive of the defunct site:
(FAQTS : Computers : Programming : Languages : Python)
and both of the defunct url's work appended to that archive url
(http://web.archive.org/web/20010616225136/)
also, the example code was part of
a snippets library:
here is the help on operating on files;
eg,
# the directory of the currently executing program:
import sys, os
if __name__ == '__main__':
    _thisDir = sys.argv[0]
else:
    _thisDir = sys.modules[__name__].__file__
_thisDir = os.path.split(_thisDir)[0]
print _thisDir
7.21: news.cyb/dev.py/style guide has some pragma too:

. the python style guide is more than just formatting;
it has some pragmas and gotcha warnings too;
eg,  Programming Recommendations:
Code should be written in a way that does not disadvantage
other implementations of Python
(PyPy, Jython, IronPython, Cython, Psyco, and such).
For example,
do not rely on CPython's efficient implementation of
in-place string concatenation for
statements in the form a += b or a = a + b.
Those statements run more slowly in Jython.
In performance sensitive parts of the library,
the ''.join() form should be used instead.
This will ensure that concatenation occurs in
linear time across various implementations.

Comparisons to singletons like None
should always be done with is or is not,
never the equality operators.
Also,
beware of writing if x
when you really mean if x is not None
-- e.g. when testing whether a variable or
argument that defaults to None
was set to some other value.
The other value might have a type (such as a container)
that could be false in a boolean context!
7.14: bk.cyb/dev.py/lists:
. index starting at 0(zero) means an insert(i, obj)
is the same as putting an obj after the ith item .
. list + list2
= list`extend(list2)
= list`append(list2[:])
= list`insert(-1, list2) .
7.14: 9.6:
. notice how stack is related to list:
pop = un(right-most element)
pop = un push;
push = append .
. which is the opposite of append:
is pop removing the right-most ?
9.6: yes, list.pop() is un-append;
pop() takes the right-most .
. list.remove(elem) finds an item equal to the given elem;
contrast that to L.pop(i), removes the ith element .
-- remove() searches for the first instance
(throws ValueError if not present).

7.24: web,news:
. see the usage of __all__ (a list)
in the __init__.py for packages .
If __all__ is defined in __init__.py,
and you use "from my_package import *"
then only the modules/variables defined in __all__
will be loaded.

>>> import os
>>> os.getcwd()
'/home/user'
>>> os.chdir("/tmp/")
>>> os.getcwd()
'/tmp'

# Linux:
export PYTHONPATH=/path/to/my/library:$PYTHONPATH
# Windows:
set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
7.16: news.cyb/dev.py/testing/windmill:

mikeal 2009`intro to windmill:
. Windmill is a Selenium competitor
written entirely in Python & JavaScript
with test-writing support for both.
Windmill`intro:
. Windmill is a web testing tool
designed to let you painlessly automate
and debug your web application.
Originating at the Open Source Applications Foundation
Windmill was built to help QA
keep up with the rapid release cycles
of the Chandler Server Web UI (Cosmo) project.
As the Cosmo client is heavy in
JavaScript and AJAX functionality,
Windmill makes the communication
between the service and the client code
a priority.
Windmill Test Framework:
. Cross-browser test recorder
Record, edit, playback and interact with your tests
from one simple interface.
. Also check out the DOM Explorer, Assertion Explorer
and fully integrated Firebug-Lite.
Interact from a python shell with the
browser and the windmill service .
. install ipython and automatically get
an even more usable shell.
. more encouragement 2011:
"( Selenium 2 and Python
- ok so Windmill is my new favorite:
This looks interesting!:
http://readthedocs.org/docs/selenium-python/en/latest/
Update: Windmill is more fun now .)

No comments:

Post a Comment