How to use the humanfriendly.testing.random_string 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
def test_tags(self):
        """Test that tags can be created and introspected."""
        with TemporaryDirectory() as directory:
            repository = self.get_instance(bare=False, local=directory)
            # Create an initial commit and give it a tag.
            self.create_initial_commit(repository)
            initial_tag = random_string(10)
            assert initial_tag not in repository.tags
            repository.create_tag(initial_tag)
            assert initial_tag in repository.tags
            # Create a follow up commit and give it a tag.
            self.create_followup_commit(repository)
            followup_tag = random_string(10)
            assert followup_tag not in repository.tags
            repository.create_tag(followup_tag)
            assert followup_tag in repository.tags
github xolox / python-vcs-repo-mgr / vcs_repo_mgr / tests.py View on Github external
def commit_file(self, repository, filename=None, contents=None, message=None):
        """Commit a file to the given repository."""
        filename = filename or random_string(15)
        contents = contents or random_string(1024)
        exists = repository.context.exists(filename)
        repository.context.write_file(filename, contents)
        repository.add_files(filename)
        repository.commit(message=message or ("Committing %s file '%s'" % (
            "changed" if exists else "new", filename,
        )))
github xolox / python-capturer / capturer / tests.py View on Github external
def test_combined_capture_subprocess(self):
        """Test combined standard output and error capturing from subprocesses."""
        expected_stdout = random_string()
        expected_stderr = random_string()
        with CaptureOutput() as capturer:
            subprocess.call([
                sys.executable,
                '-c',
                ';'.join([
                    'import sys',
                    'sys.stdout.write(%r)' % (expected_stdout + '\n'),
                    'sys.stderr.write(%r)' % (expected_stderr + '\n'),
                ]),
            ])
            assert expected_stdout in capturer.get_lines()
            assert expected_stderr in capturer.get_lines()
github xolox / python-capturer / capturer / tests.py View on Github external
def test_stderr_capture_same_process(self):
        """Test standard error capturing from the same process."""
        expected_stderr = random_string()
        with CaptureOutput() as capturer:
            sys.stderr.write(expected_stderr + "\n")
            assert expected_stderr in capturer.get_lines()
github xolox / python-qpass / qpass / tests.py View on Github external
def test_cli_quiet(self):
        """Test copying of a password without echoing the entry's text."""
        # Generate a password and some additional text for a dummy password store entry.
        a_password = random_string()
        additional_text = random_string()
        raw_entry = a_password + "\n\n" + additional_text
        # Prepare a mock method to test that the password is copied,
        # but without actually invoking the `pass' program.
        copy_password_method = MagicMock()
        # Some voodoo to mock methods in classes that
        # have yet to be instantiated follows :-).
        mocked_class = type("TestPasswordEntry", (PasswordEntry,), dict(text=raw_entry))
        setattr(mocked_class, "copy_password", copy_password_method)
        with PatchedAttribute(qpass, "PasswordEntry", mocked_class):
            with PatchedAttribute(cli, "is_clipboard_supported", lambda: True):
                with TemporaryDirectory() as directory:
                    touch(os.path.join(directory, "foo.gpg"))
                    returncode, output = run_cli(main, "--password-store=%s" % directory, "--quiet", "foo")
                    # Make sure the command succeeded.
                    assert returncode == 0
                    # Make sure the password was copied to the clipboard.
github xolox / python-vcs-repo-mgr / vcs_repo_mgr / tests.py View on Github external
def test_export(self):
        """Test exporting of revisions."""
        with TemporaryDirectory() as directory:
            # Change the current working directory to our temporary directory
            # so that we can give a relative pathname to export(). This is a
            # regression test for a bug that was fixed in vcs-repo-mgr 4.1.3.
            os.chdir(directory)
            # Initialize a repository object of the parametrized type.
            repository = self.get_instance(bare=False, local=os.path.join(directory, 'repo'))
            repository.create()
            # Commit a file to the repository.
            versioned_filename = random_string(10)
            versioned_contents = random_string(250)
            self.commit_file(
                repository=repository,
                filename=versioned_filename,
                contents=versioned_contents,
                message="Initial commit",
            )
            # Export the initial revision.
            export_directory_relative = 'export'
            export_directory_absolute = os.path.join(directory, export_directory_relative)
            returncode, output = run_cli(
                main, '--repository=%s' % repository.local,
                '--export=%s' % export_directory_relative,
            )
            self.assertEquals(returncode, 0)
            # Check that the file we committed was exported.
            exported_file = os.path.join(export_directory_absolute, versioned_filename)
github xolox / python-qpass / qpass / tests.py View on Github external
def test_cli_filter(self):
        """Test filtering of entry text."""
        # Generate a password and some additional text for a dummy password store entry.
        a_password = random_string()
        additional_text = random_string()
        sensitive_detail = "password: %s" % random_string()
        raw_entry = a_password + "\n\n" + additional_text + "\n" + sensitive_detail
        # Some voodoo to mock methods in classes that
        # have yet to be instantiated follows :-).
        mocked_class = type("TestPasswordEntry", (PasswordEntry,), dict(copy_password=MagicMock(), text=raw_entry))
        with PatchedAttribute(qpass, "PasswordEntry", mocked_class):
            with TemporaryDirectory() as directory:
                touch(os.path.join(directory, "foo.gpg"))
                returncode, output = run_cli(main, "--password-store=%s" % directory, "--filter=^password:", "foo")
                # Make sure the command succeeded.
                assert returncode == 0
                # Make sure the expected output was generated.
                assert additional_text in output
                assert sensitive_detail not in output
github xolox / python-capturer / capturer / tests.py View on Github external
def test_text_capture(self):
        """Test that capturing of all output as a single string is supported."""
        expected_output = random_string()
        with CaptureOutput() as capturer:
            print(expected_output)
            assert expected_output in capturer.get_text()
github xolox / python-capturer / capturer / tests.py View on Github external
def test_unmerged_capture(self):
        """Test that standard output and error can be captured separately."""
        expected_stdout = random_string()
        expected_stderr = random_string()
        with CaptureOutput(merged=False) as capturer:
            sys.stdout.write(expected_stdout + "\n")
            sys.stderr.write(expected_stderr + "\n")
            assert expected_stdout in capturer.stdout.get_lines()
            assert expected_stderr in capturer.stderr.get_lines()
github xolox / python-capturer / capturer / tests.py View on Github external
def test_combined_capture_same_process(self):
        """Test combined standard output and error capturing from the same process."""
        expected_stdout = random_string()
        expected_stderr = random_string()
        with CaptureOutput() as capturer:
            sys.stdout.write(expected_stdout + "\n")
            sys.stderr.write(expected_stderr + "\n")
            assert expected_stdout in capturer.get_lines()
            assert expected_stderr in capturer.get_lines()