White scenery @showyou, hatena

If you have any comments, you may also send twitter @shsub or @showyou.

noseが残念な話

1.import nose;nose.main()ができない

これうちの環境(Ubuntu 9.04 x86, python 2.6.4)だけなのかもしれないけど

def testHoge():
    ...

if __name__ == '__main__':
    import nose
    nose.main()

python test.pyとやっても0 testsになる。

2.utf-8対応が貧弱

これunittestからっぽいけど、nose.tools.assertEqualの結果が

AssertionError: u'\u691c\u7d22\u30b5\u30a4\u30c8 ' != u'\u691c\u7d22\u30b5\u30a4
\u30c8'

みたいな感じで出て貧弱。ちなみにnoseのassertだとそもそもエラー時に出力されない。


しかもprint関数使うとエンコードエラーが出る。unittestだと問題ないんですけどね。

今日の料理3

http://d.hatena.ne.jp/showyou/20091217/1261061508

こんな感じに変えた。あまり変わってないかと

# -*- coding:utf-8 -*-
import analyzer
#from nose.tools import assert_equal

class Test_removeCharacter():
    def testHTTP(self):
        assert self._rc(u"検索サイト http://www.google.com"), u"検索サイト "

    def testTag1(self): #[]カット
        assert self._rc(u"検索サイト [mb]") == u"検索サイト "

    def testTag2(self): #**カット
        assert self._rc(u"検索サイト *Tw*") == u"検索サイト "

    def testBrowsing(self):
        assert self._rc(u"Browsing:ほげほげ") == u""
        assert self._rc(u"browsing: ふがふが")== u""

    def testRT(self): #RT:カット
        assert self._rc(u"あああああ RT @hoge: abcde") == u"あああああ "

    def testHashtag(self): #カット
        assert self._rc(u"あああああ #test") == u"あああああ "

    """ todo: __でメソッドが外部非公開かどうか確認 """
    def _rc(self,input):
        return analyzer.RemoveCharacter(input)

if __name__ == '__main__':
    nose.main()