Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
"""
|
|
|
|
Test the API of the symtable module.
|
|
|
|
"""
|
2005-11-24 23:15:49 -04:00
|
|
|
import symtable
|
2006-01-23 03:49:36 -04:00
|
|
|
import unittest
|
2001-02-02 14:24:26 -04:00
|
|
|
|
2023-11-07 12:32:16 -04:00
|
|
|
from test import support
|
|
|
|
from test.support import os_helper
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
|
|
|
|
|
|
|
|
TEST_CODE = """
|
|
|
|
import sys
|
|
|
|
|
|
|
|
glob = 42
|
2018-10-19 21:46:00 -03:00
|
|
|
some_var = 12
|
2020-10-03 16:45:55 -03:00
|
|
|
some_non_assigned_global_var = 11
|
|
|
|
some_assigned_global_var = 11
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
|
|
|
|
class Mine:
|
|
|
|
instance_var = 24
|
|
|
|
def a_method(p1, p2):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def spam(a, b, *var, **kw):
|
|
|
|
global bar
|
2020-10-03 16:45:55 -03:00
|
|
|
global some_assigned_global_var
|
|
|
|
some_assigned_global_var = 12
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
bar = 47
|
2018-10-19 21:46:00 -03:00
|
|
|
some_var = 10
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
x = 23
|
|
|
|
glob
|
|
|
|
def internal():
|
|
|
|
return x
|
2018-10-19 21:46:00 -03:00
|
|
|
def other_internal():
|
|
|
|
nonlocal some_var
|
|
|
|
some_var = 3
|
|
|
|
return some_var
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
return internal
|
2001-02-09 18:57:10 -04:00
|
|
|
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
def foo():
|
|
|
|
pass
|
2003-07-15 17:24:27 -03:00
|
|
|
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
def namespace_test(): pass
|
|
|
|
def namespace_test(): pass
|
2023-09-28 23:08:04 -03:00
|
|
|
|
|
|
|
type Alias = int
|
|
|
|
type GenericAlias[T] = list[T]
|
|
|
|
|
|
|
|
def generic_spam[T](a):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class GenericMine[T: int]:
|
|
|
|
pass
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def find_block(block, name):
|
|
|
|
for ch in block.get_children():
|
|
|
|
if ch.get_name() == name:
|
|
|
|
return ch
|
2005-10-20 11:27:21 -03:00
|
|
|
|
2006-01-23 03:49:36 -04:00
|
|
|
|
|
|
|
class SymtableTest(unittest.TestCase):
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
|
|
|
|
top = symtable.symtable(TEST_CODE, "?", "exec")
|
|
|
|
# These correspond to scopes in TEST_CODE
|
|
|
|
Mine = find_block(top, "Mine")
|
|
|
|
a_method = find_block(Mine, "a_method")
|
|
|
|
spam = find_block(top, "spam")
|
|
|
|
internal = find_block(spam, "internal")
|
2018-10-19 21:46:00 -03:00
|
|
|
other_internal = find_block(spam, "other_internal")
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
foo = find_block(top, "foo")
|
2023-09-28 23:08:04 -03:00
|
|
|
Alias = find_block(top, "Alias")
|
|
|
|
GenericAlias = find_block(top, "GenericAlias")
|
|
|
|
GenericAlias_inner = find_block(GenericAlias, "GenericAlias")
|
|
|
|
generic_spam = find_block(top, "generic_spam")
|
|
|
|
generic_spam_inner = find_block(generic_spam, "generic_spam")
|
|
|
|
GenericMine = find_block(top, "GenericMine")
|
|
|
|
GenericMine_inner = find_block(GenericMine, "GenericMine")
|
|
|
|
T = find_block(GenericMine, "T")
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
|
|
|
|
def test_type(self):
|
|
|
|
self.assertEqual(self.top.get_type(), "module")
|
|
|
|
self.assertEqual(self.Mine.get_type(), "class")
|
|
|
|
self.assertEqual(self.a_method.get_type(), "function")
|
|
|
|
self.assertEqual(self.spam.get_type(), "function")
|
|
|
|
self.assertEqual(self.internal.get_type(), "function")
|
2023-09-28 23:08:04 -03:00
|
|
|
self.assertEqual(self.foo.get_type(), "function")
|
|
|
|
self.assertEqual(self.Alias.get_type(), "type alias")
|
|
|
|
self.assertEqual(self.GenericAlias.get_type(), "type parameter")
|
|
|
|
self.assertEqual(self.GenericAlias_inner.get_type(), "type alias")
|
|
|
|
self.assertEqual(self.generic_spam.get_type(), "type parameter")
|
|
|
|
self.assertEqual(self.generic_spam_inner.get_type(), "function")
|
|
|
|
self.assertEqual(self.GenericMine.get_type(), "type parameter")
|
|
|
|
self.assertEqual(self.GenericMine_inner.get_type(), "class")
|
|
|
|
self.assertEqual(self.T.get_type(), "TypeVar bound")
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
|
2020-07-07 21:45:45 -03:00
|
|
|
def test_id(self):
|
|
|
|
self.assertGreater(self.top.get_id(), 0)
|
|
|
|
self.assertGreater(self.Mine.get_id(), 0)
|
|
|
|
self.assertGreater(self.a_method.get_id(), 0)
|
|
|
|
self.assertGreater(self.spam.get_id(), 0)
|
|
|
|
self.assertGreater(self.internal.get_id(), 0)
|
2023-09-28 23:08:04 -03:00
|
|
|
self.assertGreater(self.foo.get_id(), 0)
|
|
|
|
self.assertGreater(self.Alias.get_id(), 0)
|
|
|
|
self.assertGreater(self.GenericAlias.get_id(), 0)
|
|
|
|
self.assertGreater(self.generic_spam.get_id(), 0)
|
|
|
|
self.assertGreater(self.GenericMine.get_id(), 0)
|
2020-07-07 21:45:45 -03:00
|
|
|
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
def test_optimized(self):
|
|
|
|
self.assertFalse(self.top.is_optimized())
|
|
|
|
|
|
|
|
self.assertTrue(self.spam.is_optimized())
|
|
|
|
|
|
|
|
def test_nested(self):
|
|
|
|
self.assertFalse(self.top.is_nested())
|
|
|
|
self.assertFalse(self.Mine.is_nested())
|
|
|
|
self.assertFalse(self.spam.is_nested())
|
|
|
|
self.assertTrue(self.internal.is_nested())
|
|
|
|
|
|
|
|
def test_children(self):
|
|
|
|
self.assertTrue(self.top.has_children())
|
|
|
|
self.assertTrue(self.Mine.has_children())
|
|
|
|
self.assertFalse(self.foo.has_children())
|
|
|
|
|
|
|
|
def test_lineno(self):
|
|
|
|
self.assertEqual(self.top.get_lineno(), 0)
|
2020-10-03 16:45:55 -03:00
|
|
|
self.assertEqual(self.spam.get_lineno(), 14)
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
|
|
|
|
def test_function_info(self):
|
|
|
|
func = self.spam
|
2012-01-03 18:23:11 -04:00
|
|
|
self.assertEqual(sorted(func.get_parameters()), ["a", "b", "kw", "var"])
|
2018-10-19 21:46:00 -03:00
|
|
|
expected = ['a', 'b', 'internal', 'kw', 'other_internal', 'some_var', 'var', 'x']
|
2012-01-03 18:23:11 -04:00
|
|
|
self.assertEqual(sorted(func.get_locals()), expected)
|
2020-10-03 16:45:55 -03:00
|
|
|
self.assertEqual(sorted(func.get_globals()), ["bar", "glob", "some_assigned_global_var"])
|
2008-08-20 09:55:31 -03:00
|
|
|
self.assertEqual(self.internal.get_frees(), ("x",))
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
|
|
|
|
def test_globals(self):
|
|
|
|
self.assertTrue(self.spam.lookup("glob").is_global())
|
2009-03-31 12:26:37 -03:00
|
|
|
self.assertFalse(self.spam.lookup("glob").is_declared_global())
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
self.assertTrue(self.spam.lookup("bar").is_global())
|
2009-03-31 12:26:37 -03:00
|
|
|
self.assertTrue(self.spam.lookup("bar").is_declared_global())
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
self.assertFalse(self.internal.lookup("x").is_global())
|
|
|
|
self.assertFalse(self.Mine.lookup("instance_var").is_global())
|
2020-04-06 13:05:57 -03:00
|
|
|
self.assertTrue(self.spam.lookup("bar").is_global())
|
2020-10-03 16:45:55 -03:00
|
|
|
# Module-scope globals are both global and local
|
|
|
|
self.assertTrue(self.top.lookup("some_non_assigned_global_var").is_global())
|
|
|
|
self.assertTrue(self.top.lookup("some_assigned_global_var").is_global())
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
|
2018-10-19 21:46:00 -03:00
|
|
|
def test_nonlocal(self):
|
|
|
|
self.assertFalse(self.spam.lookup("some_var").is_nonlocal())
|
|
|
|
self.assertTrue(self.other_internal.lookup("some_var").is_nonlocal())
|
|
|
|
expected = ("some_var",)
|
|
|
|
self.assertEqual(self.other_internal.get_nonlocals(), expected)
|
|
|
|
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
def test_local(self):
|
|
|
|
self.assertTrue(self.spam.lookup("x").is_local())
|
2020-04-06 13:05:57 -03:00
|
|
|
self.assertFalse(self.spam.lookup("bar").is_local())
|
2020-10-03 16:45:55 -03:00
|
|
|
# Module-scope globals are both global and local
|
|
|
|
self.assertTrue(self.top.lookup("some_non_assigned_global_var").is_local())
|
|
|
|
self.assertTrue(self.top.lookup("some_assigned_global_var").is_local())
|
2020-04-06 13:05:57 -03:00
|
|
|
|
|
|
|
def test_free(self):
|
|
|
|
self.assertTrue(self.internal.lookup("x").is_free())
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
|
|
|
|
def test_referenced(self):
|
|
|
|
self.assertTrue(self.internal.lookup("x").is_referenced())
|
|
|
|
self.assertTrue(self.spam.lookup("internal").is_referenced())
|
|
|
|
self.assertFalse(self.spam.lookup("x").is_referenced())
|
|
|
|
|
|
|
|
def test_parameters(self):
|
|
|
|
for sym in ("a", "var", "kw"):
|
|
|
|
self.assertTrue(self.spam.lookup(sym).is_parameter())
|
|
|
|
self.assertFalse(self.spam.lookup("x").is_parameter())
|
|
|
|
|
|
|
|
def test_symbol_lookup(self):
|
|
|
|
self.assertEqual(len(self.top.get_identifiers()),
|
|
|
|
len(self.top.get_symbols()))
|
|
|
|
|
|
|
|
self.assertRaises(KeyError, self.top.lookup, "not_here")
|
|
|
|
|
|
|
|
def test_namespaces(self):
|
|
|
|
self.assertTrue(self.top.lookup("Mine").is_namespace())
|
|
|
|
self.assertTrue(self.Mine.lookup("a_method").is_namespace())
|
|
|
|
self.assertTrue(self.top.lookup("spam").is_namespace())
|
|
|
|
self.assertTrue(self.spam.lookup("internal").is_namespace())
|
|
|
|
self.assertTrue(self.top.lookup("namespace_test").is_namespace())
|
|
|
|
self.assertFalse(self.spam.lookup("x").is_namespace())
|
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(self.top.lookup("spam").get_namespace() is self.spam)
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
ns_test = self.top.lookup("namespace_test")
|
|
|
|
self.assertEqual(len(ns_test.get_namespaces()), 2)
|
|
|
|
self.assertRaises(ValueError, ns_test.get_namespace)
|
|
|
|
|
2021-07-18 09:56:09 -03:00
|
|
|
ns_test_2 = self.top.lookup("glob")
|
|
|
|
self.assertEqual(len(ns_test_2.get_namespaces()), 0)
|
|
|
|
self.assertRaises(ValueError, ns_test_2.get_namespace)
|
|
|
|
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
def test_assigned(self):
|
|
|
|
self.assertTrue(self.spam.lookup("x").is_assigned())
|
|
|
|
self.assertTrue(self.spam.lookup("bar").is_assigned())
|
|
|
|
self.assertTrue(self.top.lookup("spam").is_assigned())
|
|
|
|
self.assertTrue(self.Mine.lookup("a_method").is_assigned())
|
|
|
|
self.assertFalse(self.internal.lookup("x").is_assigned())
|
|
|
|
|
2016-09-09 00:50:03 -03:00
|
|
|
def test_annotated(self):
|
|
|
|
st1 = symtable.symtable('def f():\n x: int\n', 'test', 'exec')
|
|
|
|
st2 = st1.get_children()[0]
|
|
|
|
self.assertTrue(st2.lookup('x').is_local())
|
|
|
|
self.assertTrue(st2.lookup('x').is_annotated())
|
|
|
|
self.assertFalse(st2.lookup('x').is_global())
|
|
|
|
st3 = symtable.symtable('def f():\n x = 1\n', 'test', 'exec')
|
|
|
|
st4 = st3.get_children()[0]
|
|
|
|
self.assertTrue(st4.lookup('x').is_local())
|
|
|
|
self.assertFalse(st4.lookup('x').is_annotated())
|
|
|
|
|
2018-10-14 14:01:03 -03:00
|
|
|
# Test that annotations in the global scope are valid after the
|
|
|
|
# variable is declared as nonlocal.
|
|
|
|
st5 = symtable.symtable('global x\nx: int', 'test', 'exec')
|
|
|
|
self.assertTrue(st5.lookup("x").is_global())
|
|
|
|
|
|
|
|
# Test that annotations for nonlocals are valid after the
|
|
|
|
# variable is declared as nonlocal.
|
|
|
|
st6 = symtable.symtable('def g():\n'
|
|
|
|
' x = 2\n'
|
|
|
|
' def f():\n'
|
|
|
|
' nonlocal x\n'
|
|
|
|
' x: int',
|
|
|
|
'test', 'exec')
|
|
|
|
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
def test_imported(self):
|
|
|
|
self.assertTrue(self.top.lookup("sys").is_imported())
|
|
|
|
|
|
|
|
def test_name(self):
|
|
|
|
self.assertEqual(self.top.get_name(), "top")
|
|
|
|
self.assertEqual(self.spam.get_name(), "spam")
|
|
|
|
self.assertEqual(self.spam.lookup("x").get_name(), "x")
|
|
|
|
self.assertEqual(self.Mine.get_name(), "Mine")
|
|
|
|
|
|
|
|
def test_class_info(self):
|
2008-08-20 09:55:31 -03:00
|
|
|
self.assertEqual(self.Mine.get_methods(), ('a_method',))
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
|
|
|
|
def test_filename_correct(self):
|
|
|
|
### Bug tickler: SyntaxError file name correct whether error raised
|
|
|
|
### while parsing or building symbol table.
|
2016-12-11 08:39:01 -04:00
|
|
|
def checkfilename(brokencode, offset):
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
try:
|
|
|
|
symtable.symtable(brokencode, "spam", "exec")
|
|
|
|
except SyntaxError as e:
|
|
|
|
self.assertEqual(e.filename, "spam")
|
2016-12-11 08:39:01 -04:00
|
|
|
self.assertEqual(e.lineno, 1)
|
|
|
|
self.assertEqual(e.offset, offset)
|
Merged revisions 65715,65724,65726,65732,65736-65739,65775 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65715 | benjamin.peterson | 2008-08-16 16:04:16 -0500 (Sat, 16 Aug 2008) | 1 line
add some documentation for symtable
........
r65724 | benjamin.peterson | 2008-08-16 17:11:33 -0500 (Sat, 16 Aug 2008) | 2 lines
include filename and line number in SyntaxError
........
r65726 | georg.brandl | 2008-08-16 17:37:05 -0500 (Sat, 16 Aug 2008) | 2 lines
Review symtable docs.
........
r65732 | benjamin.peterson | 2008-08-16 18:29:40 -0500 (Sat, 16 Aug 2008) | 1 line
PySTEntry's constructor is static; there's no point in a fancy API name
........
r65736 | benjamin.peterson | 2008-08-16 20:09:17 -0500 (Sat, 16 Aug 2008) | 1 line
expose PySTEntry.nested so the symtable module will work
........
r65737 | benjamin.peterson | 2008-08-16 20:17:15 -0500 (Sat, 16 Aug 2008) | 1 line
a few improvements
........
r65738 | benjamin.peterson | 2008-08-16 20:27:30 -0500 (Sat, 16 Aug 2008) | 1 line
fix compile errors
........
r65739 | benjamin.peterson | 2008-08-16 21:23:43 -0500 (Sat, 16 Aug 2008) | 1 line
uhh PySTEntry->ste_unoptimized has to be exposed too
........
r65775 | benjamin.peterson | 2008-08-17 12:13:26 -0500 (Sun, 17 Aug 2008) | 5 lines
get the symtable module back in working order
- Fix broken functions
- Add (hopefully) extensive tests
- Modernize a little
........
2008-08-17 15:02:44 -03:00
|
|
|
else:
|
|
|
|
self.fail("no SyntaxError for %r" % (brokencode,))
|
2016-12-11 08:39:01 -04:00
|
|
|
checkfilename("def f(x): foo)(", 14) # parse-time
|
2018-09-24 18:12:49 -03:00
|
|
|
checkfilename("def f(x): global x", 11) # symtable-build-time
|
2016-06-18 07:53:36 -03:00
|
|
|
symtable.symtable("pass", b"spam", "exec")
|
2022-10-18 12:52:31 -03:00
|
|
|
with self.assertRaises(TypeError):
|
2016-06-18 07:53:36 -03:00
|
|
|
symtable.symtable("pass", bytearray(b"spam"), "exec")
|
2022-10-18 12:52:31 -03:00
|
|
|
with self.assertRaises(TypeError):
|
2016-08-06 17:29:29 -03:00
|
|
|
symtable.symtable("pass", memoryview(b"spam"), "exec")
|
2016-06-18 07:53:36 -03:00
|
|
|
with self.assertRaises(TypeError):
|
|
|
|
symtable.symtable("pass", list(b"spam"), "exec")
|
2006-01-23 03:49:36 -04:00
|
|
|
|
|
|
|
def test_eval(self):
|
|
|
|
symbols = symtable.symtable("42", "?", "eval")
|
|
|
|
|
|
|
|
def test_single(self):
|
|
|
|
symbols = symtable.symtable("42", "?", "single")
|
|
|
|
|
|
|
|
def test_exec(self):
|
|
|
|
symbols = symtable.symtable("def f(x): return x", "?", "exec")
|
|
|
|
|
2019-05-28 20:21:17 -03:00
|
|
|
def test_bytes(self):
|
|
|
|
top = symtable.symtable(TEST_CODE.encode('utf8'), "?", "exec")
|
|
|
|
self.assertIsNotNone(find_block(top, "Mine"))
|
|
|
|
|
|
|
|
code = b'# -*- coding: iso8859-15 -*-\nclass \xb4: pass\n'
|
|
|
|
|
|
|
|
top = symtable.symtable(code, "?", "exec")
|
|
|
|
self.assertIsNotNone(find_block(top, "\u017d"))
|
|
|
|
|
2020-10-03 16:45:55 -03:00
|
|
|
def test_symtable_repr(self):
|
|
|
|
self.assertEqual(str(self.top), "<SymbolTable for module ?>")
|
|
|
|
self.assertEqual(str(self.spam), "<Function SymbolTable for spam in ?>")
|
|
|
|
|
2023-11-07 12:32:16 -04:00
|
|
|
def test_symbol_repr(self):
|
|
|
|
self.assertEqual(repr(self.spam.lookup("glob")),
|
|
|
|
"<symbol 'glob': GLOBAL_IMPLICIT, USE>")
|
|
|
|
self.assertEqual(repr(self.spam.lookup("bar")),
|
|
|
|
"<symbol 'bar': GLOBAL_EXPLICIT, DEF_GLOBAL|DEF_LOCAL>")
|
|
|
|
self.assertEqual(repr(self.spam.lookup("a")),
|
|
|
|
"<symbol 'a': LOCAL, DEF_PARAM>")
|
|
|
|
self.assertEqual(repr(self.spam.lookup("internal")),
|
|
|
|
"<symbol 'internal': LOCAL, USE|DEF_LOCAL>")
|
|
|
|
self.assertEqual(repr(self.spam.lookup("other_internal")),
|
|
|
|
"<symbol 'other_internal': LOCAL, DEF_LOCAL>")
|
|
|
|
self.assertEqual(repr(self.internal.lookup("x")),
|
|
|
|
"<symbol 'x': FREE, USE>")
|
|
|
|
self.assertEqual(repr(self.other_internal.lookup("some_var")),
|
|
|
|
"<symbol 'some_var': FREE, USE|DEF_NONLOCAL|DEF_LOCAL>")
|
|
|
|
|
2023-09-10 09:04:24 -03:00
|
|
|
def test_symtable_entry_repr(self):
|
|
|
|
expected = f"<symtable entry top({self.top.get_id()}), line {self.top.get_lineno()}>"
|
|
|
|
self.assertEqual(repr(self.top._table), expected)
|
|
|
|
|
2006-01-23 03:49:36 -04:00
|
|
|
|
2023-11-07 12:32:16 -04:00
|
|
|
class CommandLineTest(unittest.TestCase):
|
|
|
|
maxDiff = None
|
|
|
|
|
|
|
|
def test_file(self):
|
|
|
|
filename = os_helper.TESTFN
|
|
|
|
self.addCleanup(os_helper.unlink, filename)
|
|
|
|
with open(filename, 'w') as f:
|
|
|
|
f.write(TEST_CODE)
|
|
|
|
with support.captured_stdout() as stdout:
|
|
|
|
symtable.main([filename])
|
|
|
|
out = stdout.getvalue()
|
|
|
|
self.assertIn('\n\n', out)
|
|
|
|
self.assertNotIn('\n\n\n', out)
|
|
|
|
lines = out.splitlines()
|
|
|
|
self.assertIn(f"symbol table for module from file {filename!r}:", lines)
|
|
|
|
self.assertIn(" local symbol 'glob': def_local", lines)
|
|
|
|
self.assertIn(" global_implicit symbol 'glob': use", lines)
|
|
|
|
self.assertIn(" local symbol 'spam': def_local", lines)
|
|
|
|
self.assertIn(" symbol table for function 'spam':", lines)
|
|
|
|
|
|
|
|
def test_stdin(self):
|
|
|
|
with support.captured_stdin() as stdin:
|
|
|
|
stdin.write(TEST_CODE)
|
|
|
|
stdin.seek(0)
|
|
|
|
with support.captured_stdout() as stdout:
|
|
|
|
symtable.main([])
|
|
|
|
out = stdout.getvalue()
|
|
|
|
stdin.seek(0)
|
|
|
|
with support.captured_stdout() as stdout:
|
|
|
|
symtable.main(['-'])
|
|
|
|
self.assertEqual(stdout.getvalue(), out)
|
|
|
|
lines = out.splitlines()
|
|
|
|
self.assertIn("symbol table for module from file '<stdin>':", lines)
|
|
|
|
|
|
|
|
|
2006-01-23 03:49:36 -04:00
|
|
|
if __name__ == '__main__':
|
2015-04-13 17:00:43 -03:00
|
|
|
unittest.main()
|