Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
7d10fa5f
Commit
7d10fa5f
authored
7 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
tests
parent
5bfb454e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
satella/coding/__init__.py
+1
-0
1 addition, 0 deletions
satella/coding/__init__.py
satella/coding/algos.py
+29
-0
29 additions, 0 deletions
satella/coding/algos.py
setup.py
+1
-1
1 addition, 1 deletion
setup.py
tests/test_coding/test_algos.py
+21
-0
21 additions, 0 deletions
tests/test_coding/test_algos.py
with
52 additions
and
1 deletion
satella/coding/__init__.py
+
1
−
0
View file @
7d10fa5f
...
...
@@ -9,3 +9,4 @@ from .typecheck import typed, List, Tuple, Dict, NewType, Callable, Sequence, \
from
.structures
import
TimeBasedHeap
,
CallableGroup
from
.monitor
import
Monitor
,
RMonitor
from
.algos
import
merge_dicts
This diff is collapsed.
Click to expand it.
satella/coding/algos.py
0 → 100644
+
29
−
0
View file @
7d10fa5f
# coding=UTF-8
from
__future__
import
print_function
,
absolute_import
,
division
import
six
import
logging
import
types
import
copy
import
itertools
from
.typecheck
import
typed
def
_merge
(
v1
,
v2
):
if
isinstance
(
v1
,
list
)
and
isinstance
(
v2
,
list
):
return
v1
+
v2
elif
isinstance
(
v1
,
dict
)
and
isinstance
(
v2
,
dict
):
v1
.
update
(
v2
)
return
v1
else
:
raise
TypeError
@typed
(
dict
,
dict
,
returns
=
dict
)
def
merge_dicts
(
first
,
second
):
for
key
in
second
.
keys
():
try
:
first
[
key
]
=
_merge
(
first
[
key
],
second
[
key
])
except
(
TypeError
,
KeyError
):
# overwrite, not a list or dict, or no key in first
first
[
key
]
=
second
[
key
]
return
first
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
7d10fa5f
...
...
@@ -2,7 +2,7 @@
from
setuptools
import
setup
,
find_packages
setup
(
name
=
'
satella
'
,
version
=
'
2.0.
8
'
,
version
=
'
2.0.
9
'
,
description
=
u
'
Utilities for writing servers in Python
'
,
author
=
u
'
Piotr Maślanka
'
,
author_email
=
'
piotrm@smok.co
'
,
...
...
This diff is collapsed.
Click to expand it.
tests/test_coding/test_algos.py
0 → 100644
+
21
−
0
View file @
7d10fa5f
# coding=UTF-8
from
__future__
import
print_function
,
absolute_import
,
division
import
six
import
unittest
from
satella.coding
import
merge_dicts
class
TestMergeDicts
(
unittest
.
TestCase
):
def
test_merge_dicts
(
self
):
tak
=
merge_dicts
({
'
kupujemy
'
:
'
tak
'
},
{
'
kupujemy
'
:
'
nie
'
})
nie
=
merge_dicts
({
'
kupujemy
'
:
'
nie
'
},
{
'
kupujemy
'
:
'
tak
'
})
self
.
assertEquals
(
tak
[
'
kupujemy
'
],
'
nie
'
)
self
.
assertEquals
(
nie
[
'
kupujemy
'
],
'
tak
'
)
def
test_merge_lists
(
self
):
tak
=
merge_dicts
({
'
kupujemy
'
:
[
'
tak
'
]},
{
'
kupujemy
'
:
[
'
nie
'
]})
self
.
assertEqual
(
set
(
tak
),
set
([
'
tak
'
,
'
nie
'
]))
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