Archive for August, 2008

Some cool misc. stuff

Monday, August 25th, 2008

I give you…Game Jam! A site for homebrew computer game sprints.

In addition, I also give you YAML2LaTeX, Inkscape, Inkscape LaTeX plugin, Inkscape to website plugin, and LyX.

Finished my first day of classes, generated something like 40 new cards for Astrophysics, not counting the yet to be imported diagrams I made…Lotsa of knowledge, hopefully Mnemosyne will help me do things more efficiently.

Spent about an hour catching up on email from work, stupid 100 MB mailbox limit meant I had to go through and delete a lot of it.

Plan of attack

Sunday, August 24th, 2008

So, after discovering the joy that is Mnemosyne, I have a special strategy for this semester. It goes something like this:

  • Monday morning class: Ethics
  • After class, go over notes and reading assigned and create question/answers in google docs.
  • Each lunch
  • Do homework/draw
  • Go to Astrophysics at 1:40 PM
  • After class, drive home, export cards for Ethics, add cards for Astrophysics and study using Mnemosyne

Rinse and repeat. Hopefully this’ll make everything go faster. I’m glad I have a LaTeX install on my laptop already, this means I’ll be able to handle basically any equation that I need to learn for Astrophysics.

I hope to be able to use either MSys or the Eclipse CDT plugin for any coding needed for Operating Systems. Based on what I’ve heard, we’ll be writing parts of an operating system simulator in C with some shell script.

If worse comes to worse, i guess I could install cygwin on my laptop again.

More design success

Sunday, August 24th, 2008

I just got finished with working on the ranking stuff a bit. Writing out the CRC cards and then the specification based tests seemed to work very well. The specification got fleshed out as I was writing the test, those simple CRC  cards were all that I really needed.

After reading the Django documentation, I also learned that I’ll be putting most of the logic for getting rankings by date into a custom Manager class.

The one issue I ran into is when I had a syntax error in a file under test, spec barfed and I had to run nosetests without any options to track it down. But it wasn’t that big of a deal.

It’s also nice how you can set it to output colors for specification/tests that pass/fail or are skipped. I stubbed out a few tests that I haven’t implemented yet as skipped tests.

By outptutting the list of specifications every run, it also forces me to name my tests  correctly. I’ve refactored the tests and test classes several times to use a more accurate description.

This is an awesome way to develop. I’m definitely adding better formatting to nose spec after I finish this project.

Requirements for link model

Friday, August 22nd, 2008

Here’s my first try at doing some CRC cards for submitted links:

Link

Responsibilities:

  • Maintain information related to submitted link
    • URL
    • title
    • submitter
    • date submitted
  • Calculate score based on votes
  • Keep track of whether the link has been flagged inappropriate or broken
  • Keep track of whether the link has been approved (for anonymous submissions)

Collaborators

  • Vote
  • User

Vote

Responsibilities:

  • Keep track of vote information (+1, -1, 0)
  • Keep track of date vote modified
  • keep track of which user voted.

Collaborators

User

Responsibilities:

  • Keep track of user information and authentication.
  • Keep track of user trust level.

View

Responsibilities:

  • Display links in correct order based on vote, session and user.

Pinocchio –with-spec working!

Thursday, August 21st, 2008

I finally upgraded pinocchio (extensions to nose, hah!) and –with-spec is working.

Here’s the output I currently get from my tests. Now, this is really slick. It generates a “Just good enough” specification based on the automated test cases I’ve created.

Index functional tests
- The response to a GET should have a 200 status code.

Tests for submitted link model object.
- link attributes

Index view should return correct format.
- Content should not be empty.
- Content should contain a list of the top links from the past week.
- Content should have a login/create account link.
- Should return a status code of 200.
- Content should have a submit-link hyperlink.
- Content should have a tag cloud.
- Content should have links for month, day, year, all time and the words “week” for navigation.
- Anonymous users should not see a settings link.
- Should return HttpResponse object.

I’ve run into two slight niggles with it. First, it doesn’t handle methods that are in camel case, only methods that are separated by underscores. Second, it doesn’t dedent docstrings or format them at all. I’m going to get darcs going and submit patches to fix both these problems.

Fixtures with nose

Thursday, August 21st, 2008

So, I’ve finally started working on the database and ran into the biggest problem yet with my nose setup. Specifically, django needs a test database setup before tests of the model object.

To do this, I first tried to find a modern django plugin for nose (with no luck). I then found nose fixtures, which allowed me to setup and teardown the test database for my tests package.

Here’s the __init__.py file for it:

from django.test import utils
from django.conf import settings
from django.db import connection

database_name = None

def setup():
    """Setup the various django fixtures."""
    database_name = settings.DATABASE_NAME
    utils.setup_test_environment()
    connection.creation.create_test_db()

def teardown():
    """Tear down the fixtures and database."""
    connection.creation.destroy_test_db(database_name)
    utils.teardown_test_environment()

Nose test cases

Thursday, August 21st, 2008

So, starting with the previous blog post, I’ve turned the verbal description f the test cases into python code. I also implemented the necessary additions to urls.py and views.py to get them to pass.

Here are my “functional tests” These use the django testing framework, which means it’s pretty close to what a real user would experience. This file needs to be updated after I get some more functionality lower down with unit tests.

functional_tests.py

from django.test import TestCase

class IndexFunctionalTests(TestCase):
    urls = 'linkranking.urls'

    def testIndexReturns200(self):
         """The response to a get should have a 200 status code."""
         response = self.client.get('/')
         self.assertEqual(response.status_code, 200)

