Skip to content

Conversation

@lrsierra
Copy link

What I changed

  • Fix crash at quiz end: join the four letters into a string and use it to build the results URL.
  • Resilient browser launch: wrap webbrowser.open_new() so headless/CI prints the URL instead of throwing.
  • Unit test added: verifies the reported type string and the exact URL opened.

Files

  • jarviscli/plugins/personality.py
  • jarviscli/tests/test_personality_plugin.py

Why

Running the personality plugin crashed after showing the type:

AttributeError: 'list' object has no attribute 'lower'

The code stored the type as a list (e.g., ['I','N','F','J']) and then called .lower() on it when formatting the URL. Joining once into a string fixes this and makes the URL deterministic.


How it works

  • Compute self.type_str = ''.join(self.type) after scoring.
  • Build URL: https://www.16personalities.com/{self.type_str.lower()}-personality.
  • Try webbrowser.open_new(url), and on exception (e.g., headless), print the URL so the session continues gracefully.

How to test

Automated

python -m unittest jarviscli.tests.test_personality_plugin -v

The test:

  • Feeds a deterministic 32-answer set that yields INFJ.
  • Asserts the output contains “Your personality is: INFJ”.
  • Mocks webbrowser.open_new and asserts it was called with:
    https://www.16personalities.com/infj-personality.

Manual (optional)

export PYTHONPATH="$PWD:$PWD/jarviscli:$PYTHONPATH"
python -c "from Jarvis import Jarvis; Jarvis().cmdloop()"
# then, at the prompt:
personality

Answer the prompts; you should see the four-letter result and your browser should open (or the URL prints in headless environments).


Backward compatibility

  • No changes to prompts, colors, or flow.
  • Only fixes the end-of-quiz crash and improves robustness of the browser open step.

Notes

  • Keeps existing path resolution for the TSV via os.path.join(FILE_PATH, ...).
  • Works on macOS/Linux; degrades gracefully when a browser isn’t available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant