Crosstips.org

My fun Crossword solver project. Crosstips.org & Krysstips.se

Kung Fu

Fujian White Crane Kung Fu

Fry-IT

Fry-IT is the company I work for

Photos

Photoalbum, both old and new.

Zope

What I have and am doing with Zope

Receptsamlingen

In Swedish only. About my "Collection of Recipes" website.

Contact me

My contact details and how to contact me.

 

Interested in buying ad space on this blog?
You can, on BuySellAds.com

KungFuPeople.com
Do you train Kung Fu?
Or know someone who does?
Then check out KungFuPeople.com


Mobile version of this page Mobile version of this page


 

You searched for keyword:unittest
 

found 0 photos and 4 blogs in and 0 blog comments in 0.00 seconds



 

Blogs

  Google London Automation Test conference - 8th of September 2006

I'm writing this from Googles office in London, UK where Google is hosting a conference on Automated Testing. Testing of software that is. There's been very little talking about usability testing or hardware testing. There's been a lot of talks about taking unittesting taken to the next level.

  String comparison function in Python (alpha) - 22nd of December 2007

I was working on a unittest which when it failed would say "this string != that string" and because some of these strings were very long (output of a HTML lib I wrote which spits out snippets of HTML code) it became hard to spot how they were different. So I decided to override the usual self.assertEqual(str1, str2) in Python's unittest class instance with this little baby:

 def assertEqualLongString(a, b):
    NOT, POINT = '-', '*'
    if a != b:
        print a
        o = ''
        for i, e in enumerate(a):
            try:
                if e != b[i]:
                    o += POINT
                else:
                    o += NOT
            except IndexError:
                o += '*'

        o += NOT * (len(a)-len(o))
        if len(b) > len(a):
            o += POINT* (len(b)-len(a))

        print o
        print b

        raise AssertionError, '(see string comparison above)'

  Mocking os.stat in Python - 8th of November 2009

I have some code that checks that a file is treated differently if some time has passed. In other words, it reacts if the modification time is more than it was before. The code uses os.stat(filename)[stat.ST_MTIME] to do this. The challenge was to mock os.stat so that I can pretend some time has passed without having to wait. Here was my first solution which made running many tests sloooow:

 def test_file_changed(self):
     filename = 'foo.txt'
     expect_timestamp = int(time.time())
     ...run the unit test with 'expect_timestamp'...
     time.sleep(1)
     expect_timestamp += 1
     ...run the unit test with 'expect_timestamp'...

  To assert or assertEqual in Python unit testing - 14th of February 2009

When you write unit tests in Python you can use these widgets:

 self.assertEqual(var1, var2, msg=None)
 self.assertNotEqual(var1, var2, msg=None)
 self.assertTrue(expr, msg=None)
 self.assertRaises(exception, func, para, meters, ...)