Beispiel #1
0
 def test_delattr(self):
     c = Container(a=1)
     del c.a
     self.assertFalse("a" in c)
     self.assertRaises(AttributeError, lambda: c.a)
     self.assertRaises(KeyError, lambda: c["a"])
     self.assertEqual(c, Container())
Beispiel #2
0
 def test_multiple_dict_args(self):
     print(
         "NOTE: dicts do not preserve order while eq does check it (by default)."
     )
     c = Container({'a': 1, 'b': 42}, {'b': 2})
     d = Container(a=1, b=2)
     # self.assertEqual(c, d)
     self.assertTrue(c.__eq__(d, skiporder=True))
Beispiel #3
0
 def test_dict_and_kw_args(self):
     print(
         "NOTE: dicts do not preserve order while eq does check it (by default)."
     )
     c = Container({'b': 42, 'c': 43}, {'a': 1, 'b': 2, 'c': 4}, c=3, d=4)
     d = Container(a=1, b=2, c=3, d=4)
     # self.assertEqual(c, d)
     self.assertTrue(c.__eq__(d, skiporder=True))
Beispiel #4
0
 def test_dict_arg(self):
     print(
         "NOTE: dicts do not preserve order while eq does check it (by default)."
     )
     print("However, only one entry is in order.")
     c = Container({'a': 1})
     d = Container(a=1)
     self.assertEqual(c, d)
     self.assertTrue(c.__eq__(d, skiporder=True))
Beispiel #5
0
 def test_update_from_list(self):
     c = Container(a=1)(b=2)(c=3)(d=4)
     d = Container()
     d.update([("a", 1), ("b", 2), ("c", 3), ("d", 4)])
     self.assertEqual(d.a, 1)
     self.assertEqual(d.b, 2)
     self.assertEqual(d.c, 3)
     self.assertEqual(d.d, 4)
     self.assertEqual(c, d)
     self.assertEqual(c.items(), d.items())
Beispiel #6
0
 def test_update_from_dict(self):
     c = Container(a=1)(b=2)(c=3)(d=4)
     d = Container()
     d.update(c)
     self.assertEqual(d.a, 1)
     self.assertEqual(d.b, 2)
     self.assertEqual(d.c, 3)
     self.assertEqual(d.d, 4)
     self.assertEqual(c, d)
     self.assertEqual(c.items(), d.items())
Beispiel #7
0
def main():
    s = socket()
    s.connect(('192.168.1.97', 9761))
    output = Container(
                      source=64,
                      dest=1,
                      sequence=33,
                      command=0x10,
                      payload_10 = None)


    while True:
        print "-"*60
        print fecha()
        print "-"*60
        paquete = MaraFrame.build(output)
        #print paquete, type(paquete)
        s.send(str(paquete))
        data = s.recv(1024)
        try:
            data = MaraFrame.parse(data)
        except FieldError as e:
            print "Error al decodificar la trama", e
            continue
        MaraFrame.pretty_print(data,
                               show_header=False,
                               show_bcc=False)
        sleep(.8)
        output.sequence += 1
        if output.sequence > MAX_SEQ:
            output.sequence = MIN_SEQ
Beispiel #8
0
    def test_copy_module(self):
        from copy import copy

        c = Container(a=1)
        d = copy(c)
        self.assertEqual(c, d)
        self.assertTrue(c is not d)
Beispiel #9
0
 def test_setattr(self):
     c = Container()
     c.a = 1
     self.assertEqual(c.a, 1)
     self.assertEqual(c["a"], 1)
     c["a"] = 2
     self.assertEqual(c.a, 2)
     self.assertEqual(c["a"], 2)
Beispiel #10
0
 def test_order(self):
     c = Container()
     while True:
         words = [("".join(chr(randint(65, 97)) for _ in range(randint(3,7))), i) for i in range(20)]
         if words != list(dict(words).keys()):
             break
     c.update(words)
     self.assertEqual([k for k, _ in words], list(c.keys()))
Beispiel #11
0
 def dispatch_packet(self, operation, data, this_length=0):
     afcpack = Container(magic=AFCMAGIC,
                         entire_length=40 + len(data),
                         this_length=40 + len(data),
                         packet_num=self.packet_num,
                         operation=operation)
     if this_length:
         afcpack.this_length = this_length
     header = AFCPacket.build(afcpack)
     self.packet_num += 1
     self.service.send(header + data)
