Passed
Push — master ( 6f77b1...954ddf )
by Oleksandr
11:42
created

tests.test_lazy   A

Complexity

Total Complexity 37

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 37
eloc 68
dl 0
loc 91
rs 9.44
c 0
b 0
f 0
1
import unittest
2
3
from verboselib.lazy import LazyString
4
5
6
class LazyStringTestCase(unittest.TestCase):
7
8
  def test_str(self):
9
    testee = LazyString(lambda: "foo")
10
    self.assertEqual(str(testee), "foo")
11
12
  def test_args_kwargs(self):
13
    testee = LazyString(
14
      lambda a, b: "{} =? {} : {}".format(a, b, a == b),
15
      10,
16
      b=20
17
    )
18
    self.assertEqual(testee, "10 =? 20 : False")
19
20
  def test_format(self):
21
    testee = LazyString(lambda: "name: {name}")
22
    self.assertEqual(testee.format(name="foo"), "name: foo")
23
24
  def test_invalid_attribute(self):
25
    testee = LazyString(lambda: "foo")
26
27
    with self.assertRaises(AttributeError):
28
      testee.foo()
29
30
  def test_len(self):
31
    testee = LazyString(lambda: "foo")
32
    self.assertEqual(len(testee), 3)
33
34
  def test_indexing(self):
35
    testee = LazyString(lambda: "foo")
36
    self.assertEqual(testee[0], "f")
37
38
  def test_iter(self):
39
    testee = LazyString(lambda: "foo")
40
    self.assertEqual(list(iter(testee)), ["f", "o", "o"])
41
42
  def test_contains(self):
43
    testee = LazyString(lambda: "foo")
44
    self.assertIn("f", testee)
45
46
  def test_add(self):
47
    testee = LazyString(lambda: "foo")
48
    self.assertEqual(testee + "bar", "foobar")
49
50
  def test_radd(self):
51
    testee = LazyString(lambda: "foo")
52
    self.assertEqual("bar" + testee, "barfoo")
53
54
  def test_mul(self):
55
    testee = LazyString(lambda: "foo")
56
    self.assertEqual(testee * 3, "foofoofoo")
57
58
  def test_rmul(self):
59
    testee = LazyString(lambda: "foo")
60
    self.assertEqual(3 * testee, "foofoofoo")
61
62
  def test_eq(self):
63
    testee = LazyString(lambda: "foo")
64
    self.assertEqual(testee, "foo")
65
66
  def test_ne(self):
67
    testee = LazyString(lambda: "foo")
68
    self.assertNotEqual(testee, "bar")
69
70
  def test_lt(self):
71
    testee = LazyString(lambda: "foo")
72
    self.assertFalse(testee < "boo")
73
    self.assertTrue( testee < "joo")
74
75
  def test_le(self):
76
    testee = LazyString(lambda: "foo")
77
    self.assertFalse(testee <= "boo")
78
    self.assertTrue( testee <= "foo")
79
    self.assertTrue( testee <= "joo")
80
81
  def test_gt(self):
82
    testee = LazyString(lambda: "foo")
83
    self.assertTrue( testee > "boo")
84
    self.assertFalse(testee > "joo")
85
86
  def test_ge(self):
87
    testee = LazyString(lambda: "foo")
88
    self.assertTrue( testee >= "boo")
89
    self.assertTrue( testee >= "foo")
90
    self.assertFalse(testee >= "joo")
91