Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
unittest and doctest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SOFT Core
SOFT 161 and 162
unittest and doctest
Commits
d18c730f
Commit
d18c730f
authored
4 years ago
by
Christopher Bohn
Browse files
Options
Downloads
Patches
Plain Diff
Initial Commit
parents
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+28
-0
28 additions, 0 deletions
.gitignore
examples.py
+24
-0
24 additions, 0 deletions
examples.py
test_parse.py
+16
-0
16 additions, 0 deletions
test_parse.py
with
68 additions
and
0 deletions
.gitignore
0 → 100644
+
28
−
0
View file @
d18c730f
# Mac file finder metadata
.DS_Store
# Windows file metadata
._*
# Thumbnail image caches
Thumbs.db
ethumbs.db
# MS Office temporary file
~*
# Emacs backup file
*~
# Common
bin
# Python files
*.pyc
*.pyo
__pycache__/
# JetBrains (IntelliJ IDEA, PyCharm, etc) files
.idea/
cmake-build-*/
*.iml
*.iws
*.ipr
venv/
This diff is collapsed.
Click to expand it.
examples.py
0 → 100644
+
24
−
0
View file @
d18c730f
# A function with associated doctests.
def
parse
(
pair
):
"""
Converts a key/value pair represented as a string to a key/value pair represented as a tuple.
Key/value pairs are expected to be separated by a colon and a space:
>>>
parse
(
'
a key: a value
'
)
(
'
a key
'
,
'
a value
'
)
If there is no colon and space, parse raises a ValueError:
>>>
parse
(
'
invalid
'
)
Traceback
(
most
recent
call
last
):
...
ValueError
:
need
more
than
1
value
to
unpack
Likewise if there is more than one separator:
>>>
parse
(
'
first: second: third
'
)
Traceback
(
most
recent
call
last
):
...
ValueError
:
too
many
values
to
unpack
(
expected
2
)
"""
key
,
value
=
pair
.
split
(
'
:
'
)
return
key
,
value
This diff is collapsed.
Click to expand it.
test_parse.py
0 → 100644
+
16
−
0
View file @
d18c730f
from
unittest
import
TestCase
import
examples
# The same tests in a separate unit-testing class.
class
TestParse
(
TestCase
):
# assertEqual is like a reversed version of assertEquals from JUnit.
def
test_parse
(
self
):
self
.
assertEqual
(
examples
.
parse
(
'
a key: a value
'
),
(
'
a key
'
,
'
a value
'
))
# It is also possible to expect exceptions like in the doctests, but the syntax is a little different.
def
test_parse_single
(
self
):
self
.
assertRaises
(
ValueError
,
examples
.
parse
,
'
invalid
'
)
def
test_parse_triple
(
self
):
self
.
assertRaises
(
ValueError
,
examples
.
parse
,
'
first: second: third
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment