Exemple #1
0
    def test_supply(self):
        wire = fastwire.Wire()

        class A(fastwire.Wired):
            @fastwire.supply(wire)
            def connected(self, a):
                self._a = a

        a = A()
        self.assertFalse(wire._emit == wire.emit)
Exemple #2
0
    def test_method_emit(self):
        wire = fastwire.Wire()

        class A():
            def connected(self, a):
                self._a = a
                return a

        a = A()
        wire.connect(a.connected)
        wire.emit(5)
        self.assertEqual(a._a, 5)
Exemple #3
0
    def test_fn_receive_emit(self):
        wire = fastwire.Wire()

        test = [0]

        @fastwire.fn_receive(wire)
        def connected(a):
            test[0] = a

        val = 5.7
        wire.emit(a=val)
        self.assertEqual(test[0], val)
Exemple #4
0
    def test_receive_emit(self):
        wire = fastwire.Wire()

        class A(fastwire.Wired):
            @fastwire.receive(wire)
            def connected(self, a):
                self._a = a

        a = A()
        val = 5.7
        wire.emit(a=val)
        self.assertEqual(a._a, val)
Exemple #5
0
    def test_wire_emit_performance(self):
        wire = fastwire.Wire()

        def connected(a):
            pass

        def f(a):
            pass

        wire.connect(connected)
        e = wire.emit
        n = 100000
        t_ref = timeit('f(5)', globals={'f': f}, number=n)
        t_test = timeit('e(a=5)', globals={'e': e}, number=n)
        self.assertTrue(t_test / t_ref < 1.5)
Exemple #6
0
 def test_default(self):
     wire = fastwire.Wire(name='test_name')
     wire.set_default(57)
     self.assertEqual(wire.fetch(), 57)
Exemple #7
0
 def test_attrs_kwarg(self):
     dct = {'a': 5}
     wire = fastwire.Wire(name='test_name', attrs=dct)
     self.assertEqual(wire.attrs, dct)
Exemple #8
0
 def test_doc_kwarg(self):
     wire = fastwire.Wire(name='test_name', doc='test_doc')
     self.assertEqual(wire.doc, 'test_doc')
Exemple #9
0
 def test_doc_arg(self):
     wire = fastwire.Wire('test_name', 'test_doc')
     self.assertEqual(wire.doc, 'test_doc')
Exemple #10
0
 def test_name_kwarg(self):
     wire = fastwire.Wire(name='test_name')
     self.assertEqual(wire.name, 'test_name')