Repository: chapyter/chapyter (language: python)

Issue:
Uable to add use %chapyter openai_api_org  = 'value' 
Hi there, I want to configure the chapyter. However, when I use %chapyter openai_api_org = 'org-myorg', it's said that:

UsageError: Invalid usage of the chapyter command: openai_api_org = 'org-PrhJLJTejKb36yGXRldiR9RT'. It supports the following usage:
- %chapyter
  print all the configurable parameters and its current value
- %chapyter <parameter_name>
  print the current value of the parameter
- %chapyter <parameter_name>=<value>
  set the value of the parameter


Discussion / hints:
Can u remove the space between the equal sign and try again? 

Fix patch:
diff --git a/chapyter/magic.py b/chapyter/magic.py
index 0893a1a..f8527c1 100644
--- a/chapyter/magic.py
+++ b/chapyter/magic.py
@@ -353,6 +353,10 @@ def chapyter(self, line):
         - %chapyter <parameter_name>=<value>
           set the value of the parameter
         """
+
+        # This code is inspired by the %config magic command in IPython
+        # See the code here: https://github.com/ipython/ipython/blob/6b17e43544316d691376e35e677032a4b00d6eeb/IPython/core/magics/config.py#L36
+
         # remove text after comments
         line = line.strip().split("#")[0].strip()
 
@@ -366,7 +370,7 @@ def chapyter(self, line):
             return
         elif line in all_class_configs.keys():
             return getattr(self, line)
-        elif "=" in line and line.split("=")[0] in all_class_configs.keys():
+        elif "=" in line and line.split("=")[0].strip() in all_class_configs.keys():
             cfg = Config()
             exec(f"cfg.{self.__class__.__name__}." + line, self.shell.user_ns, locals())
             self.update_config(cfg)


Test patch:
diff --git a/tests/test_chapyter.py b/tests/test_chapyter.py
new file mode 100644
index 0000000..9051337
--- /dev/null
+++ b/tests/test_chapyter.py
@@ -0,0 +1,40 @@
+from IPython.terminal.interactiveshell import TerminalInteractiveShell
+
+from chapyter.magic import Chapyter
+
+
+def test_chapyter_config():
+    shell = TerminalInteractiveShell()
+    shell.run_line_magic("load_ext", "chapyter")
+
+    # Test whether it can display the help message
+    result = shell.run_line_magic("chapyter", "")
+
+    # Test whether it can display the correct default values
+    traits = Chapyter.class_own_traits()
+    for key, value in traits.items():
+        result = shell.run_line_magic("chapyter", key)
+
+        # Skip for cases where the default value is None or empty string
+        # TODO: check why there is such inconsistency
+        if result is None and value.default_value == "":
+            continue
+
+        assert result == value.default_value
+
+    # Test whether it can be used to properly set the values
+    for key, value in traits.items():
+        if isinstance(value, str):
+            shell.run_line_magic("chapyter", f"{key}='test'")
+            result = shell.run_line_magic("chapyter", key)
+            assert result == "test"
+        # Skip for other types for now
+
+    # Test whether it can be used to properly set the values
+    # For cases where there is a space between the value and the equal sign
+    # See https://github.com/chapyter/chapyter/issues/36
+    for key, value in traits.items():
+        if isinstance(value, str):
+            shell.run_line_magic("chapyter", f"{key} = 'text'")
+            result = shell.run_line_magic("chapyter", key)
+            assert result == "text"