How to use the humanfriendly.testing.run_cli function in humanfriendly

To help you get started, we’ve selected a few humanfriendly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xolox / python-vcs-repo-mgr / vcs_repo_mgr / tests.py View on Github external
"""Test querying the command line interface for local revision numbers."""
        with TemporaryDirectory() as directory:
            repository = self.get_instance(bare=False, local=directory)
            repository.create()
            self.create_initial_commit(repository)
            # Check the revision number of the initial commit.
            initial_revision_number = repository.find_revision_number()
            assert initial_revision_number in (0, 1)
            # Create a second commit.
            self.create_followup_commit(repository)
            # Check the revision number of the second commit.
            second_revision_number = repository.find_revision_number()
            assert second_revision_number in (1, 2)
            assert second_revision_number > initial_revision_number
            # Get the local revision number of a revision using the command line interface.
            returncode, output = run_cli(
                main, '--repository=%s' % repository.local,
                '--find-revision-number',
            )
            self.assertEquals(returncode, 0)
            self.assertEquals(int(output), second_revision_number)
github xolox / python-executor / executor / tests.py View on Github external
def fudge_factor_hammer():
            timer = Timer()
            returncode, output = run_cli(
                main,
                '--fudge-factor=%i' % fudge_factor,
                *python_golf('import sys', 'sys.exit(0)')
            )
            assert returncode == 0
            assert timer.elapsed_time > (fudge_factor / 2.0)
        retry(fudge_factor_hammer, 60)
github xolox / python-rotate-backups / rotate_backups / tests.py View on Github external
def test_strict_rotation(self):
        """Test strict rotation."""
        with TemporaryDirectory(prefix='rotate-backups-', suffix='-test-suite') as root:
            os.mkdir(os.path.join(root, 'galera_backup_db4.sl.example.lab_2016-03-17_10-00'))
            os.mkdir(os.path.join(root, 'galera_backup_db4.sl.example.lab_2016-03-17_12-00'))
            os.mkdir(os.path.join(root, 'galera_backup_db4.sl.example.lab_2016-03-17_16-00'))
            run_cli(main, '--hourly=3', '--daily=1', root)
            assert os.path.exists(os.path.join(root, 'galera_backup_db4.sl.example.lab_2016-03-17_10-00'))
            assert os.path.exists(os.path.join(root, 'galera_backup_db4.sl.example.lab_2016-03-17_12-00')) is False
            assert os.path.exists(os.path.join(root, 'galera_backup_db4.sl.example.lab_2016-03-17_16-00'))
github xolox / python-executor / executor / tests.py View on Github external
def timeout_hammer():
            timer = Timer()
            returncode, output = run_cli(
                main, '--timeout=5',
                *python_golf('import time', 'time.sleep(10)')
            )
            assert returncode != 0
            assert timer.elapsed_time < 10
        retry(timeout_hammer, 60)
github xolox / python-rotate-backups / rotate_backups / tests.py View on Github external
])
        with TemporaryDirectory(prefix='rotate-backups-', suffix='-test-suite') as root:
            # Specify the rotation scheme and options through a configuration file.
            config_file = os.path.join(root, 'rotate-backups.ini')
            parser = configparser.RawConfigParser()
            parser.add_section(root)
            parser.set(root, 'hourly', '24')
            parser.set(root, 'daily', '7')
            parser.set(root, 'weekly', '4')
            parser.set(root, 'monthly', '12')
            parser.set(root, 'yearly', 'always')
            parser.set(root, 'ionice', 'idle')
            with open(config_file, 'w') as handle:
                parser.write(handle)
            self.create_sample_backup_set(root)
            run_cli(main, '--verbose', '--config=%s' % config_file)
            backups_that_were_preserved = set(os.listdir(root))
            assert backups_that_were_preserved == expected_to_be_preserved
github xolox / python-rotate-backups / rotate_backups / tests.py View on Github external
def test_minutely_rotation(self):
        """Test rotation with multiple backups per hour."""
        with TemporaryDirectory(prefix='rotate-backups-', suffix='-test-suite') as root:
            os.mkdir(os.path.join(root, 'backup-2016-01-10_21-15-00'))
            os.mkdir(os.path.join(root, 'backup-2016-01-10_21-30-00'))
            os.mkdir(os.path.join(root, 'backup-2016-01-10_21-45-00'))
            run_cli(main, '--prefer-recent', '--relaxed', '--minutely=2', root)
            assert not os.path.exists(os.path.join(root, 'backup-2016-01-10_21-15-00'))
            assert os.path.exists(os.path.join(root, 'backup-2016-01-10_21-30-00'))
            assert os.path.exists(os.path.join(root, 'backup-2016-01-10_21-45-00'))
