Ejemplo n.º 1
0
def test_peek_at_datum_on_port():
    """
    Test peek at datum on a test port with complete datum
    """
    from kwiver.sprokit.pipeline import process
    from kwiver.sprokit.pipeline import datum, DatumType
    from kwiver.vital.config import config
    from kwiver.sprokit.pipeline import edge
    from kwiver.sprokit.pipeline import stamp
    cfg = config.empty_config()
    # Create Dummy Receiver process
    receiver_proc = process.PythonProcess(cfg)
    optional = process.PortFlags()
    receiver_proc.declare_input_port("test_port", "test", optional,
                                     "test_port")
    # Create an Edge and connect input port to the edge
    test_edge = edge.Edge()
    receiver_proc.connect_input_port("test_port", test_edge)
    # Create an Edge Datum and push it to the port
    s = stamp.new_stamp(1)
    e_datum = edge.EdgeDatum(datum.complete(), s)
    test_edge.push_datum(e_datum)
    receiver_datum_type = receiver_proc.peek_at_datum_on_port(
        "test_port").type()
    if receiver_datum_type != DatumType.complete:
        test_error("Datum mismatch: expected a complete datum, got {0}".format(
            receiver_datum_type))
Ejemplo n.º 2
0
 def test_unset_geo_poly(self):
     c = config.empty_config()
     keya = 'keya'
     valuea = create_geo_poly()
     c.set_value_geo_poly(keya, valuea)
     c.unset_value(keya)
     c.get_value_geo_poly(keya)
Ejemplo n.º 3
0
    def test_subblock(self):
        c = config.empty_config()
        block1 = 'block1'
        block2 = 'block2'

        keya = 'keya'
        keyb = 'keyb'
        keyc = 'keyc'

        valuea = 'valuea'
        valueb = 'valueb'
        valuec = 'valuec'

        c.set_value(block1 + config.Config.block_sep() + keya, valuea)
        c.set_value(block1 + config.Config.block_sep() + keyb, valueb)
        c.set_value(block2 + config.Config.block_sep() + keyc, valuec)

        d = c.subblock(block1)
        get_valuea = d.get_value(keya)
        get_valueb = d.get_value(keyb)

        nose.tools.assert_equal(valuea, get_valuea,
                                "Subblock does not inherit expected keys")
        nose.tools.assert_equal(valueb, get_valueb,
                                "Subblock does not inherit expected keys")
        nose.tools.assert_equal(d.has_value(keyc), False,
                                "Subblock inherited unrelated key")
Ejemplo n.º 4
0
 def test_unset_value(self):
     c = config.empty_config()
     keya = 'keya'
     valuea = 'valuea'
     c.set_value(keya, valuea)
     c.unset_value(keya)
     c.get_value(keya)
Ejemplo n.º 5
0
 def test_get_value(self):
     c = config.empty_config()
     keya = 'keya'
     valuea = 'valuea'
     c.set_value(keya, valuea)
     get_valuea = c.get_value(keya)
     nose.tools.assert_equal(valuea, get_valuea)
Ejemplo n.º 6
0
    def nested_config_helper(self, instance, abstract_algo):
        nested_cfg = config.empty_config()
        instance.get_nested_algo_configuration("algorithm", nested_cfg,
                                               instance)

        nose.tools.ok_(
            instance.check_nested_algo_configuration("algorithm", nested_cfg))

        nested_algo = instance.set_nested_algo_configuration(
            "algorithm", nested_cfg)

        # Should have created a concrete algorithm instance
        nose.tools.ok_(type(instance) is type(nested_algo))

        # Verify that the value for key "threshold" is 0.0
        threshold_value = nested_algo.get_configuration().get_value(
            "threshold")
        nose.tools.ok_(
            threshold_value == "0.0",
            "threshold config value {}, expected 0.0".format(threshold_value),
        )

        # Check case where the value for key "type" doesn't match
        # any implementation
        nested_cfg.subblock_view("algorithm").set_value("type", "foo")

        # Check should fail
        nose.tools.assert_false(
            instance.check_nested_algo_configuration("algorithm", nested_cfg))

        # Should get back nullptr
        nose.tools.ok_(
            instance.set_nested_algo_configuration("algorithm", nested_cfg) is
            None)
