Exemplo n.º 1
0
    def testComputedSet(self):
        s1 = trellis.Set([1, 4, 5])
        s2 = trellis.Set([1, 5, 6, 10])

        union = ComputedUnion(map(set_wrapper, (s1, s2)))

        self.failUnlessEqual(set(union), set([1, 4, 5, 6, 10]))
Exemplo n.º 2
0
    def testChangeSources(self):
        s1 = trellis.Set([0, 2, 4])
        s2 = trellis.Set([4, 6])
        s3 = trellis.Set([2])

        union = ComputedUnion([set_wrapper(s1)])
        with self.record_changes(union) as record:
            union.input.add(set_wrapper(s2))

        self.failUnlessEqual(set(union), set([0, 2, 4, 6]))
        self.failUnlessRecordMatches(
            record,
            (set([0, 2, 4, 6]), set([6]), set()),
            (set([0, 2, 4, 6]), set(), set()),
        )

        with self.record_changes(union) as record:
            union.input.add(set_wrapper(s3))

        self.failUnlessEqual(set(union), set([0, 2, 4, 6]))
        self.failUnlessRecordMatches(
            record,
            (set([0, 2, 4, 6]), set(), set()),
        )

        with self.record_changes(union) as record:
            union.input = trellis.Set([set_wrapper(s2)])

        self.failUnlessRecordMatches(
            record,
            (set([4, 6]), set(), set([0, 2])),
            (set([4, 6]), set(), set()),
        )
Exemplo n.º 3
0
    def testAddNoop(self):
        s1 = trellis.Set([1, 4, 5])
        s2 = trellis.Set([1, 5, 6, 10])

        union = ComputedUnion(map(set_wrapper, (s1, s2)))

        with self.record_changes(union) as record:
            s1.add(10)

        self.failUnlessRecordMatches(
            record,
            (set([1, 4, 5, 6, 10]), set(), set()),
        )
Exemplo n.º 4
0
    def testRemoveOne(self):
        s1 = trellis.Set([1, 4, 5])
        s2 = trellis.Set([1, 5, 6, 10])

        union = ComputedUnion(map(set_wrapper, (s1, s2)))

        with self.record_changes(union) as record:
            s2.remove(6)

        self.failUnlessRecordMatches(
            record,
            (set([1, 4, 5, 10]), set(), set([6])),
            (set([1, 4, 5, 10]), set(), set()),
        )
Exemplo n.º 5
0
    def testAddAndRemove(self):
        s1 = trellis.Set([101, 103])
        s2 = trellis.Set([102])
        union = ComputedUnion(map(set_wrapper, (s1, s2)))

        def addAndRemove():
            s1.add(102)
            s2.remove(102)

        with self.record_changes(union) as record:
            trellis.modifier(addAndRemove)()

        self.failUnlessRecordMatches(
            record,
            (set([101, 102, 103]), set(), set()),
        )
Exemplo n.º 6
0
    def testRemoveNoop(self):
        s1 = trellis.Set([1, 4, 5])
        s2 = trellis.Set([1, 5, 6, 10])

        union = ComputedUnion(map(set_wrapper, (s1, s2)))

        with self.record_changes(union) as record:
            s2.remove(5)

        # make sure there are no changes posted if we add
        # an element to one of our items that's already
        # in another source
        self.failUnlessRecordMatches(
            record,
            (set([1, 4, 5, 6, 10]), set(), set()),
        )
Exemplo n.º 7
0
    def testLength(self):
        s1 = trellis.Set([0, 2, 4])
        s2 = trellis.Set([4, 6])
        s3 = trellis.Set([2])

        union = ComputedUnion([set_wrapper(s1)])
        self.failUnlessEqual(len(union), 3)

        union.input.add(set_wrapper(s2))
        self.failUnlessEqual(len(union), 4)

        union.input.add(set_wrapper(s3))
        self.failUnlessEqual(len(union), 4)

        union.input.clear()
        self.failUnlessEqual(len(union), 0)
