I'm using Python Python 3.10.8
I have a function that splits regex delimited strings into a tuple of arbitrary length. I want to count the number of sub-strings returned from my function. But when the source string does not have the delimiter, and my function correctly returns a tuple with a single string, the built-in len() returns the length of the string. How can I know/force that the return value is a single string, and not a collection of characters? This test function does not work as desired:
def test_da_tuple(subject_string, expected_length):
da_tuple = MangleSplitter.tuple_of(subject_string)
pprint.pprint(da_tuple)
tuple_len = len(da_tuple)
assert tuple_len == expected_length, ("\"%s\" split into %d not %d" % (subject_string, tuple_len, expected_length))
And some samples
MANGLED_STR_00 = "Jack L. Chalker - Demons of the Dancing GodsUC - #2DG"
CRAZYNESS = "A - B - C - D - F - F - G - H - I"
MANGLED_STR_07 = "Book Over"
I want my test_da_tuple() to verify 3 for MANGLED_STR_00, 9 for CRAZYNESS, and 1 for MANGLED_STR_07. Instead I get an assertion error that MANGLED_STR_07 split into 9 not 1.