import unittest
import os
import sys
from gitdata import GitData
import simplejson as json

class TestGitData(unittest.TestCase):
    def test_fetch(self):
        gd = GitData(repo="./treenexus")

        study_id = 438
        study_nexson = gd.fetch_study(study_id)
        valid = 1
        try:
            json.loads(study_nexson)
        except:
            valid = 0
        self.assertTrue( valid, "fetch_study(%s) returned valid JSON" % study_id)

    def test_write(self):
        gd = GitData(repo="./treenexus")
        author   = "John Doe <john@doe.com>"
        content  = '{"foo":"bar"}'
        study_id = 9999
        branch   = "johndoe_study_%s" % study_id
        new_sha  = gd.write_study(study_id,content,branch,author)
        self.assertTrue( new_sha != "", "new_sha is non-empty")

    def test_branch_exists(self):
        gd = GitData(repo="./treenexus")
        exists = gd.branch_exists("nothisdoesnotexist")
        self.assertTrue( exists == 0, "branch does not exist")

        exists = gd.branch_exists("master")
        self.assertTrue( exists, "master branch exists")

def suite():
    loader = unittest.TestLoader()
    testsuite = loader.loadTestsFromTestCase(TestGitData)
    return testsuite

def test_main():
    testsuite = suite()
    runner = unittest.TextTestRunner(sys.stdout, verbosity=2)
    result = runner.run(testsuite)

if __name__ == "__main__":
    test_main()

from nose       import with_setup
from nose.tools import *
import os
import sys
from gitdata import GitData
import simplejson as json

def test_fetch():
    gd = GitData(repo="./treenexus")

    study_id = 438
    study_nexson = gd.fetch_study(study_id)
    valid = 1
    try:
        json.loads(study_nexson)
    except:
        valid = 0
    assert valid, "fetch_study(%s) returned valid JSON" % study_id

def test_write():
    gd = GitData(repo="./treenexus")
    author   = "John Doe <john@doe.com>"
    content  = '{"foo":"bar"}'
    study_id = 999
    branch   = "johndoe_study_%s" % study_id
    new_sha  = gd.write_study(study_id,content,branch,author)
    assert new_sha != "", "new_sha is non-empty"

def test_branch_exists():
    gd = GitData(repo="./treenexus")
    exists = gd.branch_exists("nothisdoesnotexist")
    assert exists == 0, "branch does not exist"

    exists = gd.branch_exists("master")
    assert exists, "master branch exists"

test_branch_exists()
test_fetch()
test_write()

--- 
+++ 
@@ -1,39 +1,48 @@
-from nose       import with_setup
-from nose.tools import *
+import unittest
 import os
 import sys
 from gitdata import GitData
 import simplejson as json
 
-def test_fetch():
-    gd = GitData(repo="./treenexus")
+class TestGitData(unittest.TestCase):
+    def test_fetch(self):
+        gd = GitData(repo="./treenexus")
 
-    study_id = 438
-    study_nexson = gd.fetch_study(study_id)
-    valid = 1
-    try:
-        json.loads(study_nexson)
-    except:
-        valid = 0
-    assert valid, "fetch_study(%s) returned valid JSON" % study_id
+        study_id = 438
+        study_nexson = gd.fetch_study(study_id)
+        valid = 1
+        try:
+            json.loads(study_nexson)
+        except:
+            valid = 0
+        self.assertTrue( valid, "fetch_study(%s) returned valid JSON" % study_id)
 
-def test_write():
-    gd = GitData(repo="./treenexus")
-    author   = "John Doe <john@doe.com>"
-    content  = '{"foo":"bar"}'
-    study_id = 999
-    branch   = "johndoe_study_%s" % study_id
-    new_sha  = gd.write_study(study_id,content,branch,author)
-    assert new_sha != "", "new_sha is non-empty"
+    def test_write(self):
+        gd = GitData(repo="./treenexus")
+        author   = "John Doe <john@doe.com>"
+        content  = '{"foo":"bar"}'
+        study_id = 9999
+        branch   = "johndoe_study_%s" % study_id
+        new_sha  = gd.write_study(study_id,content,branch,author)
+        self.assertTrue( new_sha != "", "new_sha is non-empty")
 
-def test_branch_exists():
-    gd = GitData(repo="./treenexus")
-    exists = gd.branch_exists("nothisdoesnotexist")
-    assert exists == 0, "branch does not exist"
+    def test_branch_exists(self):
+        gd = GitData(repo="./treenexus")
+        exists = gd.branch_exists("nothisdoesnotexist")
+        self.assertTrue( exists == 0, "branch does not exist")
 
-    exists = gd.branch_exists("master")
-    assert exists, "master branch exists"
+        exists = gd.branch_exists("master")
+        self.assertTrue( exists, "master branch exists")
 
-test_branch_exists()
-test_fetch()
-test_write()
+def suite():
+    loader = unittest.TestLoader()
+    testsuite = loader.loadTestsFromTestCase(TestGitData)
+    return testsuite
+
+def test_main():
+    testsuite = suite()
+    runner = unittest.TextTestRunner(sys.stdout, verbosity=2)
+    result = runner.run(testsuite)
+
+if __name__ == "__main__":
+    test_main()
Convert GitData tests to a unittest suite