Ejemplo n.º 7
0
def test_api_calls():
    from kwiver.vital.config import config
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline import process
    from kwiver.sprokit.pipeline import process_factory

    modules.load_known_modules()

    proc_type = 'orphan'
    c = config.empty_config()

    process_factory.create_process(proc_type, '')
    process_factory.create_process(proc_type, '', c)
    process_factory.types()
    process_factory.description(proc_type)

    process_factory.Process.property_no_threads
    process_factory.Process.property_no_reentrancy
    process_factory.Process.property_unsync_input
    process_factory.Process.property_unsync_output
    process_factory.Process.port_heartbeat
    process_factory.Process.config_name
    process_factory.Process.config_type
    process_factory.Process.type_any
    process_factory.Process.type_none
    process_factory.Process.type_data_dependent
    process_factory.Process.type_flow_dependent
    process_factory.Process.flag_output_const
    process_factory.Process.flag_input_static
    process_factory.Process.flag_input_mutable
    process_factory.Process.flag_input_nodep
    process_factory.Process.flag_required
Ejemplo n.º 8
0
 def test_read_only_unset(self):
     c = config.empty_config()
     keya = 'keya'
     valuea = 'valuea'
     c.set_value(keya, valuea)
     c.mark_read_only(keya)
     c.unset_value(keya)
Ejemplo n.º 9
0
 def test_default_value(self):
     c = config.empty_config()
     keya = 'keya'
     keyb = 'keyb'
     valueb = 'valueb'
     get_valueb = c.get_value(keyb, valueb)
     nose.tools.assert_equal(valueb, get_valueb)
Ejemplo n.º 10
0
def test_create():
    from kwiver.vital.config import config
    from kwiver.sprokit.pipeline import pipeline

    c = config.empty_config()

    pipeline.Pipeline()
    pipeline.Pipeline(c)
Ejemplo n.º 11
0
def test_python_to_python(sched_type):
    from kwiver.vital.config import config
    from kwiver.sprokit.pipeline import pipeline
    from kwiver.sprokit.pipeline import process

    name_source = 'source'
    name_sink = 'sink'

    port_output = 'number'
    port_input = 'number'

    min = 0
    max = 10
    output_file = 'test-python-run-python_to_python.txt'

    c = config.empty_config()

    c.set_value(process.PythonProcess.config_name, name_source)
    c.set_value('start', str(min))
    c.set_value('end', str(max))

    s = make_source(c)

    c = config.empty_config()

    c.set_value(process.PythonProcess.config_name, name_sink)
    c.set_value('output', output_file)

    t = make_sink(c)

    p = pipeline.Pipeline(c)

    p.add_process(s)
    p.add_process(t)

    p.connect(name_source, port_output,
              name_sink, port_input)

    p.setup_pipeline()

    run_pipeline(sched_type, p, c)

    check_file(output_file, list(range(min, max)))

    if t.stepped and not t.finalized:
        test_error("sink process not finalized")
Ejemplo n.º 12
0
 def test_delitem(self):
     c = config.empty_config()
     key = 'key'
     value = 'oldvalue'
     c[key] = value
     del c[key]
     nose.tools.assert_equal(c.has_value(key), False,
                             "The key was not deleted")
Ejemplo n.º 13
0
 def test_has_value(self):
     c = config.empty_config()
     keya = 'keya'
     keyb = 'keyb'
     valuea = 'valuea'
     c.set_value(keya, valuea)
     nose.tools.ok_(c.has_value(keya))
     nose.tools.ok_(not c.has_value(keyb))
Ejemplo n.º 14
0
    def test_get_value_geo_poly(self):
        c = config.empty_config()
        keya = "keya"
        valuea = create_geo_poly()

        c.set_value_geo_poly(keya, valuea)
        get_valuea = c.get_value_geo_poly(keya)
        self.check_pts_equal(valuea, get_valuea)
