Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
controlhost
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
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
km3py
controlhost
Commits
d70c391b
Commit
d70c391b
authored
Dec 18, 2014
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Tag implementation
parent
d8d8dc7f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
controlhost/__init__.py
+29
-5
29 additions, 5 deletions
controlhost/__init__.py
controlhost/tests/test_controlhost.py
+27
-3
27 additions, 3 deletions
controlhost/tests/test_controlhost.py
with
56 additions
and
8 deletions
controlhost/__init__.py
+
29
−
5
View file @
d70c391b
...
...
@@ -20,11 +20,35 @@ __status__ = "Development"
class
Tag
(
object
):
def
__init__
(
self
):
pass
SIZE
=
8
def
__init__
(
self
,
data
=
None
):
self
.
_data
=
b
''
self
.
data
=
data
@property
def
data
(
self
):
return
self
.
_data
@data.setter
def
data
(
self
,
value
):
if
not
value
:
value
=
b
''
if
len
(
value
)
>
self
.
SIZE
:
raise
ValueError
(
"
The maximum tag size is {0}
"
.
format
(
self
.
SIZE
))
self
.
_data
=
value
while
len
(
self
.
_data
)
<
self
.
SIZE
:
self
.
_data
+=
b
'
\x00
'
def
__str__
(
self
):
return
str
(
self
.
data
).
strip
(
'
\x00
'
)
def
__len__
(
self
):
return
len
(
self
.
_data
)
class
Message
(
object
):
pass
class
Prefix
(
object
):
pass
class
Message
(
object
):
pass
This diff is collapsed.
Click to expand it.
controlhost/tests/test_controlhost.py
+
27
−
3
View file @
d70c391b
...
...
@@ -14,12 +14,36 @@ class TestTag(unittest.TestCase):
def
test_init
(
self
):
tag
=
Tag
()
def
test_empty_tag_has_correct_length
(
self
):
tag
=
Tag
()
self
.
assertEqual
(
Tag
.
SIZE
,
len
(
tag
))
def
test_tag_has_correct_length
(
self
):
for
tag_name
in
(
'
foo
'
,
'
bar
'
,
'
baz
'
,
'
1
'
):
tag
=
Tag
(
tag_name
)
self
.
assertEqual
(
Tag
.
SIZE
,
len
(
tag
))
def
test_tag_with_invalid_length_raises_valueerror
(
self
):
with
self
.
assertRaises
(
ValueError
):
tag
=
Tag
(
'
123456789
'
)
def
test_tag_has_correct_data
(
self
):
tag
=
Tag
(
'
foo
'
)
self
.
assertEqual
(
'
foo
\x00\x00\x00\x00\x00
'
,
tag
.
data
)
tag
=
Tag
(
'
abcdefgh
'
)
self
.
assertEqual
(
'
abcdefgh
'
,
tag
.
data
)
def
test_tag_has_correct_string_representation
(
self
):
tag
=
Tag
(
'
foo
'
)
self
.
assertEqual
(
'
foo
'
,
str
(
tag
))
class
TestMessage
(
unittest
.
TestCase
):
def
test_init
(
self
):
message
=
Message
()
class
TestPrefix
(
unittest
.
TestCase
):
def
test_init
(
self
):
prefix
=
Prefix
()
class
TestMessage
(
unittest
.
TestCase
):
def
test_init
(
self
):
message
=
Message
()
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
sign in
to comment