Example #1
0
 def get_output_type(self):
     """
     Provides a way for dataproviders to change the datatype they emit. In most cases
     implementing get_out_conversion args is recommended and will let you acomplish what you want.
     @returs: A C{string} in the form "type_name?arg_name=foo&arg_name2=bar"
     """
     args = self.get_output_conversion_args()
     if len(args) == 0:
         return self._out_type_
     else:
         return "%s?%s" % (self._out_type_, Utils.encode_conversion_args(args))
Example #2
0
 def get_output_type(self):
     """
     Provides a way for dataproviders to change the datatype they emit. In most cases
     implementing get_out_conversion args is recommended and will let you acomplish what you want.
     @returs: A C{string} in the form "type_name?arg_name=foo&arg_name2=bar"
     """
     args = self.get_output_conversion_args()
     if len(args) == 0:
         return self._out_type_
     else:
         return "%s?%s" % (self._out_type_, Utils.encode_conversion_args(args))
def convert():    
    for name, test_encodings, all_encodings in TEST:
        files = get_external_resources(name)
        for description,uri in files.items():
            f = File.File(uri)
            exists = f.exists()
            ok("%s: File %s exists" % (name,uri), exists, False)
            if exists:
                for encoding in test_encodings:
                    args = all_encodings[encoding]
                    
                    to_type = "file/%s?%s" % (name,Utils.encode_conversion_args(args))
                    try:
                        newdata = tc.convert("file",to_type, f)
                        success = newdata != None and newdata.exists()
                    except: 
                        success = False

                    ok("%s: Conversion of %s -> %s" % (name,description,encoding), success, False)

    gobject.idle_add(mainloop.quit)
        except Exceptions.ConversionDoesntExistError:
            ok("ConversionDoesntExistError exception caught", True)
        except Exception:
            ok("Conversion exception caught", False)
    else:
        #check the correct conversions are predicted
        conversions = tc._get_conversions(f,t)
        ok("Correct num conversions predicted", len(expected) == len(conversions))
        i = 0
        for cf, ct, a in conversions:
            ef,et = expected[i].split("->")
            ok("Correct conversion: %s -> %s (v. %s -> %s)" % (cf,ct,ef,et), cf == ef and ct == et)
            i += 1
        
        data = fKlass()
        newdata = tc.convert(f,t,data)
        ok("Data converted ok (no args)", True)

        #check conversion args are handled
        args = {"arg1":Utils.random_string(),"arg2":Utils.random_string()}
        conversions = tc._get_conversions(f,"%s?%s" % (t,Utils.encode_conversion_args(args)))
        ok("Conversion args passed to last converter", conversions[-1][-1] == args)            
        newdata = tc.convert(f,"%s?%s"%(t,Utils.encode_conversion_args(args)),data)
        ok("Data converted ok (with args)", data._name_ == fKlass._name_ and newdata._name_ == tKlass._name_)

test.finished()
finished()