regex search and replace example scripts

Search and replace is such a common task that it should be a tool that’s in every command line script author’s toolbox. There are probably endless solutions to the problem. I’ve put together my standard methods for tackling the problem. I’ll also show similar Perl versions, mainly for comparisons. ...

February 8, 2013 · 4 min · Brian

Python regex Search and Replace Examples

Search and replace is such a common task that it should be a tool that’s in every command line script author’s toolbox. There are probably endless solutions to the problem. I’ve put together my standard methods for tackling the problem. I’ll also show similar Perl versions, mainly for comparisons. use models using Python with a more complex regular expression using Perl ...

February 8, 2013 · 4 min

Perl regex Search and Replace Examples

Search and replace is such a common task that it should be a tool that’s in every command line script author’s toolbox. There are probably endless solutions to the problem. I’ve put together my standard methods for tackling the problem, with Perl. You can also use Python, of course, as well as other tools like sed. Use Models In most of the following discussion, I’m just replacing ‘foo’ with ‘bar’....

February 7, 2013 · 2 min

nose introduction

This post has several examples, and covers fixtures, test discovery, asserts, running options, and running unittests and doctests. Nose’s tagline is “nose extends unittest to make testing easier”. It’s is a fairly well known python unit test framework, and can run doctests, unittests, and “no boilerplate” tests. It is a good candidate for a go-to test framework. I think a smart developer should get familiar doctest, unittest, pytest, and nose. Then decide if one of those makes the most sense for them, or if they want to keep looking for features only found in other frameworks....

January 29, 2013 · 9 min · Brian

pytest introduction

I think of pytest as the run-anything, no boilerplate, no required api, use-this-unless-you-have-a-reason-not-to test framework. This is really where testing gets fun. As with previous intro’s on this site, I’ll run through an overview, then a simple example, then throw pytest at my markdown.py project. I’ll also cover fixtures, test discovery, and running unittests with pytest. No boilerplate, no required api The doctest and unittest both come with Python. They are pretty powerful on their own, and I think you should at least know about those frameworks, and learn how to run them at least on some toy examples, as it gives you a mental framework to view other test frameworks....

January 15, 2013 · 8 min

Confession … I still use perl on the command line

I have a confession to make. I still use Perl. Regularly. But mostly as a command line tool. Is that a reason? or an excuse? When I started using Python regularly, I tried to replace my Perl usage. Nothing against Perl, I just wanted to force myself to use Python to aid in my learning of the language. I still have quite a few Perl habits that are hard to break....

January 9, 2013 · 3 min

unittest introduction

The unittest test framework is python’s xUnit style framework. It is a standard module that you already have if you’ve got python version 2.1 or greater. In this post, I’ll cover the basics of how to create and run a simple test using unittest. Then I’ll show how I’m using it to test markdown.py. Overview of unittest The unittest module used to be called PyUnit, due to it’s legacy as a xUnit style framework....

January 4, 2013 · 6 min · Brian

doctest introduction

The doctest test framework is a python module that comes prepackaged with Python. This post covers the basics of how to put doctests in your code, and outside of your code, in a separate file. Then I’ll show how I’m using it to test markdown.py. conceptual model of python doctest This is from python.org: The doctest module searches for pieces of text that look like interactive Python sessions, and then executes those sessions to verify that they work exactly as shown....

December 11, 2012 · 6 min · Brian

Software API/CLI interface adapters

While writing software, we are faced with lots and lots of interfaces. The public interface for some tool or module or package or whatever is usually referred to as the API, the CLI, or simply the user interface. In this post, when considering an interface, I am specifically referring to APIs and CLIs. Sometimes, we find a software component that does exactly what we want, but the interface is not what we want....

November 27, 2012 · 6 min · Brian

Stub for markdown.py

To explore the concepts of functional testing using python and python testing frameworks, I’m building a project to test, markdown.py on github. In this post, I’m discussing the stub implementation that I will use to set up the testing frameworks. ...

October 25, 2012 · 2 min · Brian