2014/09/30

Django series: Tricks on doing Test Driven Development

Preface

This post will not talk about how to write TDD in django. Instead, it covers how to do this HAPPIER (in my opinion).
In case, you do not know how to do TDD under the django framework, please take a look here.

Tricks

  • How to run test cases?

python manage.py test
  • How to colorize the above output?

Take a look here
Personally I am using the pyrg
  • How to change the TEST RUNNER?

Actually, you can change the test runner of django (EG: nose2) instead of using the default one. Take a look here.
Note that you should write this statement TEST_RUNNER='djnose2.TestRunner' instead of TEST_RUNNER=djnose2.TestRunner in order to make this work.
  • How to capture the output from the running tests (eg: pprint, logging etc) with COLOR?

pyrg -- manage.py test -- -B
The difficulty is how to pass options to your test runner.
The first -- tellspyrg that following (manage.py test -- -B) MUST BE arguments instead of OPTIONS. The second -- tells manage.py the -B MUST BE the ARGUMENT instead of the OPTIONS. Then, you can pass the -B options to your custom test runner (I am using nose2).

2014/09/22

To the world of social networking

Hello world! First blog post about this course and this blogger.

After attending first few lecture talks, I can feel the power and the potential of studying social networking. It is amazing that people invent intrinsic ways to analyze and model User Generated Contents by using Natural Language Processing and probability theory.

Actually, I am really interest on how modern social medias like facebook, google plus analyze user's behavior and how to make use of such kind of data to do advertisements pushing and promotions efficiently.

What I learnt from lecture 3 allows me to analyze users' content. Conceptually, by using term weighting, we are able to convert data from text based context to digits. Then, by using either or both of the vector space model and k-clustering, we are able to classify the type of the user context. Once we are able to categorize type of content, the remaining stuff is simply coding.

k-cluster


Besides the implementations, I am really excited about tricks on improving the accuracy of the classifications and how can those big companies profit from them. Hopefully, the following lectures will cover those issues one by one.

2014/09/15

Django series: About django-admin.py

Following documents what I have walked through from here
  • Relationship between django-admin.py and manage.py
manage.py is a wrapper of django-admin.py which take cares the following before delegated to django-admin.py:
* It puts your project’s package on sys.path.
* It sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project’s settings.py file.
* It calls django.setup() to initialize various internals of Django.
  • List of helpful commands
    • dumpdata, output all data in database related to the given apps
    • inspectdb, create a model for each table inside the database
    • loaddata, load data from fixture to the database
    • flush, erase all data from the database

2014/09/04

Java TDD = PROJECT + ANT + JUNIT

About

This blog is about what issues I have faced and tackle on writing a JAVA project with TDD (Test driven development). As you may not know, I am not an experienced Java developer. All the java coding skills came from a course 2 years ago.

Project

My goal is building up an application for fetching concert’s information from EVENTFUL. Although there is an official java binding provided, some of it’s dependencies (eg: XML) are not supported on ANDROID device by default. So, I am going to make a new one.

ANT

For brevity, I will say this tool works like grunt or makefile which ease the burdens of testing and compile your source code.
Typically, it required a makefile named as build.xml
Structure of the build.xml
XML := 1 * Project
Project := 1~N * Target
Target := 1~N * Task

FAQ

JUNIT

A popular testing framework. To be honest, all I need is the fabulous assertions.

FAQ

  • Installation on MAC BOOK AIR (MAC OS)
Command sudo port install junit works well. Make sure you have updated your port database if you are fail to issue the above command.
  • Compilation on command line
PATH is the most difficult issue in this part. Make sure you have included both junit.jar and hamcrest-core.jar on compilation.
  • How to run JUNIT on command line
2 points to note. The first one is make sure you have included all jar files on your java class path. The second one is how you call your test class. Below is an example
/opt/local/share/java/junit.jar:/opt/local/share/java/hamcrest-core.jar:.:./com/ideafactory/dataquery/test/PerformerTest.class org.junit.runner.JUnitCore com.ideafactory.dataquery.test.PerformerTest