April 13, 2008 by Isaac
First of all, if you don't have Emacs installed on Windows then you should download it now.
Once you have Emacs installed then you'll naturally want to add "Open With Emacs" to your Windows right-click menu. To do this you'll need to make a registry entry. The easiest way is to copy the following text into a file, call it emacs.reg or something similar, and then double click the file.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell]
[HKEY_CLASSES_ROOT\*\shell\Open With Emacs]
[HKEY_CLASSES_ROOT\*\shell\Open With Emacs\command]
@="C:\\progs\\emacs-22.2\\bin\\runemacs.exe \"%1\""
Of course you should substitute the path to emacs with wherever you have it installed on your system.
That's it. Enjoy using Emacs in Windows.
Posted in Computer Stuff
No Comments »
April 10, 2008 by Isaac
Linux has many amazing programs that can be chained together to produce amazing results. Today I needed to turn a multi-line file into a CSV (comma separated) file. In Linux this is super easy:
cat file | tr '\n' ','
Basically, this will turn a file like this:
Line1
Line2
Line3
Line4
Into this:
Line1,Line2,Line3,Line4
Posted in Bash/Shell
No Comments »
April 9, 2008 by Isaac
One of the greatest things about being a test engineer is that I get to delve into a little bit of everything. At work I use a handful of different languages to accomplish different tasks. Up until recently TCL programming has been a thorn in my side. I love the interactive Python shell ipython and sorely miss having the same thing in TCL. Just today I found tclreadline, which adds command history and tab completion to the TCL shell. This is definitely something to add to your superhero tool belt.
Posted in TCL
2 Comments »
March 31, 2008 by Isaac
Background
I love Python and my personal experience has shown that testers are about 4x more productive when using Python than when using Java. However, at work I am a tester on a Java application. I've been looking for a way to bridge that gap and allow me to write my tests in Python but test a Java application.
I've looked into Jython and while it had many advantages it has one major drawback that I can't live with: Jython only implements Python 2.2. Most of the time this is fine, but there are times where I use Python 2.4 or 2.5 features and don't want to create a workaround just so I can use an older Python standard. If I had the money I would pay someone to bring Jython up to date. But, that's not a possibility.
I did find another alternative that so far seems to work great. It is still in development, but JPype seems to be working fairly well. JPype differs in philosophy from Jython in a fundamental way: Jython is a complete reimplementation of Python in Java, whereas JPype is a bridge between CPython and native Java.
Kicking The Tires
This article is a "how to," so let's get down to business. I'm going to create a Java class that I would like to access from Python. Here is Java class:
package org.wg3i.test;
class Test {
private String msg;
public Test() {
}
public void speak(String msg) {
System.out.println(msg);
}
public void setString(String s) {
msg = s;
}
public String getString() {
return msg;
}
}
The class is simple enough, but it will illustrate the basic JPype usage. For my testing I compiled this and placed it into a jar file. Feel free to leave it as a class file if you wish. I'll show you how to deal with both situations below.
For reference, here is my ant build file:
<project name="TestProject" basedir="." default="jar">
<property name="src.dir" value="src"></property>
<property name="build.dir" value="build"></property>
<property name="classes.dir" value="${build.dir}/classes"></property>
<property name="jar.dir" value="${build.dir}/jar"></property>
<target name="clean">
<delete dir="build">
</delete>
<target name="compile">
<mkdir dir="${classes.dir}">
<javac srcdir="${src.dir}" destdir="${classes.dir}">
</javac>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}">
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
</jar>
<target name="clean-build" depends="clean,jar">
</target>
</mkdir></target></mkdir></target></target></project>
After creating a jar file you are ready to go. Here is the Python code to utilize a jar file and create an instance of the Java class.
# Simple little JPype test. Note: This test assumes
# that the jar file is in the build/jar directory
# relative to the current directory
import jpype
import os.path
jarpath = os.path.join(os.path.abspath('.'), 'build/jar')
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.ext.dirs=%s" % jarpath)
Test = jpype.JClass('org.wg3i.test.Test') # get the class
t = Test() # create an instance of the class
t.speak("This is a test message") # try to call one of the class methods
t.setString("Hello, World") # set a string
s = t.getString() # get the string back
print s
jpype.shutdownJVM()
In a nutshell that's it. I promised to show you how to initialize JPype when you have class files and not jar files. Here's a Python example that shows that This example also shows the use of the JPackage method, which gets a package, not a class.
import jpype
import os.path
classpath = os.path.join(os.path.abspath('.'), 'build/classes')
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path=%s" % classpath)
testPkg = jpype.JPackage('org').wg3i.test # get the package
Test = testPkg.Test # get the class
t = Test() # create an instance of the class
t.speak("This is a test message") # try to call one of the class methods
t.setString("Hello, World") # set a string
s = t.getString() # get the string back
print s
jpype.shutdownJVM()
Conclusion
There are many things I have not covered, such as passing arrays back and forth, types other than strings, exceptions, etc. However, this should be enough to get you started using JPype. I'd be interested in hearing your own experiences or suggestions.
Posted in Java, Programming, Python
1 Comment »
March 28, 2008 by Isaac
In the lab today I was having problems with a slow network. In tracing the cables from the computer I found they went into a hub, not a switch. After recovering from shock I checked the card settings to see what duplex mode they were in. It turns out that in addition to being connected to a hub they were also running in half duplex mode. This is a very busy network and a with a hub all the computers see the traffic from all the other computers. A switch would be much better. So on my todo list goes another task: get a switch from IT for this subnet.
Linux LAN card: Find out full duplex / half speed or mode
Posted in Administration
No Comments »
March 27, 2008 by Isaac
Dataflow programming is something new to me. Lately I've been looking up articles and information about this programming paradigm. In a sense I suppose that I am familiar with the concepts. In Linux I use the pipe "|" a lot to pump data from one program to another. Each program in the stage alters the data in some way. This is basically what dataflow programming is all about -- piping data through a system of small blocks, with each block altering the data in some way.
In doing my searches I came across an interesting Python package that allows you to do basic dataflow programming. This article by the author of zflow covers the basic usage and concepts of the package and dataflow programming in general. I am interested to see if this package keeps evolving. Now, I just need to figure out a good application in software testing for dataflow programming. Any ideas?
Posted in Programming, Python
No Comments »
March 21, 2008 by Isaac
Crontab has got to be one of the greatest programs ever written. How in the world did we get along before being able to schedule the periodic execution of commands? Of course when I am setting up a cron job I seldom remember the order of the fields, so at the top of my crontab files I always stick a large comment block to remind me. This little diagram is priceless as a header in crontab files.
# * * * * * command to be executed
# - - - - -
# | | | | |
# | | | | +----- day of week (0 - 6) (Sunday=0)
# | | | +------- month (1 - 12)
# | | +--------- day of month (1 - 31)
# | +----------- hour (0 - 23)
# +------------- min (0 - 59)
Here is a good reference link for all things crontab: Unix Crontab - setting up cron jobs using crontab
Posted in Administration, Computer Stuff
No Comments »
March 20, 2008 by Isaac
I love Emacs as an editor. I love all the features and flexibility. Now, it is a somewhat heavyweight editor in that sometimes you don't need an editor with the kitchen sink. On those occasions I do condescend to using vi.
One of the things that I found and love is Emacs color themes. It is not very obvious on that web page how to download the package, so here is the download link. It's kinda fun to have so many color themes available whenever I feel like switching themes.
Posted in Computer Stuff
No Comments »
March 19, 2008 by Isaac
I think it's a safe bet to say that anyone who has been in software testing or programming for any length of time has had to create a regular expression (RE). Most of the RE's that I create are simple and I can do them quickly. However, this past week I had need to create several RE's that were more complex than normal. Fortunately, open source software came to the rescue. I found this great tool called Regular Expression Editor. My kudos to the author of that program. It allows you to enter some sample text in one box and the RE in another. As you type in your regular expression the sample text is highlighted and you can see if what you are typing is working or not. This tool allowed me to find some problems with my initial regular expression and fine tune it for some corner cases.
Although the author claims the main purpose of this tool is to edit text using regular expressions, I find it useful for fine tuning my regular expressions.
Posted in Administration, Computer Stuff, Programming
No Comments »