Exemplo n.º 8
0
    def testStrSort(self):
        data = trellis.Set([1, 3, 4])
        sorted_set = collections.SortedSet(data=data, sort_key=str)

        self.failUnlessEqual(list(sorted_set), [1, 3, 4])
        data.add(2)
        self.failUnlessEqual(list(sorted_set), [1, 2, 3, 4])
Exemplo n.º 9
0
    def testRemoveTwice(self):
        s1 = trellis.Set([101, 103])
        s2 = trellis.Set([101])
        union = ComputedUnion(map(set_wrapper, (s1, s2)))

        def removeTwice():
            s1.remove(101)
            s2.remove(101)

        with self.record_changes(union) as record:
            trellis.modifier(removeTwice)()

        self.failUnlessRecordMatches(
            record,
            (set([103]), set(), set([101])),
            (set([103]), set(), set()),
        )
Exemplo n.º 10
0
    def testUnicodeSort(self):
        data = trellis.Set([1, 2])
        sorted_set = collections.SortedSet(data=data,
                                           sort_key=unicode,
                                           reverse=True)

        self.failUnlessEqual(list(sorted_set), [2, 1])
        data.add(0)
        self.failUnlessEqual(list(sorted_set), [2, 1, 0])
Exemplo n.º 11
0
    def testChangePredicate(self):
        input = trellis.Set(Component(value=i) for i in xrange(10))
        subset = core.FilteredSubset(input=input,
                                     predicate=lambda comp: comp.value > 6)

        self.failUnlessEqual(sorted(x.value for x in subset), [7, 8, 9])

        subset.predicate = lambda comp: comp.value % 2
        self.failUnlessEqual(sorted(x.value for x in subset), [1, 3, 5, 7, 9])
Exemplo n.º 12
0
def load_domain():
    """Load up the domain model for ChandlerApplication"""
    if not isfile(EIM_PERSISTENCE_FILE):
        ChandlerApplication.sidebar_entries = trellis.Set(
                sidebar.SidebarEntry(collection=keyword.Keyword(name))
                for name in (u"Home", u"Work")
            )
    else:
        from chandler.sharing import dumpreload
        dumpreload.reload(EIM_PERSISTENCE_FILE, gzip=True)
Exemplo n.º 13
0
 def testPartialRollbackSet(self):
     c1 = trellis.Cell(lambda: None)
     s = trellis.Set()
     s.add(1)
     self.assertEqual(list(s.added), [1])
     sp = self.ctrl.savepoint()
     self.ctrl.change_attr(self.ctrl, 'current_listener', c1)
     s.add(2)
     self.assertEqual(list(s.added), [1, 2])
     self.ctrl.rollback_to(sp)
     self.assertEqual(list(s.added), [1])
Exemplo n.º 14
0
    def testOnce(self):

        input = trellis.Set(Component(value=i) for i in xrange(10))
        subset = core.FilteredSubset(input=input,
                                     predicate=lambda comp: comp.value > 6)

        self.failUnlessEqual(sorted(x.value for x in subset), [7, 8, 9])

        special = Component(value=-3)
        input.add(special)

        self.failIf(special in subset)
        self.failUnlessEqual(sorted(x.value for x in subset), [7, 8, 9])

        special.value = 31
        self.failUnless(special in subset)
        self.failUnlessEqual(sorted(x.value for x in subset), [7, 8, 9, 31])
Exemplo n.º 15
0
 def setUp(self):
     super(MFSFuturesTestCase, self).setUp()
     input = trellis.Set(Component(value=i) for i in xrange(10))
     self.subset = core.FilteredSubset(
         input=input, predicate=lambda comp: comp.value > 6)
Exemplo n.º 16
0
 def testRemoveLast(self):
     data = trellis.Set([1, 2])
     sorted_set = collections.SortedSet(data=data)
     data.remove(2)
     self.failUnlessEqual(list(sorted_set), [1])
Exemplo n.º 17
0
 def testAddToEnd(self):
     data = trellis.Set([1])
     sorted_set = collections.SortedSet(data=data)
     data.add(2)
     self.failUnlessEqual(list(sorted_set), [1, 2])