Ejemplo n.º 15
0
    def test_default_value_geo_poly(self):
        c = config.empty_config()
        keyb = 'keyb'
        valueb = create_geo_poly()

        get_valueb = c.get_value_geo_poly(keyb, valueb)

        self.check_pts_equal(valueb, get_valueb)
Ejemplo n.º 16
0
    def test_get_geo_poly_str(self):
        c = config.empty_config()
        keya = 'key'
        valuea = create_geo_poly()

        c.set_value_geo_poly(keya, valuea)
        str_out = c.get_value(keya)
        nose.tools.ok_(isinstance(str_out, str))
Ejemplo n.º 17
0
def test_create():
    from kwiver.vital.config import config
    from kwiver.sprokit.pipeline import edge

    c = config.empty_config()

    edge.Edge()
    edge.Edge(c)
    edge.Edges()
Ejemplo n.º 18
0
 def test_get_value_nested(self):
     c = config.empty_config()
     keya = 'keya'
     keyb = 'keyb'
     valuea = 'valuea'
     c.set_value(keya + config.Config.block_sep() + keyb, valuea)
     nc = c.subblock(keya)
     get_valuea = nc.get_value(keyb)
     nose.tools.assert_equal(valuea, get_valuea)
Ejemplo n.º 19
0
def _dummy_detector_cfg():
    test_cfg = config.empty_config()
    test_cfg.set_value("center_x", "3")
    test_cfg.set_value("center_y", "5")
    test_cfg.set_value("dx", "0.3")
    test_cfg.set_value("dy", "0.2")
    test_cfg.set_value("height", "10")
    test_cfg.set_value("width", "15")
    return test_cfg
Ejemplo n.º 20
0
    def test_get_value_geo_poly_nested(self):
        c = config.empty_config()
        keya = 'keya'
        keyb = 'keyb'
        valuea = create_geo_poly()
        c.set_value_geo_poly(keya + config.Config.block_sep() + keyb, valuea)
        nc = c.subblock(keya)
        get_valuea = nc.get_value_geo_poly(keyb)

        self.check_pts_equal(valuea, get_valuea)
Ejemplo n.º 21
0
    def test_get_value_empty_geo_poly(self):
        c = config.empty_config()
        keya = 'keya'
        valuea = GeoPolygon()

        c.set_value_geo_poly(keya, valuea)
        get_valuea = c.get_value_geo_poly(keya)

        nose.tools.ok_(valuea.is_empty())
        nose.tools.ok_(get_valuea.is_empty())
Ejemplo n.º 22
0
def test_python_to_cpp(sched_type):
    from kwiver.vital.config import config
    from kwiver.sprokit.pipeline import pipeline
    from kwiver.sprokit.pipeline import process

    name_source = 'source'
    name_sink = 'sink'

    port_output = 'number'
    port_input = 'number'

    min = 0
    max = 10
    output_file = 'test-python-run-python_to_cpp.txt'

    c = config.empty_config()

    c.set_value(process.PythonProcess.config_name, name_source)
    c.set_value('start', str(min))
    c.set_value('end', str(max))

    s = make_source(c)

    c = config.empty_config()

    c.set_value('output', output_file)

    t = create_process('print_number', name_sink, c)

    p = pipeline.Pipeline()

    p.add_process(s)
    p.add_process(t)

    p.connect(name_source, port_output,
              name_sink, port_input)

    p.setup_pipeline()

    run_pipeline(sched_type, p, c)

    check_file(output_file, list(range(min, max)))
Ejemplo n.º 23
0
 def get_configuration(self):
     """
     The mixin gets the configuration from super, creates a configuration
     with threshold and merges the two
     :return A kwiver.vital.config.Config object with threshold key
     """
     base_cfg = super(CommonConfigurationMixin, self).get_configuration()
     cfg = config.empty_config()
     cfg.set_value("threshold", str(self.threshold))
     cfg.merge_config(base_cfg)
     return cfg
