Skip to content
Snippets Groups Projects
Commit 3fd9ab0c authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

code cleanup

parent 7a94700c
No related branches found
No related tags found
No related merge requests found
Showing with 57 additions and 76 deletions
......@@ -19,4 +19,4 @@ exclude_paths:
- docs/**
ratings:
paths:
- satella/**
\ No newline at end of file
- satella/**
......@@ -5,7 +5,7 @@ This essentially allows you to have a heap object that will pretty much
behave like the `heapq <https://docs.python.org/2/library/heapq.html>` library.
.. autoclass:: satella.coding.Heap
:members:
:members:
TimeBasedHeap
---------
......@@ -14,4 +14,12 @@ Time-based heap is a good structure if you have many callbacks set to fire at a
time in the future. It functions very like a normal Heap.
.. autoclass:: satella.coding.TimeBasedHeap
:members:
:members:
typednamedtuple
---------------
It's a named tuple, but it has typed fields. You will get a TypeError if you
try to assign something else there.
.. autofunction:: satella.coding.typednamedtuple
......@@ -60,6 +60,7 @@ author = u'Piotr Maślanka'
#
# The short X.Y version.
from satella import __version__
version = '.'.join(__version__.split('.', 2)[:2])
# The full version, including alpha/beta/rc tags.
release = __version__
......
......@@ -2,17 +2,17 @@ Welcome to satella's documentation!
===================================
.. toctree::
:maxdepth: 2
:caption: Contents:
:maxdepth: 2
:caption: Contents:
coding/monitor
coding/debug
coding/typechecking
coding/structures
instrumentation/traceback
instrumentation/metrics
source/modules
posix
coding/monitor
coding/debug
coding/typechecking
coding/structures
instrumentation/traceback
instrumentation/metrics
source/modules
posix
Indices and tables
......
# coding=UTF-8
"""
Simple Echo service
"""
from __future__ import print_function, absolute_import, division
import six
import logging
logger = logging.getLogger(__name__)
# coding=UTF-8
"""
It sounds like a melody
"""
from __future__ import print_function, absolute_import, division
import six
import logging
import socket
logger = logging.getLogger(__name__)
from satella.posix import daemonize
if __name__ == '__main__':
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('0.0.0.0', 7))
daemonize(uid='daemon', gid='daemon')
......@@ -8,24 +8,22 @@ from .algos import merge_dicts
from .concurrent import Monitor, RMonitor, CallableGroup
from .recast_exceptions import rethrow_as, silence_excs
from .structures import TimeBasedHeap, Heap, typednamedtuple, OmniHashableMixin
from .structures import TimeBasedHeap, Heap, typednamedtuple, OmniHashableMixin, Singleton
from .typecheck import typed, Callable, Sequence, \
TypeVar, Mapping, Iterable, Any, Optional, CallSignature, \
Number, coerce, Set, Dict, List, Tuple, checked_coerce, for_argument, \
precondition, PreconditionError
from .structures import TimeBasedHeap, Heap, typednamedtuple, OmniHashableMixin
from .singleton import Singleton
__all__ = [
'typednamedtuple', 'OmniHashableMixin'
'TimeBasedHeap', 'Heap', 'CallableGroup',
'TimeBasedHeap', 'Heap', 'CallableGroup',
'Monitor', 'RMonitor', 'merge_dicts',
'typed', 'NewType', 'Callable', 'Sequence', 'coerce'
'TypeVar','Mapping', 'Iterable', 'Union', 'Any', 'Optional',
'TypeVar', 'Mapping', 'Iterable', 'Union', 'Any',
'Optional',
'CallSignature', 'Number',
'Set', 'Dict', 'List', 'Tuple', 'checked_coerce', 'for_argument',
'precondition', 'PreconditionError',
'rethrow_as', 'silence_excs',
'Singleton'
]
# coding=UTF-8
from __future__ import print_function, absolute_import, division
__all__ = [
'typednamedtuple',
'Heap',
'TimeBasedHeap',
'OmniHashableMixin',
'Singleton'
]
from .singleton import Singleton
from .structures import *
from .typednamedtuple import *
......@@ -67,5 +67,4 @@ else:
"""
return _SingletonWrapper(cls)
Singleton = singleton
# coding=UTF-8
from __future__ import print_function, absolute_import, division
import inspect
from copy import copy
import itertools
from .basics import *
from collections import namedtuple
from copy import copy
from .basics import *
__all__ = [
'_CSArgument',
......
# coding=UTF-8
from __future__ import print_function, absolute_import, division
import typing
import numbers
import typing
__all__ = [
'Callable', 'Sequence', 'Number', 'Mapping', 'Iterable', 'Any',
......@@ -9,7 +10,6 @@ __all__ = [
'_NotGiven', '_NoDefault', '_NOP', '_TRUE'
]
Callable = lambda *args: typing.Callable
Sequence = typing.Sequence
Number = numbers.Real
......@@ -23,6 +23,7 @@ Tuple = lambda *opt: tuple
Dict = lambda *p: dict
Set = lambda *p: set
# Internal tokens - only instances will be
class _NotGiven(object):
pass
......
......@@ -11,9 +11,7 @@ from satella.coding import typed, CallSignature, Number, coerce, Optional, \
class TestTypecheck(unittest.TestCase):
def test_precondition(self):
@precondition('len(x) == 1', lambda x: x == 1, None)
def return_double(x, y, z):
pass
......@@ -21,7 +19,7 @@ class TestTypecheck(unittest.TestCase):
self.assertRaises(PreconditionError, lambda: return_double([], 1, 5))
self.assertRaises(PreconditionError, lambda: return_double([1], 2, 5))
return_double([1], 1, 'dupa')
def test_cls(self):
# if we don't care about apps
class Lol(object):
......@@ -39,7 +37,6 @@ class TestTypecheck(unittest.TestCase):
Lol().lel([], {}, (), set([1]), lambda a: None)
def test_che_co2(self):
@checked_coerce((int, None))
def p(a):
return a
......@@ -65,7 +62,6 @@ class TestTypecheck(unittest.TestCase):
self.assertIsInstance(testa('5'), int)
def test_checked_coerce(self):
@checked_coerce([(str, int), int], returns=(int, float))
def testa(a):
return a
......@@ -144,7 +140,7 @@ class TestTypecheck(unittest.TestCase):
@typed(Optional(int))
def testa(a=5):
pass
self.assertRaises(TypeError, lambda: testa(2.0))
testa(a=2.0)
self.assertRaises(TypeError, lambda: testa('yuyu'))
......@@ -152,7 +148,6 @@ class TestTypecheck(unittest.TestCase):
testa(a=6)
def test_shorter_coerces(self):
@coerce(int, None, str)
def test(a, b, c, d, e):
return a, b, c, d, e
......@@ -174,10 +169,9 @@ class TestTypecheck(unittest.TestCase):
self.assertEqual(Wtf().add('1', '2.5'), 3.5)
def test_coerce_result(self):
@coerce(returns=str)
def add(a, b):
return a+b
return a + b
self.assertEqual(add(1, 2), '3')
......@@ -189,8 +183,6 @@ class TestTypecheck(unittest.TestCase):
Wtf().add(1, 2.5)
def test_T2(self):
@typed((int, None))
def testa(a=5):
......
# coding=UTF-8
from __future__ import print_function, absolute_import, division
import unittest
from satella.coding import Singleton
class TestSingleton(unittest.TestCase):
def test_singleton(self):
@Singleton
class MyClass(object):
def __init__(self):
......@@ -18,4 +19,3 @@ class TestSingleton(unittest.TestCase):
a.a = 6
self.assertEqual(b.a, 6)
# coding=UTF-8
from __future__ import print_function, absolute_import, division
import copy
import unittest
import mock
import six
from satella.coding import TimeBasedHeap, Heap, CallableGroup, typednamedtuple, \
OmniHashableMixin
import six
import copy
import mock
class TestCallableGroup(unittest.TestCase):
......@@ -16,9 +17,7 @@ class TestCallableGroup(unittest.TestCase):
class TestTimeBasedHeap(unittest.TestCase):
def test_omni(self):
class Omni(OmniHashableMixin):
_HASH_FIELDS_TO_USE = ['a']
......
......@@ -27,8 +27,10 @@ class TestPidlock(unittest.TestCase):
class TestDaemon(unittest.TestCase):
@unittest.skipIf('win' in sys.platform, 'Running on Windows')
def test_daemonize(self):
with patch('sys.stdin') as stdin, patch('sys.stdout') as stdout, patch('sys.stderr') as stderr, \
patch('os.fork', return_value=0) as fork, patch('os.umask') as umask, patch('os.setsid') as setsid, \
with patch('sys.stdin') as stdin, patch('sys.stdout') as stdout, patch(
'sys.stderr') as stderr, \
patch('os.fork', return_value=0) as fork, patch('os.umask') as umask, patch(
'os.setsid') as setsid, \
patch('os.chdir') as chdir, patch('sys.exit', new=lambda: 0) as exit:
from satella.posix import daemonize
......
# coding=UTF-8
from __future__ import print_function, absolute_import, division
import os
import unittest
from satella.posix import suicide
class TestSuicide(unittest.TestCase):
def test_suicide(self):
pcid = os.fork()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment