Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
grumpy
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
grumpy
Commits
c0a76bc2
Commit
c0a76bc2
authored
Jan 23, 2017
by
YOU
Committed by
Dylan Trotter
Jan 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unittest for argparse (#200)
parent
7016d5b5
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
4980 additions
and
111 deletions
+4980
-111
third_party/stdlib/argparse.py
third_party/stdlib/argparse.py
+56
-47
third_party/stdlib/test/test_argparse.py
third_party/stdlib/test/test_argparse.py
+4858
-0
third_party/stdlib/test/test_support.py
third_party/stdlib/test/test_support.py
+63
-62
third_party/stdlib/unittest_signals.py
third_party/stdlib/unittest_signals.py
+3
-2
No files found.
third_party/stdlib/argparse.py
View file @
c0a76bc2
This diff is collapsed.
Click to expand it.
third_party/stdlib/test/test_argparse.py
0 → 100644
View file @
c0a76bc2
This diff is collapsed.
Click to expand it.
third_party/stdlib/test/test_support.py
View file @
c0a76bc2
...
...
@@ -9,13 +9,13 @@ import contextlib
# import gc
# import socket
import
sys
#
import os
import
os
# import platform
# import shutil
import
warnings
import
unittest
# import importlib
#
import UserDict
import
UserDict
# import re
# import time
# import struct
...
...
@@ -27,7 +27,8 @@ import unittest
__all__
=
[
"Error"
,
"TestFailed"
,
"have_unicode"
,
"BasicTestRunner"
,
"run_unittest"
,
"check_warnings"
,
"check_py3k_warnings"
"check_warnings"
,
"check_py3k_warnings"
,
"CleanImport"
,
"EnvironmentVarGuard"
]
# __all__ = ["Error", "TestFailed", "ResourceDenied", "import_module",
...
...
@@ -927,83 +928,83 @@ def check_py3k_warnings(*filters, **kwargs):
return
_filterwarnings
(
filters
,
kwargs
.
get
(
'quiet'
))
#
class CleanImport(object):
#
"""Context manager to force import to return a new module reference.
class
CleanImport
(
object
):
"""Context manager to force import to return a new module reference.
#
This is useful for testing module-level behaviours, such as
#
the emission of a DeprecationWarning on import.
This is useful for testing module-level behaviours, such as
the emission of a DeprecationWarning on import.
#
Use like this:
Use like this:
#
with CleanImport("foo"):
#
importlib.import_module("foo") # new reference
#
"""
with CleanImport("foo"):
importlib.import_module("foo") # new reference
"""
#
def __init__(self, *module_names):
#
self.original_modules = sys.modules.copy()
#
for module_name in module_names:
#
if module_name in sys.modules:
#
module = sys.modules[module_name]
#
# It is possible that module_name is just an alias for
#
# another module (e.g. stub for modules renamed in 3.x).
#
# In that case, we also need delete the real module to clear
#
# the import cache.
#
if module.__name__ != module_name:
#
del sys.modules[module.__name__]
#
del sys.modules[module_name]
def
__init__
(
self
,
*
module_names
):
self
.
original_modules
=
sys
.
modules
.
copy
()
for
module_name
in
module_names
:
if
module_name
in
sys
.
modules
:
module
=
sys
.
modules
[
module_name
]
# It is possible that module_name is just an alias for
# another module (e.g. stub for modules renamed in 3.x).
# In that case, we also need delete the real module to clear
# the import cache.
if
module
.
__name__
!=
module_name
:
del
sys
.
modules
[
module
.
__name__
]
del
sys
.
modules
[
module_name
]
#
def __enter__(self):
#
return self
def
__enter__
(
self
):
return
self
#
def __exit__(self, *ignore_exc):
#
sys.modules.update(self.original_modules)
def
__exit__
(
self
,
*
ignore_exc
):
sys
.
modules
.
update
(
self
.
original_modules
)
#
class EnvironmentVarGuard(UserDict.DictMixin):
class
EnvironmentVarGuard
(
UserDict
.
DictMixin
):
#
"""Class to help protect the environment variable properly. Can be used as
#
a context manager."""
"""Class to help protect the environment variable properly. Can be used as
a context manager."""
#
def __init__(self):
#
self._environ = os.environ
#
self._changed = {}
def
__init__
(
self
):
self
.
_environ
=
os
.
environ
self
.
_changed
=
{}
#
def __getitem__(self, envvar):
#
return self._environ[envvar]
def
__getitem__
(
self
,
envvar
):
return
self
.
_environ
[
envvar
]
#
def __setitem__(self, envvar, value):
#
# Remember the initial value on the first access
#
if envvar not in self._changed:
#
self._changed[envvar] = self._environ.get(envvar)
#
self._environ[envvar] = value
def
__setitem__
(
self
,
envvar
,
value
):
# Remember the initial value on the first access
if
envvar
not
in
self
.
_changed
:
self
.
_changed
[
envvar
]
=
self
.
_environ
.
get
(
envvar
)
self
.
_environ
[
envvar
]
=
value
#
def __delitem__(self, envvar):
#
# Remember the initial value on the first access
#
if envvar not in self._changed:
#
self._changed[envvar] = self._environ.get(envvar)
#
if envvar in self._environ:
#
del self._environ[envvar]
def
__delitem__
(
self
,
envvar
):
# Remember the initial value on the first access
if
envvar
not
in
self
.
_changed
:
self
.
_changed
[
envvar
]
=
self
.
_environ
.
get
(
envvar
)
if
envvar
in
self
.
_environ
:
del
self
.
_environ
[
envvar
]
#
def keys(self):
#
return self._environ.keys()
def
keys
(
self
):
return
self
.
_environ
.
keys
()
#
def set(self, envvar, value):
#
self[envvar] = value
def
set
(
self
,
envvar
,
value
):
self
[
envvar
]
=
value
#
def unset(self, envvar):
#
del self[envvar]
def
unset
(
self
,
envvar
):
del
self
[
envvar
]
#
def __enter__(self):
#
return self
def
__enter__
(
self
):
return
self
#
def __exit__(self, *ignore_exc):
#
for (k, v) in self._changed.items():
#
if v is None:
#
if k in self._environ:
#
del self._environ[k]
#
else:
#
self._environ[k] = v
#
os.environ = self._environ
def
__exit__
(
self
,
*
ignore_exc
):
for
(
k
,
v
)
in
self
.
_changed
.
items
():
if
v
is
None
:
if
k
in
self
.
_environ
:
del
self
.
_environ
[
k
]
else
:
self
.
_environ
[
k
]
=
v
os
.
environ
=
self
.
_environ
# class DirsOnSysPath(object):
...
...
third_party/stdlib/unittest_signals.py
View file @
c0a76bc2
# TODO: support signal
# import signal
import
weakref
#
import weakref
# from functools import wraps
import
functools
...
...
@@ -43,7 +43,8 @@ class _InterruptHandler(object):
# for result in _results.keys():
# result.stop()
_results
=
weakref
.
WeakKeyDictionary
()
# _results = weakref.WeakKeyDictionary()
_results
=
{}
def
registerResult
(
result
):
_results
[
result
]
=
1
...
...
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