forked from cython/cython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify utility code loader as per discussion + tests
- Loading branch information
1 parent
3f8fefb
commit 2599deb
Showing
12 changed files
with
169 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import unittest | ||
|
||
from Cython.Compiler import Code, UtilityCode | ||
|
||
|
||
def strip_2tup(tup): | ||
return tup[0] and tup[0].strip(), tup[1] and tup[1].strip() | ||
|
||
class TestUtilityLoader(unittest.TestCase): | ||
""" | ||
Test loading UtilityCodes | ||
""" | ||
|
||
expected = "test {{loader}} prototype", "test {{loader}} impl" | ||
expected_tempita = (expected[0].replace('{{loader}}', 'Loader'), | ||
expected[1].replace('{{loader}}', 'Loader')) | ||
|
||
required = "I am a dependency proto", "I am a dependency impl" | ||
|
||
context = dict(loader='Loader') | ||
|
||
name = "TestUtilityLoader" | ||
filename = "TestUtilityLoader.c" | ||
cls = Code.UtilityCode | ||
|
||
def test_load_as_string(self): | ||
got = strip_2tup(self.cls.load_as_string(self.name)) | ||
self.assertEquals(got, self.expected) | ||
|
||
got = strip_2tup(self.cls.load_as_string(self.name, self.filename)) | ||
self.assertEquals(got, self.expected) | ||
|
||
got = strip_2tup(self.cls.load_as_string(self.name, context=self.context)) | ||
self.assertEquals(got, self.expected_tempita) | ||
|
||
def test_load(self): | ||
utility = self.cls.load(self.name) | ||
got = strip_2tup((utility.proto, utility.impl)) | ||
self.assertEquals(got, self.expected) | ||
|
||
# Not implemented yet | ||
#required, = utility.requires | ||
#self.assertEquals((required.proto, required.impl), self.required) | ||
|
||
utility = self.cls.load(self.name, from_file=self.filename) | ||
got = strip_2tup((utility.proto, utility.impl)) | ||
self.assertEquals(got, self.expected) | ||
|
||
|
||
class TestCythonUtilityLoader(TestUtilityLoader): | ||
""" | ||
Test loading CythonUtilityCodes | ||
""" | ||
|
||
# Just change the attributes and run the same tests | ||
expected = None, "test {{cy_loader}} impl" | ||
expected_tempita = None, "test CyLoader impl" | ||
|
||
required = None, "I am a Cython dependency impl" | ||
|
||
context = dict(cy_loader='CyLoader') | ||
|
||
name = "TestCyUtilityLoader" | ||
filename = "TestCyUtilityLoader.pyx" | ||
cls = UtilityCode.CythonUtilityCode | ||
|
||
# Small hack to pass our tests above | ||
cls.proto = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
########## TestCyUtilityLoader ########## | ||
test {{cy_loader}} impl |
Oops, something went wrong.