Beispiel #12
0
 def test_ne_wrong_order(self):
     print(
         "WARNING: dict randomizes key order so this test may fail unexpectedly if the order is correct by chance."
     )
     c = Container(a=1,
                   b=2,
                   c=3,
                   d=4,
                   e=5,
                   f=6,
                   g=7,
                   h=8,
                   i=9,
                   j=10,
                   k=11,
                   l=12,
                   m=13,
                   n=14)
     d = Container(shuffled(c.items()))
     self.assertNotEqual(c, d)
Beispiel #13
0
 def test_order_randomized(self):
     print("WARNING: this test is randomized and may not be reproducible")
     c = Container()
     while True:
         words = [
             ("".join(chr(randint(65, 97))
                      for _ in range(randint(3, 7))), i) for i in range(20)
         ]
         if words != list(dict(words).keys()):
             break
     c.update(words)
     self.assertEqual([k for k, _ in words], list(c.keys()))
Beispiel #14
0
    def dispatch_packet(self, operation, data, this_length=0):
        """
        Dispatches an AFC packet over a client.

        Args:
            `operation`: The operation to do. See the source code for the list of constants.
            `data`: The data to send with header.
            `this_length` (optional): Not sure but, according to C libimobiledevice, it looks
                like size of packet + data length.
        """
        afcpack = Container(magic=AFCMAGIC,
                            entire_length=40 + len(data),
                            this_length=40 + len(data),
                            packet_num=self.packet_num,
                            operation=operation)
        if this_length:
            afcpack.this_length = this_length
        header = AFCPacket.build(afcpack)
        self.packet_num += 1
        self.service.send(header + data)
Beispiel #15
0
 def test_str_nested(self):
     c = Container(a=1)(b=2)(c=Container())
     self.assertEqual(
         str(c), "Container: \n    a = 1\n    b = 2\n    c = Container: ")
Beispiel #16
0
 def test_getattr_missing(self):
     c = Container(a=1)
     self.assertRaises(AttributeError, lambda: c.unknownkey)
     self.assertRaises(KeyError, lambda: c["unknownkey"])
Beispiel #17
0
 def test_getattr(self):
     c = Container(a=1)
     self.assertEqual(c["a"], 1)
     self.assertEqual(c.a, 1)
Beispiel #18
0
 def test_str_recursive(self):
     c = Container(a=1)(b=2)
     c.c = c
     self.assertEqual(
         str(c),
         "Container: \n    a = 1\n    b = 2\n    c = <recursion detected>")
Beispiel #19
0
 def test_not_in(self):
     c = Container()
     self.assertTrue("a" not in c)
Beispiel #20
0
 def test_bool_true(self):
     c = Container(a=1)
     self.assertTrue(c)
Beispiel #21
0
 def test_repr_nested(self):
     c = Container(a=1)(b=2)(c=Container())
     self.assertEqual(repr(c), "Container(a=1)(b=2)(c=Container())")
     self.assertEqual(eval(repr(c)), c)
Beispiel #22
0
 def test_ctor_from_dict(self):
     c = Container(a=1)(b=2)(c=3)(d=4)
     d = Container(c)
     self.assertEqual(c, d)
Beispiel #23
0
 def test_repr_empty(self):
     c = Container()
     self.assertEqual(repr(c), "Container()")
     self.assertEqual(eval(repr(c)), c)
Beispiel #24
0
 def test_repr(self):
     c = Container(a=1)(b=2)(c=3)
     self.assertEqual(repr(c), "Container(a=1)(b=2)(c=3)")
Beispiel #25
0
 def test_repr_recursive(self):
     c = Container(a=1)(b=2)
     c.c = c
     self.assertEqual(repr(c),
                      "Container(a=1)(b=2)(c=<recursion detected>)")
Beispiel #26
0
 def test_in(self):
     c = Container(a=1)
     self.assertTrue("a" in c)
Beispiel #27
0
 def test_iters(self):
     c = Container(a=1)(b=2)(c=3)(d=4)
     self.assertEqual(list(c.iterkeys()), ["a", "b", "c", "d"])
     self.assertEqual(list(c.itervalues()), [1, 2, 3, 4])
     self.assertEqual(list(c.iteritems()), [("a", 1), ("b", 2), ("c", 3),
                                            ("d", 4)])
Beispiel #28
0
 def test_str(self):
     c = Container(a=1)(b=2)(c=3)
     self.assertEqual(str(c),
                      "Container: \n    a = 1\n    b = 2\n    c = 3")
Beispiel #29
0
 def test_eq(self):
     c = Container(a=1)(b=2)(c=3)(d=4)(e=5)
     d = Container(a=1)(b=2)(c=3)(d=4)(e=5)
     self.assertEqual(c, d)
Beispiel #30
0
 def test_str_empty(self):
     c = Container()
     self.assertEqual(str(c), "Container: ")