Beispiel #1
0
def quantize(begin, end, subdiv, breakouts):
    lapse = Lapse(begin, timedelta(hours=1) / subdiv)
    results = []
    iterator = iter(breakouts)
    repeat = 0
    try:
        breakout = next(iterator)
        while lapse.precedes(end):
            if lapse.precedes(breakout.start_at):
                repeat = 0
                results.append((lapse.start_at, Nothing(), repeat))
            elif breakout.lapse.contains(lapse):
                results.append((lapse.start_at, maybe(breakout), repeat))
                repeat += 1
            else:
                repeat = 0
                breakout = next(iterator)
                continue
            lapse.increment()
    except StopIteration:
        while lapse.precedes(end):
            results.append((lapse.start_at, Nothing(), repeat))
            lapse.increment()
    finally:
        return results
Beispiel #2
0
    def test_comparisons(self):
        self.assertReallyEqual(Something(1), 1)
        self.assertReallyEqual(1, Something(1))
        self.assertReallyEqual(Something(1), Something(1))
        self.assertReallyEqual(Nothing(), Nothing())

        self.assertReallyNotEqual(Something(1), Something(2))
        self.assertReallyNotEqual(Something(1), Nothing())
        self.assertReallyNotEqual(Nothing(), Something(1))
Beispiel #3
0
 def test_nothing_cmp(self):
     if PY2:
         self.assertEqual(0, cmp(Nothing(), Nothing()))
         self.assertEqual(1, cmp(1, Nothing()))
         self.assertEqual(1, cmp(Something(5), Nothing()))
         self.assertEqual(1, cmp(5, Nothing()))
         self.assertEqual(-1, cmp(Nothing(), Something(5)))
         self.assertEqual(-1, cmp(Nothing(), 5))
Beispiel #4
0
    def test_something_cmp(self):
        l = [Something(1), 2, Nothing()]
        sortedl = sorted(l)
        self.assertTrue(isinstance(sortedl[0], Nothing))
        self.assertTrue(isinstance(sortedl[1], Something))
        self.assertTrue(isinstance(sortedl[2], int))

        self.assertEqual(sortedl[0], None)
        self.assertEqual(sortedl[1], 1)
        self.assertEqual(sortedl[2], 2)
Beispiel #5
0
    def test_something_cmp(self):
        if PY2:
            n = Nothing()
            s = maybe(5)
            s1 = maybe(7)

            self.assertEqual(1, cmp(s, n))
            self.assertEqual(cmp(5, 5), cmp(s, s))
            self.assertEqual(cmp(5, 7), cmp(s, s1))
            self.assertEqual(cmp(7, 5), cmp(s1, s))
            self.assertEqual(cmp(5, 5), cmp(s, 5))
            self.assertEqual(cmp(5, 7), cmp(s, 7))
            self.assertEqual(cmp(7, 5), cmp(7, s))
Beispiel #6
0
 def test_nothing_neSomething(self):
     self.assertTrue(Nothing() != Something(2))
     self.assertTrue(Something(1) != Nothing())
Beispiel #7
0
 def test_nothing_notEqualToSomething(self):
     self.assertFalse(Nothing() == Something(2))
     self.assertFalse(Something(1) == Nothing())
Beispiel #8
0
 def test_nothing_equalToNothing(self):
     self.assertTrue(Nothing() == Nothing())
Beispiel #9
0
 def test_nothing_getItem_returnsNothing(self):
     n = Nothing()['name']
     self.assertTrue(isinstance(n, Nothing))
     self.assertTrue(n.is_none())
     self.assertFalse(n.is_some())
Beispiel #10
0
 def test_nothing_setItem_doestNothing(self):
     Nothing()['name'] = 'value'  # Will raise if __setitem__ wasnt defined
Beispiel #11
0
 def test_nothing_unicode(self):
     if PY2:
         self.assertEqual(unicode(Nothing()), unicode(None))
Beispiel #12
0
 def test_nothing_ltNone_isFalse(self):
     self.assertFalse(Nothing() < None)
Beispiel #13
0
 def test_nothing_gtAnything_isFalse(self):
     self.assertFalse(Nothing() > Nothing())
     self.assertFalse(Nothing() > Something(123))
     self.assertFalse(Nothing() > None)
     self.assertFalse(Nothing() > "Value")
Beispiel #14
0
 def test_something_cmp_greaterThanNothing(self):
     l = [Something(0), Nothing()]
     sortedl = sorted(l)
     self.assertTrue(isinstance(sortedl[0], Nothing))
     self.assertTrue(isinstance(sortedl[1], Something))
Beispiel #15
0
 def test_nothing_strings_returnNone(self):
     self.assertEqual(str(Nothing()), "Nothing")
Beispiel #16
0
 def test_nothing_getItem_returnsNone(self):
     result = Nothing()[10]
     self.assertIsInstance(result, Nothing)
Beispiel #17
0
 def test_nothing_length_isZero(self):
     self.assertEqual(len(Nothing()), 0)
Beispiel #18
0
 def test_nothing_nonzero_isFalse(self):
     self.assertFalse(bool(Nothing()))
Beispiel #19
0
 def test_nothing_neNothing(self):
     self.assertFalse(Nothing() != Nothing())
Beispiel #20
0
 def test_nothing_getItem_returnsNothing(self):
     n = Nothing()['name']
     self.assertTrue(isinstance(n, Nothing))
     self.assertTrue(n.is_none())
     self.assertFalse(n.is_some())
Beispiel #21
0
 def test_nothing_ltSomething_isTrue(self):
     self.assertTrue(Nothing() < Something(1))
Beispiel #22
0
 def test_nothing_geNotNoneOrNothing_isFalse(self):
     self.assertFalse(Nothing() >= Something(2))
     self.assertFalse(Nothing() >= "some")
Beispiel #23
0
 def test_nothing_ltNotNone_isFalse(self):
     self.assertTrue(Nothing() < "some")
Beispiel #24
0
 def test_nothing_delItem_doestNothing(self):
     del Nothing()['name']  # Will raise if __delitem__ wasnt defined
Beispiel #25
0
 def test_nothing_leAnything_isTrue(self):
     self.assertTrue(Nothing() <= Nothing())
     self.assertTrue(Nothing() <= Something(123))
     self.assertTrue(Nothing() <= None)
     self.assertTrue(Nothing() <= "Value")
Beispiel #26
0
 def test_something_leNothing_isFalse(self):
     self.assertFalse(Something("value") <= Nothing())
Beispiel #27
0
 def test_something_geNothing_isTrue(self):
     self.assertTrue(Something("value") >= Nothing())
Beispiel #28
0
 def test_nothing_geNone_isTrue(self):
     self.assertTrue(Nothing() >= None)