github xolox / python-rsync-system-backup / rsync_system_backup / tests.py View on Github external
def create_encrypted_backup(self, source, destination):
        """Create a backup to an encrypted device using the command line interface."""
        # Wipe an existing backup (if any).
        if os.path.isdir(destination):
            execute('rm', '--recursive', destination, sudo=True)
        # Create a new backup.
        exit_code, output = run_cli(
            main, '--crypto=%s' % CRYPTO_NAME,
            '--mount=%s' % MOUNT_POINT,
            '--disable-notifications',
            # We skip snapshot creation and rotation to minimize the number
            # of commands required in /etc/sudoers.d/rsync-system-backup.
            '--backup',
            source, destination,
        )
        assert exit_code == 0
github xolox / python-qpass / qpass / tests.py View on Github external
def test_cli_list(self):
        """Test the output of ``qpass --list``."""
        with TemporaryDirectory() as directory:
            touch(os.path.join(directory, "foo.gpg"))
            touch(os.path.join(directory, "foo/bar.gpg"))
            touch(os.path.join(directory, "Also with spaces.gpg"))
            returncode, output = run_cli(main, "--password-store=%s" % directory, "--list")
            assert returncode == 0
            entries = output.splitlines()
            assert "foo" in entries
            assert "foo/bar" in entries
            assert "Also with spaces" in entries
github xolox / python-rotate-backups / rotate_backups / tests.py View on Github external
def test_argument_validation(self):
        """Test argument validation."""
        # Test that an invalid ionice scheduling class causes an error to be reported.
        returncode, output = run_cli(main, '--ionice=unsupported-class')
        assert returncode != 0
        # Test that an invalid rotation scheme causes an error to be reported.
        returncode, output = run_cli(main, '--hourly=not-a-number')
        assert returncode != 0
        # Argument validation tests that require an empty directory.
        with TemporaryDirectory(prefix='rotate-backups-', suffix='-test-suite') as root:
            # Test that non-existing directories cause an error to be reported.
            returncode, output = run_cli(main, os.path.join(root, 'does-not-exist'))
            assert returncode != 0
            # Test that loading of a custom configuration file raises an
            # exception when the configuration file cannot be loaded.
            self.assertRaises(ValueError, lambda: list(load_config_file(os.path.join(root, 'rotate-backups.ini'))))
            # Test that an empty rotation scheme raises an exception.
            self.create_sample_backup_set(root)
            self.assertRaises(ValueError, lambda: RotateBackups(rotation_scheme={}).rotate_backups(root))
        # Argument validation tests that assume the current user isn't root.
github paylogic / py2deb / py2deb / tests.py View on Github external
def test_conversion_of_package_with_dependencies(self):
        """
        Convert a non trivial Python package with several dependencies.

        Converts deb-pkg-tools_ to a Debian package archive and sanity checks the
        result. Performs static checks on the metadata (dependencies) of the
        resulting package archive.

        .. _deb-pkg-tools: https://pypi.org/project/deb-pkg-tools
        """
        # Use a temporary directory as py2deb's repository directory so that we
        # can easily find the *.deb archive generated by py2deb.
        with TemporaryDirectory() as directory:
            # Run the conversion command.
            exit_code, output = run_cli(main, '--repository=%s' % directory, 'deb-pkg-tools==1.22')
            assert exit_code == 0
            # Find the generated Debian package archives.
            archives = glob.glob('%s/*.deb' % directory)
            logger.debug("Found generated archive(s): %s", archives)
            # Make sure the expected dependencies have been converted.
            converted_dependencies = set(parse_filename(a).name for a in archives)
            expected_dependencies = set(convert_package_name(n) for n in (
                'cached-property',
                'chardet',
                'coloredlogs',
                'deb-pkg-tools',
                'executor',
                'humanfriendly',
                'python-debian',
                'six',
            ))