def test_current_source_key(mocker, match): mocker.patch( "raincoat.source.get_current_or_latest_version", return_value=(True, "3.8") ) assert pypi.PyPIChecker().current_source_key(match) == ("umbrella", "3.8", True) assert match.other_version == "3.8"
def test_get_source_installed(mocker): source = mocker.patch("raincoat.match.pypi.source") source.get_current_path.return_value = "yay/" source.open_installed.return_value = {"file_1.py": ["yay"]} result = pypi.PyPIChecker().get_source( key=pypi.PyPIKey("umbrella", "3.4", True), files=["file_1.py"]) assert result == {"file_1.py": ["yay"]} assert source.get_current_path.mock_calls == [mocker.call("umbrella")] assert source.open_installed.mock_calls == [ mocker.call('yay/', ['file_1.py'])]
def test_get_source_downloaded(mocker): source = mocker.patch("raincoat.match.pypi.source") source.open_downloaded.return_value = {"file_1.py": ["yay"]} mocker.patch("raincoat.match.pypi.Cleaner.mkdir", return_value="/tmp/clean") result = pypi.PyPIChecker().get_source( key=pypi.PyPIKey("umbrella", "3.4", False), files=["file_1.py"]) assert result == {"file_1.py": ["yay"]} assert source.download_package.mock_calls == [ mocker.call('umbrella', '3.4', '/tmp/clean')] assert source.open_downloaded.mock_calls == [ mocker.call('/tmp/clean', ['file_1.py'])]
def test_get_source_installed(mocker): path = mocker.Mock() path.read_text.return_value = ["yay"] gdf = mocker.patch( "raincoat.source.get_distributed_files", return_value={"file_1.py": path} ) result = pypi.PyPIChecker().get_source( key=pypi.PyPIKey("umbrella", "3.4", True), files=["file_1.py"] ) assert result == {"file_1.py": ["yay"]} gdf.assert_called_with("umbrella")
def test_current_source_key_cache(mocker, match): get_version = mocker.patch( "raincoat.match.pypi.source.get_current_or_latest_version", return_value=(True, "3.7")) checker = pypi.PyPIChecker() a = checker.current_source_key(match) assert len(get_version.mock_calls) == 1 get_version.reset_mock() b = checker.current_source_key(match) assert get_version.mock_calls == [] assert a == b
def test_match_source_key(match): assert pypi.PyPIChecker().match_source_key(match) == ( "umbrella", "3.2", False)