<reponame>akash0x53/robot-parallel<gh_stars>1-10
#!/usr/bin/env python
# vim: et
# example: SplitSuite.py:3:1 => divide whole suite into 3 parts and execute 1st part
# from parts. 
# Author: <NAME>

from robot.api import SuiteVisitor
from itertools import islice
import math

def chunked(lst, nchunk):
    iter_lst = iter(lst)
    return iter(lambda: list(islice(iter_lst, nchunk)), [])

class SplitSuite(SuiteVisitor):
    """Visitor that keeps only every Xth test in the visited suite structure."""
    def __init__(self, parts, which_part=1):
        self.parts = float(parts)
        self.which_part = int(which_part)

    def visit_suite(self, suite):
        print "Visiting SUITE:", suite
        print "Total number of suites:", len(suite.suites)
        num_suite = math.ceil(len(suite.suites)/self.parts)
        print "number of suites:", num_suite
        chunked_suites = [i for i in chunked(suite.suites, num_suite)]
        suite_to_execute = chunked_suites[self.which_part-1]

        try:
            if len(chunked_suites[self.which_part]) < num_suite and\
                    long(self.which_part) == long(self.parts):
                suite_to_execute.extend(chunked_suites[self.which_part])
        except IndexError:
            pass

        print "Suites in this part:", len(suite_to_execute)
        print "Suites to be execute:", suite_to_execute
        suite.suites = suite_to_execute

#!/usr/bin/env python
# vim: et
# example: SplitSuite.py:3:1 => divide whole suite into 3 parts and execute 1st part
# from parts. 
# Author: <NAME>

from robot.api import SuiteVisitor
from itertools import islice
import math

def chunked(lst, nchunk):
    iter_lst = iter(lst)
    return iter(lambda: list(islice(iter_lst, nchunk)), [])

class SplitSuite(SuiteVisitor):
    """Visitor that keeps only every Xth test in the visited suite structure."""
    def __init__(self, parts, which_part=1):
        self.parts = float(parts)
        self.which_part = int(which_part)

    def visit_suite(self, suite):
        print "Visiting SUITE:", suite
        print "Total number of suites:", len(suite.suites)
        num_suite = math.ceil(len(suite.suites)/self.parts)
        print "number of suites:", num_suite
        chunked_suites = [i for i in chunked(suite.suites, num_suite)]
        suite_to_execute = chunked_suites[self.which_part-1]

        try:
            if len(chunked_suites[self.which_part]) < num_suite and\
                    long(self.which_part) == long(self.parts):
                suite_to_execute.extend(chunked_suites[self.which_part])
        except IndexError:
            pass

        print "Suites in this part:", len(suite_to_execute)
        print "Suites to be execute:", suite_to_execute
        suite.suites = suite_to_execute
#!/usr/bin/env python # vim: et # example: SplitSuite.py:3:1 => divide whole suite into 3 parts and execute 1st part # from parts. # Author: <NAME> Visitor that keeps only every Xth test in the visited suite structure.