def test_link_tool(self):
     loadPlugins()
     model = scenario_model.loadProject(
         self.locateFile('images/sample.json'))
     model.mediaFromPlugin('OutputPNG::Foo')
     lt = model.getLinkTool('sample', 'orig_input')
     self.assertTrue(isinstance(lt, scenario_model.ImageImageLinkTool))
     mask, analysis, errors = lt.compareImages('sample', 'orig_input',
                                               model, 'OutputPng')
     self.assertTrue(len(errors) == 0)
     self.assertTrue('exifdiff' in analysis)
     self.addFileToRemove('test_sm.csv')
     model.toCSV('test_sm.csv', [
         getPathValuesFunc('arguments.purpose'),
         getPathValuesFunc('arguments.subject')
     ])
     foundPasteSplice = False
     with open('test_sm.csv', 'rb') as fp:
         reader = csv.reader(fp)
         for row in reader:
             self.assertEqual(6, len(row))
             if row[3] == 'PasteSplice':
                 foundPasteSplice = True
                 self.assertEqual('sample', row[0])
                 self.assertEqual('orig_input', row[1])
                 self.assertEqual('input_mod_1', row[2])
                 self.assertEqual('add', row[4])
                 self.assertEqual('man-made object', row[5])
     self.assertTrue(foundPasteSplice)
 def test_getDonorAndBaseNodeTuples(self):
     model = scenario_model.loadProject(
         self.locateFile('images/sample.json'))
     r = model.getDonorAndBaseNodeTuples()
     for t in r:
         if ((u'hat_splice_crop', u'input_mod_1'), u'hat', [
                 u'hat_splice_crop', u'hat_splice_rot_1', u'hat_splice',
                 u'hat'
         ]) == t:
             return
     self.assertTrue(False, 'Should not be here')
Exemplo n.º 3
0
 def test_aproject(self):
     model = loadProject(self.locateFile('images/sample.json'))
     leafBaseTuple = model.getTerminalAndBaseNodeTuples()[0]
     result = graph_rules.setFinalNodeProperties(model, leafBaseTuple[0])
     self.assertEqual('yes', result['manmade'])
     self.assertEqual('no', result['face'])
     self.assertEqual('no', result['postprocesscropframes'])
     self.assertEqual('no', result['spatialother'])
     self.assertEqual('no', result['otherenhancements'])
     self.assertEqual('yes', result['color'])
     self.assertEqual('no', result['blurlocal'])
     self.assertEqual('large', result['compositepixelsize'])
     self.assertEqual('yes', result['imagecompression'])
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-u', '--username', help="optional username", required=False)
    parser.add_argument('--projects', help='Directory of projects')
    args = parser.parse_args()
    initialize(maskGenPreferences, username=args.username)

    project_list = pick_projects(args.projects)

    with open(os.path.join(args.projects,'ErrorReport_' + str(os.getpid()) + '.csv'), 'wb') as csvfile:
        error_writer = csv.writer(csvfile, delimiter = ' ', quotechar='|', quoting=csv.QUOTE_MINIMAL)
        for project in project_list:
            try:
                validate_export(error_writer, project, scenario_model.loadProject(project))
            except Exception as e:
                print (project)
                print (str(e))
Exemplo n.º 5
0
def run_it(temp_folder=None,
           expected_probes_directory='.',
           project_dir='projects'):
    """
    Store results in ErrorReport CSV file.
    If a new project is found in project_dir that has not been processed (not in expected_probes_directory), the results are stored in expected_probes_directory.
    If a project is found in expected_probes_directory, then the project is rerun to compoare to the expected results.
    :param temp_folder:  place to put exploded journals.  Removed upon completion
    :param expected_probes_directory: Expected probes store
    :param project_dir: projects to test
    :return:
    """
    from time import strftime
    if not os.path.exists(project_dir):
        return

    files_to_process = []
    for item in os.listdir(project_dir):
        if item.endswith('tgz'):
            files_to_process.append(
                os.path.abspath(os.path.join(project_dir, item)))

    done_file_name = os.path.join(expected_probes_directory,
                                  'it_tests_done.txt')
    skips = []
    if os.path.exists(done_file_name):
        with open(done_file_name, 'r') as skip:
            skips = skip.readlines()
        skips = [x.strip() for x in skips]

    count = 0
    errorCount = 0
    with open(done_file_name, 'a') as done_file:
        with open(
                os.path.join(
                    expected_probes_directory,
                    'ErrorReport_' + strftime('%b_%d_%Y_%H_%M_%S') + '.csv'),
                'w') as csvfile:
            error_writer = csv.writer(csvfile,
                                      delimiter=' ',
                                      quotechar='|',
                                      quoting=csv.QUOTE_MINIMAL)
            for file_to_process in files_to_process:
                is_error_found = False
                if file_to_process in skips:
                    count += 1
                    continue
                logging.getLogger('maskgen').info(file_to_process)
                process_dir = tempfile.mkdtemp(
                    dir=temp_folder) if temp_folder else tempfile.mkdtemp()
                try:
                    extract_archive(file_to_process, process_dir)
                    for project in bulk_export.pick_projects(process_dir):
                        scModel = loadProject(project)
                        logging.getLogger('maskgen').info(
                            'Processing {} '.format(scModel.getName()))
                        expected_results_directory = os.path.abspath(
                            os.path.join(expected_probes_directory, 'expected',
                                         scModel.getName()))
                        if not os.path.exists(expected_results_directory):
                            os.mkdir(expected_results_directory)
                            method = SeedTestMethod(expected_results_directory)
                        else:
                            method = RunTestMethod(expected_results_directory)
                        method.loadProbesData()
                        generator = ProbeGenerator(
                            scModel=scModel,
                            processors=[
                                ProbeSetBuilder(
                                    scModel=scModel,
                                    compositeBuilders=[EmptyCompositeBuilder])
                            ])
                        probes = generator(keepFailures=True)
                        logging.getLogger('maskgen').info(
                            'Processing {} probes'.format(len(probes)))
                        for probe in probes:
                            for error in method.processProbe(probe):
                                errorCount += 1
                                is_error_found = True
                                error_writer.writerow(
                                    (scModel.getName(), probe.targetBaseNodeId,
                                     probe.finalNodeId, probe.edgeId, error))
                        method.saveProbesData()
                        for probe in method.probesMissed():
                            errorCount += 1
                            is_error_found = True
                            error_writer.writerow(
                                (scModel.getName(), probe.targetBaseNodeId,
                                 probe.finalNodeId, probe.edgeId, "Missing"))
                        if not is_error_found:
                            done_file.write(file_to_process + '\n')
                            done_file.flush()
                        csvfile.flush()
                except Exception as e:
                    logging.getLogger('maskgen').error(str(e))
                    errorCount += 1
                sys.stdout.flush()
                count += 1
                shutil.rmtree(process_dir)
    if errorCount == 0:
        if os.path.exists(done_file_name):
            os.remove(done_file_name)
    return errorCount