How to use the humanfriendly.testing.TemporaryDirectory 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_vcs_control_field(self):
        """Test that Debian ``Vcs-*`` control file fields can be generated."""
        with TemporaryDirectory() as directory:
            repository = self.get_instance(bare=False, local=directory)
            self.create_initial_commit(repository)
            returncode, output = run_cli(
                main, '--repository=%s' % repository.local,
                '--vcs-control-field',
            )
            self.assertEquals(returncode, 0)
            assert repository.control_field in output
            assert repository.find_revision_id() in output
github xolox / python-vcs-repo-mgr / vcs_repo_mgr / tests.py View on Github external
def test_find_revision_id(self):
        """Test querying the command line interface for global revision ids."""
        with TemporaryDirectory() as directory:
            repository = self.get_instance(bare=False, local=directory)
            repository.create()
            self.create_initial_commit(repository)
            # Check the global revision id of the initial commit.
            revision_id = repository.find_revision_id()
            self.assertIsInstance(revision_id, string_types)
            self.assertTrue(revision_id)
            # Get the global revision id using the command line interface.
            returncode, output = run_cli(
                main, '--repository=%s' % repository.local,
                '--find-revision-id',
            )
            self.assertEquals(returncode, 0)
            self.assertEquals(output.strip(), revision_id)
github xolox / python-vcs-repo-mgr / vcs_repo_mgr / tests.py View on Github external
def test_find_revision_number(self):
        """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',
github xolox / python-vcs-repo-mgr / vcs_repo_mgr / tests.py View on Github external
def test_checkout(self):
        """Test checking out of branches."""
        contents_on_default_branch = b"This will be part of the initial commit.\n"
        contents_on_dev_branch = b"Not the same contents.\n"
        unversioned_contents = b"This was never committed.\n"
        with TemporaryDirectory() as directory:
            repository = self.get_instance(bare=False, local=directory)
            self.create_initial_commit(repository)
            # Commit a change to README on another branch.
            repository.create_branch('dev')
            self.create_followup_commit(repository)
            # Make sure the working tree can be updated to the default branch.
            repository.checkout()
            self.assertEquals(repository.context.read_file('README'), contents_on_default_branch)
            # Make sure the working tree can be updated to the `dev' branch.
            repository.checkout('dev')
            self.assertEquals(repository.context.read_file('README'), contents_on_dev_branch)
            # Make sure changes in the working tree can be discarded.
            repository.context.write_file('README', unversioned_contents)
            repository.checkout(clean=True)
            self.assertEquals(repository.context.read_file('README'), contents_on_default_branch)
github xolox / python-vcs-repo-mgr / vcs_repo_mgr / tests.py View on Github external
def test_is_clean(self):
        """Test check whether working directory is clean."""
        with TemporaryDirectory() as directory:
            # Initialize a repository object of the parametrized type.
            repository = self.get_instance(bare=False, local=directory)
            # Create the local repository.
            repository.create()
            # Make sure the working tree is considered clean.
            assert repository.is_clean is True
            # Commit a file to version control.
            self.create_initial_commit(repository)
            # Make sure the working tree is still considered clean.
            assert repository.is_clean is True
            # Change the previously committed file.
            repository.context.write_file('README', "Not the same contents.\n")
            # Make sure the working tree is now considered dirty.
            assert repository.is_clean is False
            # Make sure ensure_clean() now raises the expected exception.
            self.assertRaises(WorkingTreeNotCleanError, repository.ensure_clean)
github xolox / python-executor / executor / tests.py View on Github external
except Exception:
            pass
        finally:
            # Make sure the temporary file was cleaned up.
            assert not context.exists(temporary_file)
            # Make sure the target file wasn't created.
            assert not context.exists(random_file)
        # Test context.list_entries() and make sure it doesn't
        # mangle filenames containing whitespace.
        nasty_filenames = [
            'something-innocent',
            'now with spaces',
            'and\twith\ttabs',
            'and\nfinally\nnewlines',
        ]
        with TemporaryDirectory() as directory:
            # Create files with nasty names :-).
            for filename in nasty_filenames:
                with open(os.path.join(directory, filename), 'w') as handle:
                    handle.write('\n')
            # List the directory entries.
            parsed_filenames = context.list_entries(directory)
            # Make sure all filenames were parsed correctly.
            assert sorted(nasty_filenames) == sorted(parsed_filenames)
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.
                    assert copy_password_method.called
                    # Make sure no output was generated.
                    assert not output.strip()
github xolox / python-executor / executor / tests.py View on Github external
def test_remote_working_directory(self):
        """Make sure remote working directories can be set."""
        with SSHServer() as server:
            with TemporaryDirectory() as some_random_directory:
                output = remote('127.0.0.1', 'pwd',
                                capture=True,
                                directory=some_random_directory,
                                **server.client_options)
                assert output == some_random_directory
github xolox / python-vcs-repo-mgr / vcs_repo_mgr / tests.py View on Github external
def test_release_scheme_validation(self):
        """Make sure the release scheme validation refuses invalid values."""
        with TemporaryDirectory() as directory:
            self.assertRaises(
                ValueError, setattr,
                GitRepo(local=directory),
                'release_scheme', 'invalid',
            )
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