Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
my2to3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Emmy Vouriot
my2to3
Commits
f4794a4d
Commit
f4794a4d
authored
May 23, 2023
by
Emmeline Vouriot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make testing module more easily changeable
parent
b1f82106
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
36 additions
and
11 deletions
+36
-11
__init__.py
__init__.py
+0
-0
my2to3/hook.py
my2to3/hook.py
+3
-0
tests/__init__.py
tests/__init__.py
+0
-0
tests/sample/__init__.py
tests/sample/__init__.py
+1
-0
tests/sample/__main__.py
tests/sample/__main__.py
+3
-0
tests/test_visit.py
tests/test_visit.py
+2
-0
tests/test_visit_emmy.py
tests/test_visit_emmy.py
+27
-11
No files found.
__init__.py
0 → 100644
View file @
f4794a4d
my2to3/hook.py
View file @
f4794a4d
...
@@ -34,6 +34,9 @@ class Loader(object):
...
@@ -34,6 +34,9 @@ class Loader(object):
self
.
_filename
=
filename
self
.
_filename
=
filename
self
.
_transform
=
transform
self
.
_transform
=
transform
def
is_package
(
self
,
mod_name
):
return
len
(
self
.
_filename
)
>
len
(
self
.
_path
)
def
compile
(
self
,
name
):
def
compile
(
self
,
name
):
filename
=
self
.
_filename
filename
=
self
.
_filename
source
=
self
.
_file
.
read
()
source
=
self
.
_file
.
read
()
...
...
tests/__init__.py
0 → 100644
View file @
f4794a4d
tests/sample/__init__.py
View file @
f4794a4d
import
sample
\ No newline at end of file
tests/sample/__main__.py
0 → 100644
View file @
f4794a4d
1
//
2
print
'hello'
\ No newline at end of file
tests/test_visit.py
View file @
f4794a4d
...
@@ -36,6 +36,8 @@ class TestVisitBinOp(unittest.TestCase):
...
@@ -36,6 +36,8 @@ class TestVisitBinOp(unittest.TestCase):
self
.
_calls
.
append
(
data
)
self
.
_calls
.
append
(
data
)
def
test_visit_sample
(
self
):
def
test_visit_sample
(
self
):
import
sys
print
(
sys
.
argv
)
self
.
_finder
=
Finder
(
'sample'
,
self
.
transform
)
self
.
_finder
=
Finder
(
'sample'
,
self
.
transform
)
sys
.
meta_path
.
append
(
self
.
_finder
)
sys
.
meta_path
.
append
(
self
.
_finder
)
...
...
tests/test_visit_emmy.py
View file @
f4794a4d
...
@@ -7,11 +7,9 @@ import unittest
...
@@ -7,11 +7,9 @@ import unittest
import
sys
import
sys
import
context
import
context
from
my2to3.hook
import
Finder
from
..my2to3.hook
import
Finder
from
my2to3.visit
import
DepthVisitor
from
..my2to3.visit
import
DepthVisitor
from
my2to3.visit
import
InstrumentVisitor
from
..my2to3.visit
import
InstrumentVisitor
import
my2to3.runtime
class
BinOpVisitor
(
InstrumentVisitor
):
class
BinOpVisitor
(
InstrumentVisitor
):
...
@@ -160,20 +158,23 @@ class AddLogFunc(ast.NodeTransformer):
...
@@ -160,20 +158,23 @@ class AddLogFunc(ast.NodeTransformer):
node
=
add_log_string_node
(
node
,
self
.
_output_log
)
node
=
add_log_string_node
(
node
,
self
.
_output_log
)
return
node
return
node
import
os
LOG_PATH
=
os
.
path
.
dirname
(
__file__
)
+
"/../logs/logs_dyn_injection"
class
TestVisitBinOp
(
unittest
.
TestCase
):
class
TestVisitBinOp
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
_calls
=
[]
self
.
_calls
=
[]
self
.
_finder
=
None
self
.
_finder
=
None
if
not
os
.
path
.
exists
(
"../logs/logs_dyn_injection"
):
if
not
os
.
path
.
exists
(
LOG_PATH
):
os
.
makedirs
(
"../logs/logs_dyn_injection"
)
os
.
makedirs
(
LOG_PATH
)
else
:
else
:
for
test
in
os
.
listdir
(
"../logs/logs_dyn_injection"
):
for
test
in
os
.
listdir
(
LOG_PATH
):
if
test
.
endswith
(
".txt"
):
if
test
.
endswith
(
".txt"
):
os
.
remove
(
"../logs/logs_dyn_injection
/"
+
test
)
os
.
remove
(
LOG_PATH
+
"
/"
+
test
)
def
transform
(
self
,
source
,
name
,
filename
):
@
staticmethod
def
transform
(
source
,
name
,
filename
):
tree
=
ast
.
parse
(
source
,
filename
)
tree
=
ast
.
parse
(
source
,
filename
)
i
=
0
i
=
0
for
node
in
ast
.
walk
(
tree
):
# todo find a function with a specified order
for
node
in
ast
.
walk
(
tree
):
# todo find a function with a specified order
...
@@ -181,7 +182,7 @@ class TestVisitBinOp(unittest.TestCase):
...
@@ -181,7 +182,7 @@ class TestVisitBinOp(unittest.TestCase):
for
child
in
ast
.
iter_child_nodes
(
node
):
for
child
in
ast
.
iter_child_nodes
(
node
):
child
.
parent
=
(
i
,
node
)
child
.
parent
=
(
i
,
node
)
i
+=
1
i
+=
1
ast
.
fix_missing_locations
(
AddLogFunc
(
source
,
(
"../logs/logs_dyn_injection
/"
+
name
+
".txt"
,
filename
)).
visit
(
tree
))
ast
.
fix_missing_locations
(
AddLogFunc
(
source
,
(
LOG_PATH
+
"
/"
+
name
+
".txt"
,
filename
)).
visit
(
tree
))
return
tree
return
tree
def
info
(
self
,
data
):
def
info
(
self
,
data
):
...
@@ -204,6 +205,21 @@ class TestVisitBinOp(unittest.TestCase):
...
@@ -204,6 +205,21 @@ class TestVisitBinOp(unittest.TestCase):
]
]
)
)
def
test_visit_re6st
(
self
):
self
.
_finder
=
Finder
(
're6st'
,
self
.
transform
)
sys
.
meta_path
.
append
(
self
.
_finder
)
my2to3
.
runtime
.
logger
=
self
self
.
assertEqual
(
len
(
self
.
_calls
),
2
)
self
.
assertEqual
(
self
.
_calls
,
[
'{"loc": {"depth": 3, "col": 4, "line": 5, "name": "sample.sample"}, "type": "<type
\
'
int
\
'
>", "value": "2", "desc": null}'
,
'{"loc": {"depth": 3, "col": 8, "line": 5, "name": "sample.sample"}, "type": "<type
\
'
int
\
'
>", "value": "3", "desc": null}'
]
)
def
tearDown
(
self
):
def
tearDown
(
self
):
del
my2to3
.
runtime
.
logger
del
my2to3
.
runtime
.
logger
sys
.
meta_path
.
remove
(
self
.
_finder
)
sys
.
meta_path
.
remove
(
self
.
_finder
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment