51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
"""Tests for pattern detection module."""
|
|
|
|
from cmdparse.patterns import detect_pattern_type
|
|
|
|
|
|
class TestDetectPatternType:
|
|
def test_empty_input_returns_empty(self):
|
|
assert detect_pattern_type("") == "empty"
|
|
assert detect_pattern_type(" ") == "empty"
|
|
assert detect_pattern_type("\n\n") == "empty"
|
|
|
|
def test_table_detection(self):
|
|
table_input = """NAME IMAGE STATUS
|
|
nginx nginx:1 running
|
|
redis redis:3 stopped"""
|
|
result = detect_pattern_type(table_input)
|
|
assert result in ["table", "key_value_block"]
|
|
|
|
def test_key_value_colon_detection(self):
|
|
kv_input = """name: John
|
|
age: 30
|
|
city: NYC"""
|
|
result = detect_pattern_type(kv_input)
|
|
assert result == "key_value_colon"
|
|
|
|
def test_key_value_equals_detection(self):
|
|
kv_input = """name=John
|
|
age=30
|
|
city=NYC"""
|
|
result = detect_pattern_type(kv_input)
|
|
assert result == "key_value_equals"
|
|
|
|
def test_delimited_comma_detection(self):
|
|
csv_input = """name,age,city
|
|
John,30,NYC
|
|
Jane,25,LA"""
|
|
result = detect_pattern_type(csv_input)
|
|
assert result == "delimited_comma"
|
|
|
|
def test_delimited_tab_detection(self):
|
|
tsv_input = """name\tage\tcity
|
|
John\t30\tNYC"""
|
|
result = detect_pattern_type(tsv_input)
|
|
assert result == "delimited_tab"
|
|
|
|
def test_raw_text_detection(self):
|
|
raw_input = """This is just some random text
|
|
Without any particular structure"""
|
|
result = detect_pattern_type(raw_input)
|
|
assert result in ["raw", "table", "key_value_block"]
|