Exemple #1
0
    def testParseNIDMZip(self):
        contrasts = {}
        turtles = {}  # I like turtles.
        uploads = {}
        statmaps = {}

        for name in self.files:
            uploads[name] = NIDMUpload(
                self.files[name]['file'], tmp_dir=self.tmpdir, load=False)
            turtles[name] = uploads[name].parse_metafiles(extract_ttl=True)
            contrasts[name] = uploads[name].parse_contrasts()
            statmaps[name] = uploads[name].get_statmaps()

        """
        assert known bad file throws parsing error
        """
        for key in self.failing_files:
            with self.assertRaises(NIDMUpload.ParseException):
                print NIDMUpload(self.failing_files[key])

        """
        assert output matches expected output
        """
        for name, info in self.files.items():
            first_map = sorted(statmaps[name])[0]
            print first_map
            print info
            print name
            for field in 'name', 'type':
                self.assertEquals(first_map[field], info['output_row'][field])
            self.assertEquals(len(statmaps[name]), info['num_statmaps'])
Exemple #2
0
    def clean(self):
        cleaned_data = super(NIDMResultsForm, self).clean()
        # only process new uploads or replaced zips

        if self.instance.pk is None or 'zip_file' in self.changed_data:

            try:
                self.nidm = NIDMUpload(cleaned_data.get('zip_file'))
            except Exception,e:
                raise ValidationError("The NIDM file was not readable: {0}".format(e))
            try:
                self.clean_nidm()
            except Exception,e:
                raise ValidationError(e)
Exemple #3
0
    def clean_and_validate_zip_file(self, data, zip_file):
        # make sure the zip file has a unique name
        base_subdir = os.path.split(data['zip_file'].name)[-1].replace(
            '.nidm.zip', '')
        nres = NIDMResults.objects.filter(collection=data['collection'],
                                          name__startswith=base_subdir +
                                          ".nidm").count()
        # don't count current instance
        if self.instance.pk is not None and nres != 0:
            nres -= 1
        safe_name = '{0}_{1}.nidm'.format(base_subdir, nres)
        data['name'] = base_subdir + ".nidm" if nres == 0 else safe_name
        data['zip_file'].name = zip_file.name = data['name'] + ".zip"

        try:
            self.nidm = NIDMUpload(zip_file)
        except Exception, e:
            raise ValidationError(
                "The NIDM file was not readable: {0}".format(e))
Exemple #4
0
 def clean_and_validate_zip_file(self, data, zip_file):
     try:
         self.nidm = NIDMUpload(zip_file)
     except Exception, e:
         raise ValidationError(
             "The NIDM file was not readable: {0}".format(e))