Move parse_assignments() in code
authorKarl O. Pinc <kop@karlpinc.com>
Sun, 28 Jun 2020 20:46:43 +0000 (15:46 -0500)
committerKarl O. Pinc <kop@karlpinc.com>
Sun, 28 Jun 2020 20:46:43 +0000 (15:46 -0500)
src/pgwui_server/__init__.py
tests/test___init__.py

index 6708439a8928c7d5e37abb84a66dcd907def8e81..688b8a499e7919e935d4a645d84e0729f739ae1f 100644 (file)
@@ -189,6 +189,21 @@ def validate_literal_column_headings(errors, settings):
         errors.append(BadLiteralColumnHeadingsError(value))
 
 
+def parse_assignments(lines):
+    '''Return a list of key/value tuples from the lines of a setting
+    '''
+    result = []
+    if isinstance(lines, str):
+        for line in lines.splitlines():
+            if '=' in line:
+                key, val = line.split('=', 1)
+                result.append((key.rstrip(), val.lstrip()))
+    else:
+        for key, val in lines.items():
+            result.append((key, val))
+    return result
+
+
 def validate_settings(errors, settings, components):
     '''Be sure all settings validate
     '''
@@ -224,21 +239,6 @@ def exit_on_invalid_settings(settings, components):
         exit_reporting_errors(errors)
 
 
-def parse_assignments(lines):
-    '''Return a list of key/value tuples from the lines of a setting
-    '''
-    result = []
-    if isinstance(lines, str):
-        for line in lines.splitlines():
-            if '=' in line:
-                key, val = line.split('=', 1)
-                result.append((key.rstrip(), val.lstrip()))
-    else:
-        for key, val in lines.items():
-            result.append((key, val))
-    return result
-
-
 def add_routes(config, settings):
     '''Add routes found in pgwui.routes setting
     '''
index 8eb3741f5d8c7e26ab02cc4faf0f655ab4834eeb..8c93cd2e5104c45fa631ce88c5d23a58dbadce3e 100644 (file)
@@ -307,6 +307,38 @@ mock_validate_literal_column_headings = testing.make_mock_fixture(
     pgwui_server_init, 'validate_literal_column_headings')
 
 
+# parse_assignments()
+
+def test_parse_assignments_str():
+    '''Returns key/value string tuples and ignores lines without an "="'''
+    lines = ('key1 = value1\n'  # whitespace around = is ignored
+             '\n'
+             'ignored\n'
+             'key2=value2\n'    # missing whitespace is fine
+             'key3= value3=withequals\n'
+             )
+    result = pgwui_server_init.parse_assignments(lines)
+    assert set(result) == set([('key1', 'value1'),
+                               ('key2', 'value2'),
+                               ('key3', 'value3=withequals')])
+
+
+def test_parse_assignments_dict():
+    '''Returns key value tuples.
+    '''
+    lines = {'key1': 'value1',
+             'key2': 'value2',
+             }
+    result = pgwui_server_init.parse_assignments(lines)
+    assert set(result) == set([('key1', 'value1'),
+                               ('key2', 'value2'),
+                               ])
+
+
+mock_parse_assignments = testing.make_mock_fixture(
+    pgwui_server_init, 'parse_assignments')
+
+
 # validate_settings()
 
 def test_validate_settings(mock_abort_on_bad_setting,
@@ -424,38 +456,6 @@ mock_exit_on_invalid_settings = testing.make_mock_fixture(
     pgwui_server_init, 'exit_on_invalid_settings')
 
 
-# parse_assignments()
-
-def test_parse_assignments_str():
-    '''Returns key/value string tuples and ignores lines without an "="'''
-    lines = ('key1 = value1\n'  # whitespace around = is ignored
-             '\n'
-             'ignored\n'
-             'key2=value2\n'    # missing whitespace is fine
-             'key3= value3=withequals\n'
-             )
-    result = pgwui_server_init.parse_assignments(lines)
-    assert set(result) == set([('key1', 'value1'),
-                               ('key2', 'value2'),
-                               ('key3', 'value3=withequals')])
-
-
-def test_parse_assignments_dict():
-    '''Returns key value tuples.
-    '''
-    lines = {'key1': 'value1',
-             'key2': 'value2',
-             }
-    result = pgwui_server_init.parse_assignments(lines)
-    assert set(result) == set([('key1', 'value1'),
-                               ('key2', 'value2'),
-                               ])
-
-
-mock_parse_assignments = testing.make_mock_fixture(
-    pgwui_server_init, 'parse_assignments')
-
-
 # autoconfigurable_components()
 
 def test_autoconfiguable_components_no_autoconfig():