-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zope 4: Restore filename on code objects: `App.Extensions.getObject()…
…`. (#1139) * Port of #1138 to Zope 4. * Get back Python 2.7. * Fix builds: Build on pushes to every Zope 4.x branch. Leave out pull requests as they were are disabled later on.
- Loading branch information
Michael Howitz
committed
Jun 19, 2023
1 parent
828b197
commit 601c8f7
Showing
6 changed files
with
54 additions
and
5 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,2 @@ | ||
# This file intentionally contains a SyntaxError | ||
a = # noqa |
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,5 @@ | ||
import sys | ||
|
||
|
||
def f1(): | ||
return sys._getframe(0).f_code.co_filename |
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,40 @@ | ||
import os.path | ||
import types | ||
import unittest | ||
|
||
import App.config | ||
from App.Extensions import getObject | ||
|
||
|
||
class GetObjectTests(unittest.TestCase): | ||
"""Testing ..Extensions.getObject().""" | ||
|
||
def setUp(self): | ||
cfg = App.config.getConfiguration() | ||
assert not hasattr(cfg, 'extensions') | ||
cfg.extensions = os.path.join(os.path.dirname(__file__), 'fixtures') | ||
|
||
def tearDown(self): | ||
cfg = App.config.getConfiguration() | ||
del cfg.extensions | ||
|
||
def test_Extensions__getObject__1(self): | ||
"""Check that "getObject" returns the requested function and ... | ||
that its code object has the path set. | ||
""" | ||
obj = getObject('getObject', 'f1') | ||
self.assertIsInstance(obj, types.FunctionType) | ||
self.assertEqual(obj.__name__, 'f1') | ||
path = obj() | ||
self.assertTrue( | ||
path.endswith( | ||
os.path.sep.join( | ||
['App', 'tests', 'fixtures', 'getObject.py']))) | ||
|
||
def test_Extensions__getObject__2(self): | ||
"""It raises a SyntaxError if necessary.""" | ||
try: | ||
getObject('error', 'f1') | ||
except SyntaxError as e: | ||
self.assertEqual(str(e), 'invalid syntax (error.py, line 2)') |