make_test()   B
last analyzed

Complexity

Conditions 4

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
dl 0
loc 25
rs 8.5806
1
# coding: utf8
2
3
# Copyright 2013-2015 Vincent Jacques <[email protected]>
4
5
import itertools
6
import re
7
8
from .knot import Knot
9
10
11
def remove_kwargs(s):
12
    return re.sub("[a-z]*=", "", s)
13
14
15
def make_test(p, q):
16
    knot = Knot(p, q)
17
    yield "    def test_{}_{}(self):".format(p, q)
18
    yield "        knot = Knot({}, {})".format(p, q)
19
    yield "        self.assertEqual("
20
    yield "            knot.strings,"
21
    yield "            ["
22
    for string in knot.strings:
23
        yield "                String("
24
        yield "                    {},".format(string.k)
25
        yield "                    ["
26
        for segment in string.segments:
27
            yield remove_kwargs("                        {},".format(segment))
28
        yield "                    ],"
29
        yield "                    ["
30
        for bridge in string.bridges:
31
            yield "                        Bridge("
32
            yield remove_kwargs("                            {},".format(bridge.before))
33
            yield remove_kwargs("                            {},".format(bridge.after))
34
            yield remove_kwargs("                            {},".format(bridge.tunnel))
35
            yield "                        ),"
36
        yield "                    ],"
37
        yield "                ),"
38
    yield "            ]"
39
    yield "        )"
40
41
42
print """# coding: utf8
43
44
# Copyright 2013-2015 Vincent Jacques <[email protected]>
45
46
import unittest
47
48
from .knot import Knot, String, Segment, End, Bridge, Tunnel
49
50
51
class KnotTestCase(unittest.TestCase):"""
52
53
tests = []
54
for p, q in sorted(itertools.product(range(1, 13), repeat=2), key=lambda (p, q): (p + q, p)):
55
    tests.append("\n".join(make_test(p, q)))
56
print "\n\n".join(tests)
57