Exemplo n.º 1
0
    def process_toc(self, elm, parent_category):
        for c in elm.xpath("xhtml:li", namespaces = NSMAP):
            # Test or Category?
            xpathres = c.xpath("xhtml:a/@href", namespaces = NSMAP)
            test_section = None
            if len(xpathres) != 0:
                href = xpathres[0]
                uri = urlparse(os.path.join(self.dirname, href))
                test_section = self.get_test(uri)
                if test_section != None:
                    xhtml = etree.tostring(test_section).strip() # trim whitespace
                    name = self.get_label(c)
                    desc = self.get_desc(test_section)
                    testid = uri.fragment
                    required = test_section.attrib['class'].find('ctest') != -1
                    foldername = os.path.basename(self.folder)
                    import_testsuite.add_test(name, desc, parent_category, required, testid, self.testsuite, xhtml, foldername)

            if test_section == None:
                # does this container eventually contain a test? otherwise we won't include it.
                if self.test_for_tests(c):
                    desc = self.get_label(c)
                    if self.restriction >= 3:
                        foldername = os.path.basename(self.folder)
                        new_category = import_testsuite.add_category(common.CATEGORY_INTERNAL, \
                            desc, parent_category, self.testsuite, foldername)
                    else:
                        new_category = parent_category
                    # if this element has a nested list
                    # note that test list items don't have nested lists
                    nested_ol = c.xpath("xhtml:ol", namespaces = NSMAP)
                    if len(nested_ol) > 0:
                        self.process_toc(nested_ol[0], new_category)
Exemplo n.º 2
0
def add_testsuite(sourcedir, config_file):
    norm_sourcedir = os.path.normpath(sourcedir)
    norm_config_file = os.path.normpath(config_file)
    print "\nProcessing {0} (config = {1})".format(norm_sourcedir,
                                                   norm_config_file)
    old_testsuite = models.TestSuite.objects.get_most_recent_testsuite()
    testsuite = import_testsuite.create_testsuite()
    yaml_categories = yaml.load(open(norm_config_file).read())['Categories']

    for cat in yaml_categories:
        new_category = import_testsuite.add_category('1', cat['Name'], None,
                                                     testsuite, None)
        for epub in cat['Files']:
            fullpath = os.path.join(norm_sourcedir, epub)
            if os.path.isdir(fullpath):
                # this will add a new testsuite
                epubparser = epub_parser.EpubParser()
                epubparser.parse(fullpath, new_category, testsuite,
                                 cat['CategoryDisplayDepthLimit'])
            else:
                print "Not a directory: {0}".format(fullpath)

    num_tests = models.Test.objects.filter(testsuite=testsuite).count()
    print "This testsuite contains {0} tests".format(num_tests)
    import_testsuite.migrate_data(old_testsuite)
    print "Done importing testsuite."
Exemplo n.º 3
0
 def parse(self, folder, parent_category, testsuite, restriction):
     self.folder = folder
     self.testsuite = testsuite
     self.restriction = import_testsuite.category_restriction_to_int(restriction)
     opfpath = self.parse_container()
     navpath = self.parse_opf(opfpath)
     if self.restriction >= 2:
     	foldername = os.path.basename(self.folder)
     	self.epub_category = import_testsuite.add_category(common.CATEGORY_EPUB, \
             self.title, parent_category, testsuite, foldername)
     else:
         self.epub_category = parent_category
     self.parse_nav(navpath)
Exemplo n.º 4
0
 def parse(self, folder, parent_category, testsuite, restriction):
     self.folder = folder
     self.testsuite = testsuite
     self.restriction = import_testsuite.category_restriction_to_int(
         restriction)
     opfpath = self.parse_container()
     navpath = self.parse_opf(opfpath)
     if self.restriction >= 2:
         foldername = os.path.basename(self.folder)
         self.epub_category = import_testsuite.add_category(common.CATEGORY_EPUB, \
                self.title, parent_category, testsuite, foldername)
     else:
         self.epub_category = parent_category
     self.parse_nav(navpath)
Exemplo n.º 5
0
 def parse(self, filename, parent_category, testsuite, restriction):
     # first, extract the file to a temp folder
     zip = zipfile.ZipFile(filename)
     tempdir = tempfile.mkdtemp()
     zip.extractall(tempdir)
     
     self.filename = os.path.basename(filename)
     self.folder = tempdir
     self.testsuite = testsuite
     self.restriction = import_testsuite.category_restriction_to_int(restriction)
     opfpath = self.parse_container()
     navpath = self.parse_opf(opfpath)
     if self.restriction >= 2:
     	foldername = os.path.basename(self.folder)
     	self.epub_category = import_testsuite.add_category(common.CATEGORY_EPUB, \
             self.title, self.description, parent_category, testsuite, filename)
     else:
         self.epub_category = parent_category
     self.parse_nav(navpath)
