FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bpython/bpython/test/test_sitefix.py at reloading-sys · LongJohnCoder/bpython · GitHub
LongJohnCoder
/
bpython
Public
forked from
bpython/bpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
bpython
/
bpython
/
test
/
test_sitefix.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (36 loc) · 1.56 KB
Breadcrumbs
bpython
/
bpython
/
test
/
test_sitefix.py
Copy path
File metadata and controls
45 lines (36 loc) · 1.56 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import
sys
import
optparse
from
bpython
.
test
import
FixLanguageTestCase
as
TestCase
from
bpython
.
_py3compat
import
py3
from
bpython
.
curtsiesfrontend
import
sitefix
class
AttrReplaced
(
object
):
def
__init__
(
self
,
module
,
attr
,
replacement
):
self
.
module
=
module
self
.
attr
=
attr
self
.
replacement
=
replacement
def
__enter__
(
self
):
if
hasattr
(
self
.
module
,
self
.
attr
):
self
.
orig_value
=
getattr
(
self
.
module
,
self
.
attr
)
setattr
(
self
.
module
,
self
.
attr
,
self
.
replacement
)
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
if
hasattr
(
self
,
'orig_value'
):
setattr
(
self
.
module
,
self
.
attr
,
self
.
replacement
)
else
:
delattr
(
self
.
module
,
self
.
attr
)
class
TestCurtsiesReevaluateWithImport
(
TestCase
):
def
test_reload_works
(
self
):
orig
=
optparse
.
SUPPRESS_HELP
with
AttrReplaced
(
optparse
,
'SUPPRESS_HELP'
,
1
):
# reload(optparse)
sitefix
.
reload
(
optparse
)
self
.
assertEqual
(
optparse
.
SUPPRESS_HELP
,
orig
)
def
test_reload_sys
(
self
):
with
AttrReplaced
(
sys
,
'stdin'
,
1
):
with
AttrReplaced
(
sys
,
'a'
,
2
):
with
AttrReplaced
(
sys
,
'version'
,
3
):
sitefix
.
reload
(
sys
)
self
.
assertEqual
(
sys
.
a
,
2
)
# new attrs stick around
self
.
assertEqual
(
sys
.
stdin
,
1
)
# stdin stays
if
not
py3
:
# In Python 3 sys attributes are not replaced on reload
self
.
assertNotEqual
(
sys
.
version
,
3
)
# in Python 2
Back
|
FazBrowse Home
|
New Git URL