|
1 | 1 | """Testing pipelines and actions.""" |
| 2 | +from pathlib import Path |
2 | 3 |
|
3 | 4 | from clgen import pipeline |
4 | 5 |
|
| 6 | +FIXTURES_DIR = Path(__file__).parent / "fixtures" |
| 7 | + |
5 | 8 |
|
6 | 9 | def test_action_builtin(): |
7 | 10 | """Actions run correctly.""" |
@@ -37,3 +40,47 @@ def test_pipeline_factory(): |
37 | 40 | pipe = pipeline.pipeline_factory(actions) |
38 | 41 | assert pipe.run(" this is a bad idea. ") == "This is a bad idea." |
39 | 42 | assert pipe.run() == "No commit message." |
| 43 | + |
| 44 | + |
| 45 | +def test_pipelline_dag(): |
| 46 | + """Make sure a typical DAG from YAML executes properly.""" |
| 47 | + changelog_path = FIXTURES_DIR / "pipeline_dag_test.md" |
| 48 | + actions = [ |
| 49 | + { |
| 50 | + "action": "AppendString", |
| 51 | + "comment": "Append the changelog from the last release heading on to the generated changelog", |
| 52 | + "kwargs": { |
| 53 | + "postfix": [ |
| 54 | + { |
| 55 | + "action": "ReadFile", |
| 56 | + "comment": "Read the existing changelog", |
| 57 | + "kwargs": {"filename": str(changelog_path)}, |
| 58 | + }, |
| 59 | + { |
| 60 | + "action": "Slice", |
| 61 | + "comment": "Return just part of the file", |
| 62 | + "kwargs": { |
| 63 | + "start": [ |
| 64 | + { |
| 65 | + "action": "ReadFile", |
| 66 | + "comment": "Read the existing changelog", |
| 67 | + "kwargs": {"filename": str(changelog_path)}, |
| 68 | + }, |
| 69 | + { |
| 70 | + "action": "FirstRegExMatchPosition", |
| 71 | + "comment": "Find the position of the last release heading", |
| 72 | + "kwargs": { |
| 73 | + "pattern": r"(?im)^## [0-9]+\.[0-9]+(?:\.[0-9]+)?\s+\([0-9]+-[0-9]{2}-[0-9]{2}\)$" |
| 74 | + }, |
| 75 | + }, |
| 76 | + ] |
| 77 | + }, |
| 78 | + }, |
| 79 | + ] |
| 80 | + }, |
| 81 | + }, |
| 82 | + ] |
| 83 | + pipe = pipeline.pipeline_factory(actions) |
| 84 | + input_text = "This is new\n" |
| 85 | + expected = input_text + "## 0.0.1 (2022-01-01)\n\nThis stuff stays.\n" |
| 86 | + assert pipe.run(input_text) == expected |
0 commit comments