-
Notifications
You must be signed in to change notification settings - Fork 1
Improve test coverage from 29.7% to 51.3% - Add comprehensive tests for core modules #105
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
Changes from all commits
222533f
b93076e
43895b8
6be2eab
654707a
2b9700a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| """ | ||
| Tests for Rapid7 InsightVM config module. | ||
|
|
||
| Tests the config.py module for persistent configuration management. | ||
| """ | ||
|
|
||
| import json | ||
| import pytest | ||
| from pathlib import Path | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) standard import "from pathlib import Path" should be placed before "import pytest" Warning test
standard import "from pathlib import Path" should be placed before "import pytest"
|
||
| from unittest.mock import Mock, patch, mock_open | ||
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Unused Mock imported from unittest.mock Note test
Unused Mock imported from unittest.mock
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Unused mock_open imported from unittest.mock Note test
Unused mock_open imported from unittest.mock
Check warningCode scanning / Pylintpython3 (reported by Codacy) standard import "from unittest.mock import Mock, patch, mock_open" should be placed before "import pytest" Warning test
standard import "from unittest.mock import Mock, patch, mock_open" should be placed before "import pytest"
|
||
| import tempfile | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) standard import "import tempfile" should be placed before "import pytest" Warning test
standard import "import tempfile" should be placed before "import pytest"
|
||
| import shutil | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) standard import "import shutil" should be placed before "import pytest" Warning test
standard import "import shutil" should be placed before "import pytest"
|
||
|
|
||
| from rapid7.config import Config, get_config | ||
|
|
||
|
|
||
| class TestConfig: | ||
| """Test Config class functionality.""" | ||
|
|
||
| @pytest.fixture | ||
| def temp_config_dir(self): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Create a temporary config directory for testing.""" | ||
| temp_dir = tempfile.mkdtemp() | ||
| yield temp_dir | ||
| shutil.rmtree(temp_dir, ignore_errors=True) | ||
|
|
||
| def test_init_creates_directories(self, temp_config_dir): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test that Config creates necessary directories.""" | ||
| config = Config(config_dir=temp_config_dir) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| assert config.config_dir.exists() | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert config.state_dir.exists() | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert config.config_dir == Path(temp_config_dir) | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_init_with_default_directory(self): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test that Config uses default directory when not specified.""" | ||
| with patch('pathlib.Path.mkdir'): | ||
| with patch('pathlib.Path.exists', return_value=False): | ||
| config = Config() | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| expected_dir = Path.home() / '.insightvm' | ||
| assert config.config_dir == expected_dir | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_default_config_structure(self, temp_config_dir): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test that default configuration has expected structure.""" | ||
| config = Config(config_dir=temp_config_dir) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Check top-level keys | ||
| assert 'version' in config.data | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert 'preferences' in config.data | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert 'tools' in config.data | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Check preferences | ||
| prefs = config.data['preferences'] | ||
| assert 'confirm_destructive_operations' in prefs | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert 'colored_output' in prefs | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert 'show_progress_bars' in prefs | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert 'verbose' in prefs | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Check tools | ||
| tools = config.data['tools'] | ||
| assert 'sonar_queries' in tools | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert 'insight_agent' in tools | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert 'scan_assistant' in tools | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_save_config(self, temp_config_dir): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test saving configuration to file.""" | ||
| config = Config(config_dir=temp_config_dir) | ||
| config.data['preferences']['verbose'] = True | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| config.save() | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Verify file was created | ||
| assert config.config_file.exists() | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Verify content | ||
| with open(config.config_file, 'r') as f: | ||
| saved_data = json.load(f) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| assert saved_data['preferences']['verbose'] is True | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_load_existing_config(self, temp_config_dir): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test loading existing configuration from file.""" | ||
| # Create a config file | ||
| config_file = Path(temp_config_dir) / 'config.json' | ||
| config_data = { | ||
| 'version': '2.0.0', | ||
| 'preferences': {'verbose': True}, | ||
| 'tools': {} | ||
| } | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| Path(temp_config_dir).mkdir(parents=True, exist_ok=True) | ||
| with open(config_file, 'w') as f: | ||
| json.dump(config_data, f) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Load config | ||
| config = Config(config_dir=temp_config_dir) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| assert config.data['preferences']['verbose'] is True | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_get_preference(self, temp_config_dir): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test getting a preference value.""" | ||
| config = Config(config_dir=temp_config_dir) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| value = config.get_preference('colored_output') | ||
| assert value is True | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Test with default value | ||
| value = config.get_preference('nonexistent', default=False) | ||
| assert value is False | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_set_preference(self, temp_config_dir): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test setting a preference value.""" | ||
| config = Config(config_dir=temp_config_dir) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| config.set_preference('verbose', True) | ||
| assert config.data['preferences']['verbose'] is True | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_get_tool_config(self, temp_config_dir): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test getting tool configuration.""" | ||
| config = Config(config_dir=temp_config_dir) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| sonar_config = config.get_tool_config('sonar_queries') | ||
| assert sonar_config is not None | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert 'default_days' in sonar_config | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert sonar_config['default_days'] == 30 | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_set_tool_config(self, temp_config_dir): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test setting tool configuration.""" | ||
| config = Config(config_dir=temp_config_dir) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| new_config = {'custom_setting': 'value'} | ||
| config.set_tool_config('custom_tool', new_config) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| assert 'custom_tool' in config.data['tools'] | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert config.data['tools']['custom_tool']['custom_setting'] == 'value' | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_save_state(self, temp_config_dir): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test saving tool state.""" | ||
| config = Config(config_dir=temp_config_dir) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| state_data = {'progress': 50, 'last_item': 'item_123'} | ||
| config.save_state('test_tool', state_data) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| state_file = config.state_dir / 'test_tool_state.json' | ||
| assert state_file.exists() | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| with open(state_file, 'r') as f: | ||
| saved_state = json.load(f) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| assert saved_state['progress'] == 50 | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert saved_state['last_item'] == 'item_123' | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_load_state(self, temp_config_dir): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test loading tool state.""" | ||
| config = Config(config_dir=temp_config_dir) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Save state first | ||
| state_data = {'progress': 75} | ||
| config.save_state('test_tool', state_data) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Load state | ||
| loaded_state = config.load_state('test_tool') | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| assert loaded_state is not None | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert loaded_state['progress'] == 75 | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_load_state_nonexistent(self, temp_config_dir): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test loading state that doesn't exist.""" | ||
| config = Config(config_dir=temp_config_dir) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| state = config.load_state('nonexistent_tool') | ||
| assert state is None | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_clear_state(self, temp_config_dir): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test clearing tool state.""" | ||
| config = Config(config_dir=temp_config_dir) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Save state | ||
| config.save_state('test_tool', {'data': 'test'}) | ||
| state_file = config.state_dir / 'test_tool_state.json' | ||
| assert state_file.exists() | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Clear state | ||
| config.clear_state('test_tool') | ||
| assert not state_file.exists() | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_load_config_with_json_error(self, temp_config_dir): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test handling of corrupted JSON config file.""" | ||
| config_file = Path(temp_config_dir) / 'config.json' | ||
| Path(temp_config_dir).mkdir(parents=True, exist_ok=True) | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Write invalid JSON | ||
| with open(config_file, 'w') as f: | ||
| f.write('{ invalid json }') | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Should fall back to default config | ||
| config = Config(config_dir=temp_config_dir) | ||
| assert 'version' in config.data | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert config.data['version'] == '2.0.0' | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
|
|
||
| class TestGetConfig: | ||
| """Test get_config helper function.""" | ||
|
|
||
| def test_get_config_singleton(self): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test that get_config returns a singleton instance.""" | ||
| config1 = get_config() | ||
| config2 = get_config() | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| # Should return the same instance | ||
| assert config1 is config2 | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_get_config_returns_config_instance(self): | ||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Method could be a function Warning test
Method could be a function
|
||
| """Test that get_config returns a Config instance.""" | ||
| config = get_config() | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Trailing whitespace Warning test
Trailing whitespace
|
||
| assert isinstance(config, Config) | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert hasattr(config, 'data') | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert hasattr(config, 'save') | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert hasattr(config, 'get_preference') | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
Check warning
Code scanning / Prospector (reported by Codacy)
'unittest.mock.Mock' imported but unused (F401) Warning test