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()

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()

Convert GitData tests to a unittest suite
Convert GitData tests to a unittest suite

+ import unittest
- from nose       import with_setup
- from nose.tools import *
  import os
  import sys
  from gitdata import GitData
  import simplejson as json
  
+ class TestGitData(unittest.TestCase):
- def test_fetch():
+     def test_fetch(self):
-     gd = GitData(repo="./treenexus")
+         gd = GitData(repo="./treenexus")
  
-     study_id = 438
+         study_id = 438
-     study_nexson = gd.fetch_study(study_id)
+         study_nexson = gd.fetch_study(study_id)
-     valid = 1
-     try:
-         json.loads(study_nexson)
-     except:
-         valid = 0
+         valid = 1
+         try:
+             json.loads(study_nexson)
+         except:
+             valid = 0
-     assert valid, "fetch_study(%s) returned valid JSON" % study_id
+         self.assertTrue( valid, "fetch_study(%s) returned valid JSON" % study_id)
  
- def test_write():
+     def test_write(self):
-     gd = GitData(repo="./treenexus")
+         gd = GitData(repo="./treenexus")
-     author   = "John Doe <john@doe.com>"
+         author   = "John Doe <john@doe.com>"
-     content  = '{"foo":"bar"}'
+         content  = '{"foo":"bar"}'
-     study_id = 999
+         study_id = 9999
-     branch   = "johndoe_study_%s" % study_id
+         branch   = "johndoe_study_%s" % study_id
-     new_sha  = gd.write_study(study_id,content,branch,author)
+         new_sha  = gd.write_study(study_id,content,branch,author)
-     assert new_sha != "", "new_sha is non-empty"
+         self.assertTrue( new_sha != "", "new_sha is non-empty")
  
- def test_branch_exists():
+     def test_branch_exists(self):
-     gd = GitData(repo="./treenexus")
+         gd = GitData(repo="./treenexus")
-     exists = gd.branch_exists("nothisdoesnotexist")
+         exists = gd.branch_exists("nothisdoesnotexist")
-     assert exists == 0, "branch does not exist"
+         self.assertTrue( exists == 0, "branch does not exist")
  
-     exists = gd.branch_exists("master")
+         exists = gd.branch_exists("master")
-     assert exists, "master branch exists"
+         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
## Code Before:
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()

## Instruction:
Convert GitData tests to a unittest suite
## Code After:
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()
