Skip to content
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
Binary file modified .coverage
Binary file not shown.
6 changes: 3 additions & 3 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
env:
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
run: |
uv run pytest test/ -v --cov=plotsense --cov-report=xml --cov-report=term-missing
uv run pytest tests/ -v --cov=plotsense --cov-report=xml --cov-report=term-missing

- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:

- name: Run unit tests only (fast)
run: |
uv run pytest test/ -v -m "not slow" --tb=short
uv run pytest tests/ -v -m "not slow" --tb=short

lint:
name: Code Quality
Expand Down Expand Up @@ -105,4 +105,4 @@ jobs:

- name: Check test code quality
run: |
uv run flake8 test --count --max-line-length=150 --statistics --extend-ignore=F401,F811
uv run flake8 tests --count --max-line-length=150 --statistics --extend-ignore=F401,F811
2 changes: 0 additions & 2 deletions plotsense/visual_suggestion/suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class VisualizationRecommender:
'groq': [
('llama-3.3-70b-versatile', 0.5), # (model_name, weight)
('llama-3.1-8b-instant', 0.5)

],

}

def __init__(self,
Expand Down
372 changes: 236 additions & 136 deletions test_logs/pytest.log

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions tests/unit/test_hidden_api_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@

class TestHiddenAPIKeyInput:
"""Tests that API key input is hidden from terminal/logs."""

def test_uses_getpass_not_input(self):
"""Verify that getpass.getpass is used instead of input()."""
with patch('getpass.getpass', return_value='hidden_key') as mock_getpass:
key = prompt_for_api_key('groq', 'https://example.com', interactive=True)

# Verify getpass was called
mock_getpass.assert_called_once()
assert key == 'hidden_key'

def test_getpass_masks_input(self):
"""Verify getpass hides input from terminal."""
# getpass.getpass() does not echo input to terminal
# This is verified by the fact that getpass module is imported
# and used instead of builtins.input
with patch('getpass.getpass', return_value='secret_api_key') as mock_getpass:
key = prompt_for_api_key('openai', 'https://openai.com', interactive=True)

# The getpass function is called with appropriate prompt
call_args = mock_getpass.call_args[0][0]
assert 'OPENAI' in call_args.upper()
assert key == 'secret_api_key'

def test_hidden_input_with_skip(self):
"""Hidden input should work with skip_if_missing."""
with patch('getpass.getpass', return_value='') as mock_getpass:
key = prompt_for_api_key(
'anthropic',
'anthropic',
'https://console.anthropic.com/keys',
interactive=True,
skip_if_missing=True
)

mock_getpass.assert_called_once()
assert key is None

def test_hidden_input_required_empty_raises(self):
"""Empty hidden input should raise when key is required."""
with patch('getpass.getpass', return_value='') as mock_getpass:
Expand All @@ -53,28 +53,28 @@ def test_hidden_input_required_empty_raises(self):
interactive=True,
skip_if_missing=False
)

mock_getpass.assert_called_once()

def test_hidden_input_strips_whitespace(self):
"""Hidden input should have whitespace stripped."""
with patch('getpass.getpass', return_value=' api_key_with_spaces ') as mock_getpass:
with patch('getpass.getpass', return_value=' api_key_with_spaces '):
key = prompt_for_api_key('groq', 'https://console.groq.com/keys', interactive=True)

# Whitespace should be stripped
assert key == 'api_key_with_spaces'
assert not key.startswith(' ')
assert not key.endswith(' ')

def test_hidden_input_non_interactive_no_getpass(self):
"""Non-interactive mode should not call getpass."""
with patch('getpass.getpass') as mock_getpass:
with pytest.raises(ValueError):
prompt_for_api_key('groq', 'https://console.groq.com/keys', interactive=False)

# getpass should not be called in non-interactive mode
mock_getpass.assert_not_called()

def test_hidden_input_eof_error(self):
"""Handle EOF when getpass is used."""
with patch('getpass.getpass', side_effect=EOFError):
Expand All @@ -84,7 +84,7 @@ def test_hidden_input_eof_error(self):
'https://aistudio.google.com/app/apikey',
interactive=True
)

def test_hidden_input_os_error(self):
"""Handle OSError when getpass is used."""
with patch('getpass.getpass', side_effect=OSError):
Expand All @@ -94,23 +94,23 @@ def test_hidden_input_os_error(self):
'https://portal.azure.com',
interactive=True
)

def test_hidden_input_multiple_calls(self):
"""Multiple hidden inputs should each use getpass."""
with patch('getpass.getpass', side_effect=['key1', 'key2', 'key3']):
key1 = prompt_for_api_key('groq', 'https://example.com', interactive=True)
key2 = prompt_for_api_key('openai', 'https://example.com', interactive=True)
key3 = prompt_for_api_key('anthropic', 'https://example.com', interactive=True)

assert key1 == 'key1'
assert key2 == 'key2'
assert key3 == 'key3'

def test_hidden_input_with_special_characters(self):
"""Hidden input should handle special characters in API keys."""
special_key = 'sk-key_with-special.chars+/=abc123'

with patch('getpass.getpass', return_value=special_key):
key = prompt_for_api_key('openai', 'https://platform.openai.com/api-keys', interactive=True)

assert key == special_key
Loading
Loading