def test_add_nested_children(): graph = Graph() de1, de2, de3 = DummyExtractor(), DummyExtractor(), DummyExtractor() graph.add_children([de1, (de2, 'child', [(de3, "child's child")])]) assert len(graph.children) == 2 assert isinstance(graph.children[1].children[0], Node) assert graph.children[1].children[0].name == "child's child"
def test_graph_smoke_test(): filename = join(get_test_data_path(), 'image', 'obama.jpg') stim = ImageStim(filename) nodes = [(BrightnessExtractor(), 'brightness')] graph = Graph(nodes) result = graph.extract([stim]) brightness = result[('BrightnessExtractor', 'brightness')].values[0] assert_almost_equal(brightness, 0.556134, 5)
def test_small_pipeline(): pytest.importorskip('pytesseract') filename = join(get_test_data_path(), 'image', 'button.jpg') stim = ImageStim(filename) nodes = [(TesseractConverter(), 'tesseract', [(LengthExtractor(), 'length')])] graph = Graph(nodes) result = graph.extract([stim]) assert (0, 'button.jpg_Exit') in result.index assert ('LengthExtractor', 'text_length') in result.columns assert result[('LengthExtractor', 'text_length')].values[0] == 4
def test_node_arg_parsing(): n1, n2 = 'MyLovelyExtractor', ['MyLovelyExtractor'] args1 = Graph._parse_node_args(n1) args2 = Graph._parse_node_args(n2) assert args1 == args2 == {'transformer': 'MyLovelyExtractor'} node = ('saliencyextractor', 'saliency') args = Graph._parse_node_args(node) assert set(args.keys()) == {'transformer', 'name'} node = ('saliencyextractor', 'my_name', [('child1'), ('child2')]) args = Graph._parse_node_args(node) assert set(args.keys()) == {'transformer', 'name', 'children'} assert len(args['children']) == 2 node = { 'transformer': '...', 'name': '...'} args = Graph._parse_node_args(node) assert args == node
def test_big_pipeline(): filename = join(get_test_data_path(), 'video', 'obama_speech.mp4') video = VideoStim(filename) visual_nodes = [(FrameSamplingConverter(every=15), 'framesampling', [(TesseractConverter(), 'visual_text', [(LengthExtractor(), 'text_length')]), (VibranceExtractor(), 'visual_vibrance')])] audio_nodes = [(VideoToAudioConverter(), 'audio', [(WitTranscriptionConverter(), 'audio_text', [(LengthExtractor(), 'text_length')])])] graph = Graph() graph.add_children(visual_nodes) graph.add_children(audio_nodes) result = graph.extract(video) assert ('LengthExtractor', 'text_length') in result.columns assert ('VibranceExtractor', 'vibrance') in result.columns assert not result[('onset', '')].isnull().any() assert 'obama_speech.mp4_obama_speech.wav_today' in result.index.get_level_values(1) assert 'obama_speech.mp4_90' in result.index.get_level_values(1)
def test_add_children(): graph = Graph() de1, de2, de3 = DummyExtractor(), DummyExtractor(), DummyExtractor() graph.add_children([de1, de2, de3]) assert len(graph.children) == 3 assert all([isinstance(c, Node) for c in graph.children])