test_views.py
This file contains all the real test cases, currently it tests templates, urls and views.

from django.http import HttpRequest, HttpResponse

from linkranking import views

class TestIndexViewLayout():
    """Test the index view so that it returns an HttpResponse object that
    contains:
    * Submit Link hyperlink
    * A tag cloud
    * A list of the top Bayesian ranked links from the past week
    * Links labeled day, month, year, all time
    * A login/create account hyperlink
    """

    def setup(self):
        """Test the index view with an empty HTTP request object."""
        self.response = views.index(HttpRequest())

    def testShouldReturnAnHttpResponse(self):
        """View should return HttpResponse object."""
        assert isinstance(self.response, HttpResponse)

    def testShouldHaveStatusCode200(self):
        """View should return a status code of 200."""
        assert self.response.status_code == 200

    def testResponseShouldNotBeEmpty(self):
        """The response should not be empty."""
        assert self.response.content != ''

    def testShouldHaveSubmitHyperlink(self):
        """The response should have a submit hyperlink."""
        assert '<a href="/submit-link">Submit Link</a>' \
                in self.response.content

    def testShouldHaveTagCloud(self):
        """The response should have a tag cloud."""
        assert '<div id="tag-cloud">' in self.response.content

    def testShouldHaveListOfTopLinks(self):
        """The response should contain a list of the top links from the past
        week."""
        assert '<ul id="top-links">' in self.response.content

    def testShouldHaveLoginLink(self):
        """The response should have a login/create account link."""
        assert '<a href="/login">Login/Create Account</a>' \
                in self.response.content

    def testShouldNotHaveSettingsLink(self):
        """Anonymous users should not see a settings link."""
        assert 'settings' not in self.response.content

    def testShouldHaveTimeNavigationLinks(self):
        """The webpage should have links for month, day, year, all time and the
        words "week" for navigatiion."""
        assert '<a href="/today">today</a>' in self.response.content
        assert 'week' in self.response.content
        assert '<a href="/month">month</a>' in self.response.content
        assert '<a href="/year">year</a>' in self.response.content

So, I’ve generated a lot of very simple test cases to make sure that the correct pieces of the HTML output are there. I’m not sure if this is a good strategy (we’ll see in the future). Luckily these tests are high level enough that they shouldn’t change much when the underlining functionality changes.

One thing I’ve been debating is using BeautifulSoup to look up the tags in the output HTML instead of just poking at it to see if it directly contains strings. Using beautiful soup would definitely be more robust, but I don’t know if it’s necessary.

Mnemosyne Redux

Tuesday, August 19th, 2008

I now have 186 cards entered into Mnemosyne, most of them are about CSS, a handful are about drawing and vim commands.

I’ve gotten to the point where most of the cards aren’t that challenging, so I end up spending more time adding cards to it when I’m bored. I guess this is how spaced learning is supposed to work, gaining a lot of knowledge with little effort. Most days I’m reviewing between 3 and 18 cards.

Following the twenty tip to effective learning is very…effective. Cloze replacement is really easy and very useful for learning the sets/enumerations of values for CSS, and other things where it’s hard to formulate good questions. I’ve also used it to learn what color names are supported by CSS.

I also take every chance to rewrite the flashcards if they don’t make sense. This seems to have kept down on the number of memory interference problems I’ve had. I also have a pretty good understanding of CSS conceptually, so this has also helped.

I haven’t used any of the “advanced” features of Mnemosyne yet, embedding images, LaTeX, etc. I’ll be trying that once I start up my classes next week. The plan is to create cards from the notes in class and assigned reading every day I have class. We’ll see if it’s an effective strategy. Which reminds me, I got Tanenbaum’s book on operating systems, so I’m really excited. I love the cover.

A good challenge (besides using it for classes) would be to use mnemosyne to learn Norwegian. My mother wants to get the rust off of her Norwegian skills, as well, so it should be a good fit.

Doing TDD in Django

Monday, August 18th, 2008

So, as part of this link ranking website project, I’m trying to do TDD In Django, I’ve got a nice development setup with virtualenv with django installed locally in my development folder. My apps are added to sys.path through the PYTHONPATH environment variable and I set the DJANGO_SETTINGS_MODULE variable depending on what I’m developing at the moment. I also used easy_install to get the latest version of nose, my favorite test runner.

So, the first thing I do is write a simple smoke test to make sure that my application is setup correctly:

from django.test import TestCase

class IndexFunctionalTests(TestCase):

    def testIndexReturns200(self):
        response = self.client.get('/')
        self.assertEqual(response.status_code, 200)

This requires the DJANGO_SETTINGS_MODULE environment variable to be set. I copied what django-tagging does, and have a tiny project settings.py specified within the tests folder. I also set up the urls.py file in the linkranking directory and reference it in tests.settings file.

This psuedo project will need to be expanded once I start developing templates. And I’m still running into problem #8358. I really should try this patch to see if it fixes it.

So far using nose with Django is pretty straightforward, if I use the Django TestCase object for all the database and client related stuff.

School’s about to start

Sunday, August 17th, 2008

Another summer over. This time I didnt take any classes and now it’s time to greet the new freshmen. In one week I’ll start my classes, and in December I’ll finish my Computer Engineering degree.

I completed my Senior Audit, all I need to do is finish my classes, do exit interviews for the Math department and Electrical and Computer Engineering department and apply for my masters degree in Computer Science.

So another school year begins :)