Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix command line arg parsing from string #132

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions spine_engine/utils/command_line_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
# Public License for more details. You should have received a copy of the GNU Lesser General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################

"""
Split command line arguments.

"""
""" Split command line arguments. """


def split_cmdline_args(arg_string):
Expand All @@ -40,7 +36,7 @@ def split_cmdline_args(arg_string):
quoted_context = False
elif not character.isspace() or quoted_context:
current_word = current_word + character
else:
elif current_word:
tokens.append(current_word)
current_word = ""
if current_word:
Expand Down
9 changes: 5 additions & 4 deletions tests/utils/test_command_line_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################

"""
Unit tests for command line args module.

"""
""" Unit tests for command line args module. """

import unittest
from spine_engine.utils.command_line_arguments import split_cmdline_args
Expand All @@ -33,6 +30,10 @@ def test_split_cmdline_args(self):
self.assertEqual(splitted, ["--file=file name with spaces.dat", "-i", "3"])
splitted = split_cmdline_args("'quotation \"within\" a quotation'")
self.assertEqual(splitted, ['quotation "within" a quotation'])
splitted = split_cmdline_args(" ")
self.assertEqual(splitted, [])
splitted = split_cmdline_args("-a -b")
self.assertEqual(splitted, ["-a", "-b"])


if __name__ == "__main__":
Expand Down