import pytest from thefuck.rules.apt_list_upgradable import get_new_command, match from thefuck.types import Command match_output = ''' Hit:1 http://us.archive.ubuntu.com/ubuntu zesty InRelease Hit:2 http://us.archive.ubuntu.com/ubuntu zesty-updates InRelease Get:3 http://us.archive.ubuntu.com/ubuntu zesty-backports InRelease [89.2 kB] Hit:4 http://security.ubuntu.com/ubuntu zesty-security InRelease Hit:5 http://ppa.launchpad.net/ubuntu-mozilla-daily/ppa/ubuntu zesty InRelease Hit:6 https://download.docker.com/linux/ubuntu zesty InRelease Hit:7 https://cli-assets.heroku.com/branches/stable/apt ./ InRelease Fetched 89.2 kB in 0s (122 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done 8 packages can be upgraded. Run 'apt list --upgradable' to see them. ''' no_match_output = ''' Hit:1 http://us.archive.ubuntu.com/ubuntu zesty InRelease Get:2 http://us.archive.ubuntu.com/ubuntu zesty-updates InRelease [89.2 kB] Get:3 http://us.archive.ubuntu.com/ubuntu zesty-backports InRelease [89.2 kB] Get:4 http://security.ubuntu.com/ubuntu zesty-security InRelease [89.2 kB] Hit:5 https://cli-assets.heroku.com/branches/stable/apt ./ InRelease Hit:6 http://ppa.launchpad.net/ubuntu-mozilla-daily/ppa/ubuntu zesty InRelease Hit:7 https://download.docker.com/linux/ubuntu zesty InRelease Get:8 http://us.archive.ubuntu.com/ubuntu zesty-updates/main i386 Packages [232 kB] Get:9 http://us.archive.ubuntu.com/ubuntu zesty-updates/main amd64 Packages [235 kB] Get:10 http://us.archive.ubuntu.com/ubuntu zesty-updates/main amd64 DEP-11 Metadata [55.2 kB] Get:11 http://us.archive.ubuntu.com/ubuntu zesty-updates/main DEP-11 64x64 Icons [32.3 kB] Get:12 http://us.archive.ubuntu.com/ubuntu zesty-updates/universe amd64 Packages [156 kB] Get:13 http://us.archive.ubuntu.com/ubuntu zesty-updates/universe i386 Packages [156 kB] Get:14 http://us.archive.ubuntu.com/ubuntu zesty-updates/universe amd64 DEP-11 Metadata [175 kB] Get:15 http://us.archive.ubuntu.com/ubuntu zesty-updates/universe DEP-11 64x64 Icons [253 kB] Get:16 http://us.archive.ubuntu.com/ubuntu zesty-updates/multiverse amd64 DEP-11 Metadata [5,840 B] Get:17 http://us.archive.ubuntu.com/ubuntu zesty-backports/universe amd64 DEP-11 Metadata [4,588 B] Get:18 http://security.ubuntu.com/ubuntu zesty-security/main amd64 DEP-11 Metadata [12.7 kB] Get:19 http://security.ubuntu.com/ubuntu zesty-security/main DEP-11 64x64 Icons [17.6 kB] Get:20 http://security.ubuntu.com/ubuntu zesty-security/universe amd64 DEP-11 Metadata [21.6 kB] Get:21 http://security.ubuntu.com/ubuntu zesty-security/universe DEP-11 64x64 Icons [47.7 kB] Get:22 http://security.ubuntu.com/ubuntu zesty-security/multiverse amd64 DEP-11 Metadata [208 B] Fetched 1,673 kB in 0s (1,716 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done All packages are up to date. ''' def test_match(): assert match(Command('sudo apt update', match_output)) @pytest.mark.parametrize('command', [ Command('apt-cache search foo', ''), Command('aptitude search foo', ''), Command('apt search foo', ''), Command('apt-get install foo', ''), Command('apt-get source foo', ''), Command('apt-get clean', ''), Command('apt-get remove', ''), Command('apt-get update', ''), Command('sudo apt update', no_match_output) ]) def test_not_match(command): assert not match(command) def test_get_new_command(): new_command = get_new_command(Command('sudo apt update', match_output)) assert new_command == 'sudo apt list --upgradable' new_command = get_new_command(Command('apt update', match_output)) assert new_command == 'apt list --upgradable'