bpo-11874: fix assertion failure in argparse metavar handling (GH-1826)


- bugfix and test for fragile metavar handling in argparse (see
  bpo-24089, bpo-14046, bpo-25058, bpo-11874)
- also fixes some incorrect tests that did not make 1-element tuples correctly
(cherry picked from commit 66f02aa32f1e4adb9f24cf186f8c495399d5ce9b)

Co-authored-by: wim glenn <wim.glenn@gmail.com>
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 1b233b8..d000486 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -324,7 +324,11 @@
             if len(prefix) + len(usage) > text_width:
 
                 # break usage into wrappable parts
-                part_regexp = r'\(.*?\)+|\[.*?\]+|\S+'
+                part_regexp = (
+                    r'\(.*?\)+(?=\s|$)|'
+                    r'\[.*?\]+(?=\s|$)|'
+                    r'\S+'
+                )
                 opt_usage = format(optionals, groups)
                 pos_usage = format(positionals, groups)
                 opt_parts = _re.findall(part_regexp, opt_usage)