/ tests / examples / haystack / news_fetching / test_news_fetching.py
test_news_fetching.py
 1  import os
 2  import pytest
 3  import sys
 4  sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../..')))
 5  
 6  from examples.test_utils.get_trace_data import (
 7      run_command,
 8      extract_information,
 9      load_trace_data
10  )
11  
12  from examples.test_utils.get_components import (
13      get_component_structure_and_sequence
14  )
15  
16  @pytest.mark.parametrize("info", [
17      ("testing-news-fetching"),
18  ])
19  def test_news_fetching(info: str):
20      # Build the command to run news_fetching.py with the provided arguments
21      command = f'python news_fetching.py --info {info}'
22      cwd = os.path.dirname(os.path.abspath(__file__))  # Use the current directory
23      output = run_command(command, cwd=cwd)
24      
25      # Extract trace file location from logs
26      locations = extract_information(output)
27  
28      # Load and validate the trace data
29      data = load_trace_data(locations)
30  
31      # Get component structure and sequence
32      component_sequence = get_component_structure_and_sequence(data)
33  
34      # Print component sequence
35      print("Component sequence:", component_sequence)
36  
37      # Validate component sequence
38      assert len(component_sequence) >= 2, f"Expected at least 2 components, got {len(component_sequence)}"
39  
40