Ejemplo n.º 1
0
def options(self):
    fixture = Fixture()
    run(fixture.f,
        "-mand=em -defnone=dee -noarg -multi m1 "
        "-mand-opt=emo -multi=m2 -optzero ozed -multi-opt mo1 -noarg-opt".
    split())
    self.assertEqual(dict(fixture.defaults,
        mand="em", defnone="dee", noarg=True, multi=["m1", "m2"],
        mand_opt="emo", optzero="ozed", multi_opt=["mo1"], noarg_opt=True,
    ), fixture.values)
Ejemplo n.º 2
0
def frozen(self):
    """Input parameters should not be modified"""
    def f(a, b):
        pass

    f.param_types = dict(a=int)

    args = "7 42".split()
    param_types = dict(b=int)
    run(f, args, param_types=param_types)
    self.assertEqual("7 42".split(), args)
    self.assertEqual(dict(b=int), param_types)
Ejemplo n.º 3
0
def frozen(self):
    """Input parameters should not be modified"""
    
    def f(a, b):
        pass
    f.param_types = dict(a=int)
    
    args = "7 42".split()
    param_types = dict(b=int)
    run(f, args, param_types=param_types)
    self.assertEqual("7 42".split(), args)
    self.assertEqual(dict(b=int), param_types)
Ejemplo n.º 4
0
def types(self):
    """Test argument types"""
    fixture = Fixture()
    fixture.f.param_types = dict(
        var=float, mand_opt=set, optzero=int, multi_opt=float)
    run(fixture.f,
        "-mand-opt=hallo -optzero -12 -multi-opt=inf -multi-opt=01.0e+01 "
        "mand x x x -- 0 -1 +.625e-1".
    split())
    
    self.assertEqual("mand", fixture.values["mand"])
    self.assertEqual((0, -1, 0.0625), fixture.values["var"])
    self.assertEqual(set("halo"), fixture.values["mand_opt"])
    self.assertEqual(-12, fixture.values["optzero"])
    self.assertEqual([float("inf"), 10], fixture.values["multi_opt"])
Ejemplo n.º 5
0
def types(self):
    """Test argument types"""
    fixture = Fixture()
    fixture.f.param_types = dict(var=float,
                                 mand_opt=set,
                                 optzero=int,
                                 multi_opt=float)
    run(
        fixture.f,
        "-mand-opt=hallo -optzero -12 -multi-opt=inf -multi-opt=01.0e+01 "
        "mand x x x -- 0 -1 +.625e-1".split())

    self.assertEqual("mand", fixture.values["mand"])
    self.assertEqual((0, -1, 0.0625), fixture.values["var"])
    self.assertEqual(set("halo"), fixture.values["mand_opt"])
    self.assertEqual(-12, fixture.values["optzero"])
    self.assertEqual([float("inf"), 10], fixture.values["multi_opt"])
Ejemplo n.º 6
0
def options(self):
    fixture = Fixture()
    run(
        fixture.f, "-mand=em -defnone=dee -noarg -multi m1 "
        "-mand-opt=emo -multi=m2 -optzero ozed -multi-opt mo1 -noarg-opt".
        split())
    self.assertEqual(
        dict(
            fixture.defaults,
            mand="em",
            defnone="dee",
            noarg=True,
            multi=["m1", "m2"],
            mand_opt="emo",
            optzero="ozed",
            multi_opt=["mo1"],
            noarg_opt=True,
        ), fixture.values)
Ejemplo n.º 7
0
def positional(self):
    """Test function is called correctly"""
    fixture = Fixture()
    run(fixture.f, "em -mand-opt emo".split())
    self.assertEqual(dict(fixture.defaults, mand="em", mand_opt="emo"),
                     fixture.values)
Ejemplo n.º 8
0
def type_names(self):
    """Parameter name checking for "param_types" attribute"""
    fixture = Fixture()
    fixture.f.param_types = dict({"*": int}, optzero=int, invalid=int)
    with self.assertRaises(TypeError):
        run(fixture.f, "x -mand-opt=x".split())
Ejemplo n.º 9
0
        except LookupError:
            print("  Symbol not found:", name)
        else:
            print("  {}".format(format_symbol(sym)))

def format_tag(tag, obj, names):
    names = dict((getattr(obj, name), name) for name in names.split(", "))
    try:
        name = names[tag]
    except LookupError:
        name = ""
    else:
        name = " ({})".format(name)
    return "0x{:X}{}".format(tag, name)

def format_symbol(sym):
    return "{!r}: {}, {}, {}, shndx {}".format(
        sym.name,
        sym.entry["st_info"]["bind"],
        sym.entry["st_info"]["type"],
        sym.entry["st_other"]["visibility"],
        sym.entry["st_shndx"],
    )

def bitmask(bits):
    return ~(~0 << bits)

if __name__ == "__main__":
    from clifunc import run
    run(main)
Ejemplo n.º 10
0
def type_names(self):
    """Parameter name checking for "param_types" attribute"""
    fixture = Fixture()
    fixture.f.param_types = dict({"*": int}, optzero=int, invalid=int)
    with self.assertRaises(TypeError):
        run(fixture.f, "x -mand-opt=x".split())
Ejemplo n.º 11
0
def positional(self):
    """Test function is called correctly"""
    fixture = Fixture()
    run(fixture.f, "em -mand-opt emo".split())
    self.assertEqual(dict(fixture.defaults, mand="em", mand_opt="emo"),
        fixture.values)
Ejemplo n.º 12
0
        # TODO: base on size if no total; empty dict if neither
        control.set_done(header["part"])
        
        while True:
            header = yield from decoder.parse_header()
            if not header:
                return
            if header["size"] != control.total_length:
                raise ValueError(header["size"])
            if header["name"] != self.name:
                raise ValueError(header["name"])
            # TODO: validate header more; use download.piece_length
            if control.is_done(header["part"]):
                continue
            yield from decoder.decode_part(download.file, header)
            control.set_done(header["part"])
    
    def iter_segments(self):
        for element in self.nzb.iterfind(NZB + "segments"):
            for segment in element:
                if segment.tag != NZB + "segment":
                    raise ValueError(segment.tag)
                [id] = segment.itertext()
                yield (segment, id)

timeouts = (socket.timeout, TimeoutError)

if __name__ == "__main__":
    import clifunc
    clifunc.run()
Ejemplo n.º 13
0
        # TODO: base on size if no total; empty dict if neither
        control.set_done(header["part"])
        
        while True:
            header = yield from decoder.parse_header()
            if not header:
                return
            if header["size"] != control.total_length:
                raise ValueError(header["size"])
            if header["name"] != self.name:
                raise ValueError(header["name"])
            # TODO: validate header more; use download.piece_length
            if control.is_done(header["part"]):
                continue
            yield from decoder.decode_part(download.file, header)
            control.set_done(header["part"])
    
    def iter_segments(self):
        for element in self.nzb.iterfind(NZB + "segments"):
            for segment in element:
                if segment.tag != NZB + "segment":
                    raise ValueError(segment.tag)
                [id] = segment.itertext()
                yield (segment, id)

timeouts = (socket.timeout, TimeoutError)

if __name__ == "__main__":
    import clifunc
    clifunc.run()