Ejemplo n.º 24
0
 def test_merge_config(self):
     c = config.empty_config()
     d = config.empty_config()
     keya = 'keya'
     keyb = 'keyb'
     keyc = 'keyc'
     valuea = 'valuea'
     valueb = 'valueb'
     valuec = 'valuec'
     c.set_value(keya, valuea)
     c.set_value(keyb, valuea)
     d.set_value(keyb, valueb)
     d.set_value(keyc, valuec)
     c.merge_config(d)
     get_valuea = c.get_value(keya)
     get_valueb = c.get_value(keyb)
     get_valuec = c.get_value(keyc)
     nose.tools.assert_equal(valuea, get_valuea, "Unmerged key changed")
     nose.tools.assert_equal(valueb, get_valueb,
                             "Conflicting key was not overwritten")
     nose.tools.assert_equal(valuec, get_valuec, "New key did not appear")
Ejemplo n.º 25
0
    def test_set_get_value_wrong_type(self):
        c = config.empty_config()
        key = 'key'
        value_gp = create_geo_poly()
        value_str = 'value_str'

        nose.tools.assert_raises(TypeError, c.set_value_geo_poly, key,
                                 value_str)
        nose.tools.assert_raises(TypeError, c.set_value, key, value_gp)

        c.set_value(key, value_str)

        nose.tools.assert_raises(RuntimeError, c.get_value_geo_poly, key)
Ejemplo n.º 26
0
    def test_available_values(self):
        c = config.empty_config()
        keya = 'keya'
        keyb = 'keyb'

        valuea = 'valuea'
        valueb = 'valueb'

        c.set_value(keya, valuea)
        c.set_value(keyb, valueb)

        avail = c.available_values()
        nose.tools.assert_equal(len(avail), 2)
Ejemplo n.º 27
0
def generate_dummy_config(**kwargs):
    """
    Create an instance of kwiver.vital.config based on the named arguments
    provided to the function
    :param kwargs: Named arguments provided to the function
    :return An instance of config with named arguments as attributes
    """
    test_cfg = config.empty_config()
    for var_name in kwargs:
        if isinstance(type(kwargs[var_name]), type(config)):
            test_config.merge_config(kwargs[var_name])
        else:
            test_cfg.set_value(str(var_name), str(kwargs[var_name]))
    return test_cfg
Ejemplo n.º 28
0
    def test_getitem(self):
        c = config.empty_config()
        key = 'key'
        value = 'oldvalue'
        c[key] = value

        nose.tools.assert_equal(c[key], value)
        nose.tools.ok_(key in c,
                       "{0} is not in config after insertion".format(key))

        value = 'newvalue'
        origvalue = 'newvalue'
        c[key] = value
        value = 'replacedvalue'

        nose.tools.assert_equal(c[key], origvalue, "Value was overwritten")
Ejemplo n.º 29
0
def test_api_calls():
    from kwiver.vital.config import config
    from kwiver.vital.modules import modules
    from kwiver.sprokit.pipeline import pipeline
    from kwiver.sprokit.pipeline import scheduler_factory

    modules.load_known_modules()

    sched_type = 'thread_per_process'
    c = config.empty_config()
    p = pipeline.Pipeline()

    scheduler_factory.create_scheduler(sched_type, p)
    scheduler_factory.create_scheduler(sched_type, p, c)
    scheduler_factory.types()
    scheduler_factory.description(sched_type)
    scheduler_factory.default_type
Ejemplo n.º 30
0
    def test_nested_config(self):
        modules.load_known_modules()
        detector = ImageObjectDetector.create("example_detector")
        nested_cfg = config.empty_config()
        ImageObjectDetector.get_nested_algo_configuration( "detector",
                                                            nested_cfg,
                                                            detector )
        # Verify that test cfg is set to configuration inside detector
        # nested configuration uses the name of a detector as an additional configuration
        # key thus it is checked against 7 rather than 6
        #nose.tools.assert_equal(len(nested_cfg), 7)

        #test_cfg = _dummy_detector_cfg()
        #test_cfg.set_value("example_detector:type", "example_detector")
        #ImageObjectDetector.set_nested_algo_configuration( "example_detector",
        #                                    test_cfg,
        #                                    detector )
        nose.tools.assert_equal(ImageObjectDetector.check_nested_algo_configuration(
                                                            "detector",
                                                            nested_cfg), True)