Completed
Push — master ( a1e8f3...b95acc )
by Oleksandr
02:23
created

MaxTime   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
dl 0
loc 24
ccs 4
cts 8
cp 0.5
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate_far() 0 10 2
1
# coding: utf-8
2
3 1
from schematics.exceptions import ValidationError
4 1
from schematics.models import Model
5 1
from schematics.types import IntType, FloatType
6 1
from schematics.types.compound import ModelType
7
8
9 1
class MaxTime(Model):
10 1
    near = FloatType(
11
        min_value=0.1,
12
        max_value=30.0,
13
        default=2.0,
14
        required=True,
15
    )
16 1
    far = FloatType(
17
        min_value=0.1,
18
        max_value=30.0,
19
        default=10.0,
20
        required=True,
21
    )
22
23 1
    def validate_far(self, data, value):
24
        near = data['near']
25
26
        if value < near:
27
            raise ValidationError(
28
                "'far' value ({far}) cannot be less than 'near' value ({near})."
29
                .format(far=value, near=near)
30
            )
31
32
        return value
33
34
35 1
class Warnings(Model):
36 1
    delay = FloatType(
37
        min_value=1.0,
38
        max_value=30.0,
39
        default=10.0,
40
        required=True,
41
    )
42 1
    max_number = IntType(
43
        default=3,
44
        required=True,
45
    )
46
47
48 1
class Lags(Model):
49 1
    max_time = ModelType(
50
        model_spec=MaxTime,
51
        required=True,
52
    )
53 1
    warnings = ModelType(
54
        model_spec=Warnings,
55
        required=True,
56
    )
57