From 283da5e7de6a4a3b6aaae7045909d70b643ad380 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Thu, 10 May 2012 18:26:18 +0200 Subject: [PATCH] Fix code generation and tests after reorganization --- codegen/GenerateCode.py | 9 +++++---- run_tests.sh | 6 ++++-- src/github/Github.py | 22 +++++++++++----------- test/IntegrationTest.py | 4 +++- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/codegen/GenerateCode.py b/codegen/GenerateCode.py index 80c69a4e..6bfe424f 100644 --- a/codegen/GenerateCode.py +++ b/codegen/GenerateCode.py @@ -1,5 +1,6 @@ #!/bin/env python +import os import json import itertools @@ -9,12 +10,12 @@ import django.template.loader django.conf.settings.configure( TEMPLATE_DIRS = ( - "CodeGenerator/templates", + os.path.join( os.path.dirname( __file__ ), "templates" ), ), TEMPLATE_STRING_IF_INVALID = "We have a logic error in our template or API description", ) -description = json.load( open( "JsonDescriptionOfGithubApiV3/description.001.normalized.json" ) ) +description = json.load( open( os.path.join( os.path.dirname( __file__ ), "JsonDescriptionOfGithubApiV3", "description.001.normalized.json" ) ) ) for class_ in description[ "classes" ]: dependencies = set() @@ -32,7 +33,7 @@ for class_ in description[ "classes" ]: githubObjectTemplate = django.template.loader.get_template( "GithubObject.py" ) for class_ in description[ "classes" ]: - with open( "github/GithubObjects/" + class_[ "name" ] + ".py", "w" ) as f: + with open( os.path.join( os.path.dirname( __file__ ), "..", "src", "github", class_[ "name" ] + ".py" ), "w" ) as f: f.write( "# WARNING: this file is generated automaticaly.\n" ) f.write( "# Do not modify it manually, your work would be lost.\n" ) f.write( "\n" ) @@ -50,7 +51,7 @@ for class_ in description[ "classes" ]: f.write( "\n".join( code ) + "\n" ) referenceOfClassesTemplate = django.template.loader.get_template( "ReferenceOfClasses.md" ) -with open( "ReferenceOfClasses.md", "w" ) as f: +with open( os.path.join( os.path.dirname( __file__ ), "..", "doc", "ReferenceOfClasses.md" ), "w" ) as f: rawCode = referenceOfClassesTemplate.render( django.template.Context( description ) ).split( "\n" ) code = list() for line in rawCode: diff --git a/run_tests.sh b/run_tests.sh index 3585e71f..2ce1b72e 100644 --- a/run_tests.sh +++ b/run_tests.sh @@ -2,11 +2,13 @@ rm -f $(find . -name "*.pyc") +cd test + coverage erase -coverage run NewIntegrationTest.py +coverage run IntegrationTest.py echo "==============" echo "|| Coverage ||" echo "==============" -coverage report -m --include=./* +coverage report -m --include=../src/* diff --git a/src/github/Github.py b/src/github/Github.py index 1eaae474..3e3341d0 100644 --- a/src/github/Github.py +++ b/src/github/Github.py @@ -1,9 +1,9 @@ from Requester import Requester -import GithubObjects.AuthenticatedUser -import GithubObjects.NamedUser -import GithubObjects.Organization -import GithubObjects.Gist -import GithubObjects.PaginatedList +import AuthenticatedUser +import NamedUser +import Organization +import Gist +import PaginatedList class Github: def __init__( self, login, password ): @@ -15,32 +15,32 @@ class Github: "url": "https://api.github.com/user", # @todo Erf, this url is replaced by /users/login when __complete is called... # "login": self.__login # @todo ? } - return GithubObjects.AuthenticatedUser.AuthenticatedUser( self.__requester, attributes, lazy = True ) + return AuthenticatedUser.AuthenticatedUser( self.__requester, attributes, lazy = True ) else: attributes = { "url": "https://api.github.com/users/" + login, "login": login, } - return GithubObjects.NamedUser.NamedUser( self.__requester, attributes, lazy = False ) + return NamedUser.NamedUser( self.__requester, attributes, lazy = False ) def get_organization( self, login ): attributes = { "url": "https://api.github.com/orgs/" + login, "login": login, } - return GithubObjects.Organization.Organization( self.__requester, attributes, lazy = False ) + return Organization.Organization( self.__requester, attributes, lazy = False ) def get_gist( self, id ): attributes = { "url": "https://api.github.com/gists/" + str( id ), "id": id, } - return GithubObjects.Gist.Gist( self.__requester, attributes, lazy = False ) + return Gist.Gist( self.__requester, attributes, lazy = False ) def get_gists( self ): status, headers, data = self.__requester.request( "GET", "https://api.github.com/gists/public", None, None ) - return GithubObjects.PaginatedList.PaginatedList( - GithubObjects.Gist.Gist, + return PaginatedList.PaginatedList( + Gist.Gist, self.__requester, headers, data diff --git a/test/IntegrationTest.py b/test/IntegrationTest.py index 3c37c04d..2060f6b8 100644 --- a/test/IntegrationTest.py +++ b/test/IntegrationTest.py @@ -6,6 +6,8 @@ import unittest import httplib import traceback +sys.path.append( os.path.join( "..", "src" ) ) + import github class FakeHttpResponse: @@ -92,7 +94,7 @@ class TestCase( unittest.TestCase ): def __openFile( self, mode ): for ( _, _, functionName, _ ) in traceback.extract_stack(): if functionName.startswith( "test" ) or functionName == "setUp" or functionName == "tearDown": - fileName = os.path.join( "ReplayDataForNewIntegrationTest", self.__class__.__name__ + "." + functionName + ".txt" ) + fileName = os.path.join( "ReplayData", self.__class__.__name__ + "." + functionName + ".txt" ) if fileName != self.__fileName: self.__closeReplayFileIfNeeded() self.__fileName = fileName