chrss code coverage

September 1st, 2007

I’ve generally speaking been a fairly good boy when it comes to writing unit tests for chrss, but I know I haven’t covered everything. Most of the focus has been on the underlying chess module, so I thought I’d best have a look and see what my actual unit test code coverage was like (i.e. how much of the code is actually getting run during tests).

Nosetests has a handy --with-coverage option, that requires installing coverage.py, for just this problem.

Running:

nosetests --with-coverage --cover-package=chrss --cover-erase

Then gives me the following output:


Name                     Stmts   Exec  Cover   Missing
------------------------------------------------------
chrss                        0      0   100%
chrss.chess2               578    549    94%   69, 260, 274, 281-286, 302, 340, 343-344, 347, 349, 351, 365, 367, 371, 382-384, 387, 389, 391, 680, 886, 918, 921, 939
chrss.config                 0      0   100%
chrss.controllers          504    232    46%   35-36, 39, 50, 52, 54, 56, 58, 60, 62, 186, 195, 197, 210-237, 248-257, 261-266, 271-277, 282-290, 296-301, 307-311, 316-323, 330, 341-346, 352-380, 428, 435, 462, 478-479, 482-494, 498, 508, 512, 516, 520, 524, 529-531, 537-553, 558-566, 593, 601, 606-618, 627, 630, 636-637, 644-648, 652-678, 683-685, 690, 694-710, 714-739, 744-755, 758-760, 763-776, 779-798
chrss.model                325    228    70%   66, 68, 75, 82, 84, 91, 94, 101, 106, 115, 131-133, 136-142, 160, 164, 170-179, 187, 191-198, 207, 209, 222-224, 228, 231, 237, 245-265, 308-310, 326-335, 338-339, 354-355, 427-436, 439-442, 445-446, 455, 458-461
chrss.rest                  31      0     0%   1-43
chrss.rss                   86     50    58%   14, 18, 48-58, 67, 81-91, 95-105
chrss.templates              0      0   100%
chrss.templates.master     305    236    77%   28-29, 43, 61-65, 79, 107, 135, 148, 217, 226-249, 268, 295, 321, 346, 357, 409-430, 444-447, 453, 509-510
chrss.urls                  34      0     0%   1-57
chrss.widgets              131    115    87%   7-11, 61, 68, 109-114, 147-148, 158
------------------------------------------------------
TOTAL                     1994   1410    70%
----------------------------------------------------------------------

So overall I am (apparently) managing 70% coverage and the core chrss.chess2 module has 94% coverages. Not too bad I suppose. However I could do better and there are some notable gaps. In particular chrss.controllers only has 46% coverage and that represents some fairly important code for the whole site.

I’ve held of writing tests for some of the controller functions, as they involve sending email (signups, resetting passwords etc). I’ll have to write some sort of email mock class for that purpose, but it will be worth it as I can then be more certain things are working as they are intended.

chrss update 16

August 30th, 2007

This update includes a fairly major refactoring of chrss’s chess engine. It should make it easier to add new features in the future.

Beyond that the only (noticeable) new feature is that you can now get the Forsyth-Edwards Notation (FEN) for a game. This is a standard format for describing the current state of a game and forms the start of an API for chrss - it would allow one (for example) to write a “widget” for viewing the state of a game.

For example the FEN for game 1 looks like:


r1bk1b2/ppp1q3/2np2Np/4p1nB/8/2N5/PPPP1PPP/R1BQ1RK1 b - - 0 11

You can access the FEN for a game by clicking on the “FEN” link at the bottom of each board.

In terms of an API I should next be tackling Portable Game Notation (PGN), which should also then allow one to import games into other chess programs.

chrss has moved

August 5th, 2007

Just a quick note. Chrss has now been moved to http://chrss.co.uk/. I’ve setup redirects from the old site on psychic origami, so it should just happen naturally. Thought I’d best just make note of it here though too (in case anyone was wondering).

chrss update 15

July 12th, 2007

More additions to chrss:

  • displaying English tool-tips/hover-overs for moves
  • confirmation of move now describes the move to be made in English
  • number of games that it is your turn to move now displayed when logged in
  • “diagram” link to chessup.net for current game board (as well as when browsing previous moves)

Note chrss will be moving from http://psyhicorigami.com/chrss/ to http://chrss.co.uk/ in the coming weeks. Currently both URLs will work and share the same database, so you are free to use either one. At some point next month I shall most likely set up a permanent redirect from http://psyhicorigami.com/chrss/ to http://chrss.co.uk/, so hopefully the transition will be fairly seamless.

chrss update 14

July 2nd, 2007

Well it turns out that NetNewsWire’s javascript confirm() function doesn’t actually show a dialog. Instead it just returns false. So if you browsed from the feed to a game and tried to press the resign button not much would happen, as the javascript would behave as if you’d hit the cancel button.

Anyway, changed it to not use javascript for confirmation and instead require you to check a checkbox next to the resign button. That should be sufficient to avoid accidentally clicking on the resign button.

chrss update 13

June 19th, 2007

A very quick update to chrss:

  • AJAX-style move selection - choosing which piece to move no longer reloads the whole page (if you’ve got javascript turned on)
  • Bug fix for chess engine - on the initial move it was possible to move a pawn through a piece that should have been in it’s way

chrss update 12

June 17th, 2007

After re-theming this blog and a couple of comments about the graphics I decided it was time to re-theme chrss. I’d been meaning to do it for some time, as I’d never been too happy with the look before. However after it was pointed out that viewing the black pieces on a dark background was sometimes tricky I thought I’d best get to it.

So now the whole thing is a bit lighter and hopefully nicer to look at. I’ve also tidied up the “captured pieces”. No longer are they displayed as several different images with text saying how many are taken. Instead now they appear as a single sparkline image, which saves visual space and looks nicer. Anyway, they look a little something like this:




A textual description of the pieces captured is then available by hovering over the image.

Sure there will be a few minor tweaks to the CSS needed still, but seems to look ok so far.

chrss update 11

June 6th, 2007

Another update, where most of the work is under the hood, but I did catch a couple of small bugs in the sign up process.

Apart from that, visible changes are:

  • It should be easier to sign up as you are joining a game now - a user shouldn’t need to go back to the original invite link, as it will now be remembered after they sign up.
  • rss feeds on the “/moves”, “/comments”, “/games” and “/users” pages.
  • games that a user is waiting for an opponent, are now on a “waiting” page on the users profile (instead of under “playing”)

chrss update 10

May 25th, 2007
  • lots of pagination
  • can now browse moves and comments for all games
  • added link to user’s rss feed to the side bar when logged in

Also had a heart stopping moment when the changes for pagination weren’t working, until I found out the the paginate decorator in Turbogears doesn’t like having tg.strict_parameters being anything other than True. Easy fix, but rather annoying to only discover when I deployed to the live server…

Next job will most likely be adding in a few more rss feeds, so for example one could subscribe to newly created “open” games or else to the comments left on a particular game.

chrss update 9

May 14th, 2007

Updated chrss yesterday:

  • “open” games (an opponent needs no invitation needed to join)
  • commenting on moves (for that extra bit of social interaction)