Next / Previous / Contents / Shipman's homepage

4.5. Application.__tests__(): Run initial tests

This method adds some lines to the listbox using both the .append() and .insert() methods, exercises the .delete() method, and then tests the .count() method.

scrolledlisttest
    def __tests(self):
        """Initial testing of the ScrolledList widget.
        """

First we insure that the initial list length is zero. Then we add three lines and again check the length.

scrolledlisttest
        print "Initial size is", self.sbox.count()
        print "Add alpaca, buffalo, eagle:"
        self.sbox.append("alpaca")
        self.sbox.append("buffalo")
        self.sbox.append("eagle")
        print "Size is now", self.sbox.count()

Next we test the .clear() method. The size after clearing should be zero.

scrolledlisttest
        print "Clear listbox:"
        self.sbox.clear()
        print "Size is now", self.sbox.count()

We add the same three lines back in, then test insertion.

scrolledlisttest
        print "Add alpaca, buffalo, eagle:"
        self.sbox.append("alpaca")
        self.sbox.append("buffalo")
        self.sbox.append("eagle")
        print "Insert cachalot"
        self.sbox.insert(2, "cachalot")
        print "Size is now", self.sbox.count()

Next we test deletion.

scrolledlisttest
        print "Delete buffalo:"
        self.sbox.delete(1)
        print "Size is now", self.sbox.count()

Finally, we insert enough lines, and one long line, to make it possible to test the scrollbars.

scrolledlisttest
        print "Insert bunches o stuff"
        self.sbox.append("finch")
        self.sbox.append("goshawk")
        self.sbox.append("harrier")
        self.sbox.append("indigobird")
        self.sbox.append("jabiru")
        self.sbox.append("kingfisher")
        self.sbox.append("Middendorff's grasshopper-warbler")
        self.sbox.append("merlin")
        self.sbox.append("northern flicker")
        self.sbox.append("ovenbird")
        self.sbox.append("parula")
        print "Size is now", self.sbox.count()