Exemplo n.º 6
0
def add_testsuite(sourcedir, config_file):
    norm_sourcedir = os.path.normpath(sourcedir)
    norm_config_file = os.path.normpath(config_file)
    print "\nProcessing {0} (config = {1})".format(norm_sourcedir, norm_config_file)
    old_testsuite = models.TestSuite.objects.get_most_recent_testsuite()
    testsuite = import_testsuite.create_testsuite()
    yaml_categories = yaml.load(open(norm_config_file).read())['Categories']

    for cat in yaml_categories:
        new_category = import_testsuite.add_category('1', cat['Name'], None, testsuite, None)
        for epub in cat['Files']:
            fullpath = os.path.join(norm_sourcedir, epub)
            if os.path.isdir(fullpath):
                # this will add a new testsuite
                epubparser = epub_parser.EpubParser()
                epubparser.parse(fullpath, new_category, testsuite, cat['CategoryDisplayDepthLimit'])
            else:
                print "Not a directory: {0}".format(fullpath)

    num_tests = models.Test.objects.filter(testsuite = testsuite).count()
    print "This testsuite contains {0} tests".format(num_tests)
    import_testsuite.migrate_data(old_testsuite)
    print "Done importing testsuite."
Exemplo n.º 7
0
    def process_toc(self, elm, parent_category):
        for c in elm.xpath("xhtml:li", namespaces=NSMAP):
            # Test or Category?
            xpathres = c.xpath("xhtml:a/@href", namespaces=NSMAP)
            test_section = None
            if len(xpathres) != 0:
                href = xpathres[0]
                uri = urlparse(os.path.join(self.dirname, href))
                test_section = self.get_test(uri)
                if test_section != None:
                    xhtml = etree.tostring(
                        test_section).strip()  # trim whitespace
                    name = self.get_label(c)
                    desc = self.get_desc(test_section)
                    testid = uri.fragment
                    required = test_section.attrib['class'].find('ctest') != -1
                    foldername = os.path.basename(self.folder)
                    import_testsuite.add_test(name, desc, parent_category,
                                              required, testid, self.testsuite,
                                              xhtml, foldername)

            if test_section == None:
                # does this container eventually contain a test? otherwise we won't include it.
                if self.test_for_tests(c):
                    desc = self.get_label(c)
                    if self.restriction >= 3:
                        foldername = os.path.basename(self.folder)
                        new_category = import_testsuite.add_category(common.CATEGORY_INTERNAL, \
                            desc, parent_category, self.testsuite, foldername)
                    else:
                        new_category = parent_category
                    # if this element has a nested list
                    # note that test list items don't have nested lists
                    nested_ol = c.xpath("xhtml:ol", namespaces=NSMAP)
                    if len(nested_ol) > 0:
                        self.process_toc(nested_ol[0], new_category)
Exemplo n.º 8
0
def add_testsuite(config_section, sourcedir):
    yaml_categories = config_section['Categories']
    testsuite_type = common.TESTSUITE_TYPE_DEFAULT
    if config_section['Type'] == "Accessibility": #TODO formalize this enum
        testsuite_type = common.TESTSUITE_TYPE_ACCESSIBILITY
    old_testsuite = models.TestSuite.objects.get_most_recent_testsuite_of_type(testsuite_type)
    testsuite = import_testsuite.create_testsuite(testsuite_type)

    epub_id_checker = epub_id_check.EpubIdCheck()
    epub_id_checker.process_epubs(sourcedir)
    for cat in yaml_categories:
        new_category = import_testsuite.add_category('1', cat['Name'], "", None, testsuite, None)
        for epubid in cat['EpubIds']:
            filename = epub_id_checker.get_filename_for_id(epubid)
            epubparser = epub_parser.EpubParser()
            epubparser.parse(filename, new_category, testsuite, cat['CategoryDisplayDepthLimit'])

    num_tests = models.Test.objects.filter(testsuite = testsuite).count()
    print "This testsuite contains {0} tests".format(num_tests)
    if old_testsuite != None:
        import_testsuite.migrate_data(old_testsuite)
    else:
        print "Nothing to migrate"
    print "Done importing testsuite."