|
| 1 | +from textwrap import dedent |
| 2 | + |
| 3 | +import pytest |
| 4 | +from src import parser |
| 5 | + |
| 6 | + |
| 7 | +COMPOSITE_TEST_CASES = [ |
| 8 | + ( |
| 9 | + dedent( # Check that headers, line prefixes are discarded, anthro is joined |
| 10 | + """\ |
| 11 | + #SizeStream Measurements |
| 12 | + #Stored on Tue May 18 06:49:24 2021 |
| 13 | + #SizeStream Core Measurements |
| 14 | + #format - Measurement Valid (1 = valid), Measurement Name, Measurement |
| 15 | + # |
| 16 | + 1 Actual Weight: 1.2 |
| 17 | + #SizeStream Custom Measurements |
| 18 | + #format - Measurement Valid (1 = valid), Measurement Name, Measurement |
| 19 | + # |
| 20 | + 1 Chest: 3.4 |
| 21 | + #SizeStream Landmarks |
| 22 | + #format - Landmarks Valid (1 = valid), Landmark Name, Landmark x y z |
| 23 | + # |
| 24 | + 1 AbdomenBack 5.6 7.8 -9.10 |
| 25 | + """ |
| 26 | + ), |
| 27 | + ["Actual Weight: 1.2", "Chest: 3.4"], |
| 28 | + ["AbdomenBack 5.6 7.8 -9.10"], |
| 29 | + ), |
| 30 | + ( |
| 31 | + dedent( # Check that comments are discarded |
| 32 | + """\ |
| 33 | + #SizeStream Measurements |
| 34 | + #Stored on Tue May 18 06:49:24 2021 |
| 35 | + #SizeStream Core Measurements |
| 36 | + #format - Measurement Valid (1 = valid), Measurement Name, Measurement |
| 37 | + # |
| 38 | + 1 Actual Weight: 1.2 |
| 39 | + #SizeStream Custom Measurements |
| 40 | + #format - Measurement Valid (1 = valid), Measurement Name, Measurement |
| 41 | + # |
| 42 | + 1 ***** Body Fat / Fitness: ***** |
| 43 | + 1 Chest: 3.4 |
| 44 | + #SizeStream Landmarks |
| 45 | + #format - Landmarks Valid (1 = valid), Landmark Name, Landmark x y z |
| 46 | + # |
| 47 | + 1 AbdomenBack 5.6 7.8 -9.10 |
| 48 | + """ |
| 49 | + ), |
| 50 | + ["Actual Weight: 1.2", "Chest: 3.4"], |
| 51 | + ["AbdomenBack 5.6 7.8 -9.10"], |
| 52 | + ), |
| 53 | + ( |
| 54 | + dedent( # Check all encountered name varieties |
| 55 | + """\ |
| 56 | + #SizeStream Measurements |
| 57 | + #Stored on Tue May 18 06:49:24 2021 |
| 58 | + #SizeStream Core Measurements |
| 59 | + #format - Measurement Valid (1 = valid), Measurement Name, Measurement |
| 60 | + # |
| 61 | + 1 Actual Weight: 1.2 |
| 62 | + 1 Waist at 50%: 1.2 |
| 63 | + #SizeStream Custom Measurements |
| 64 | + #format - Measurement Valid (1 = valid), Measurement Name, Measurement |
| 65 | + # |
| 66 | + 1 Chest: 3.4 |
| 67 | + 1 Body Fat (men): 3.4 |
| 68 | + #SizeStream Landmarks |
| 69 | + #format - Landmarks Valid (1 = valid), Landmark Name, Landmark x y z |
| 70 | + # |
| 71 | + 1 AbdomenBack 5.6 7.8 -9.10 |
| 72 | + 1 Small of the Back 5.6 7.8 -9.10 |
| 73 | + """ |
| 74 | + ), |
| 75 | + ["Actual Weight: 1.2", "Waist at 50%: 1.2", "Chest: 3.4", "Body Fat (men): 3.4"], |
| 76 | + ["AbdomenBack 5.6 7.8 -9.10", "Small of the Back 5.6 7.8 -9.10"], |
| 77 | + ), |
| 78 | +] |
| 79 | + |
| 80 | + |
| 81 | +@pytest.mark.parametrize(("raw_src", "truth_anthro", "truth_landmark"), COMPOSITE_TEST_CASES) |
| 82 | +def test_composite_file_parsing( # noqa: D103 |
| 83 | + raw_src: str, truth_anthro: list[str], truth_landmark: list[str] |
| 84 | +) -> None: |
| 85 | + anthro, landmark = parser.split_composite_file(raw_src.splitlines()) |
| 86 | + |
| 87 | + assert anthro == truth_anthro |
| 88 | + assert landmark == truth_landmark |
0 commit comments