Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a regression bug came from #731 PR #749

Merged
merged 1 commit into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def cli(verbose, quiet, dry_run, pre, rebuild, find_links, index_url, extra_inde

if src_files == ('-',) and not output_file:
raise click.BadParameter('--output-file is required if input is from stdin')
elif src_files == ('setup.py',):
elif src_files == ('setup.py',) and not output_file:
output_file = DEFAULT_REQUIREMENTS_OUTPUT_FILE

if len(src_files) > 1 and not output_file:
Expand Down
38 changes: 32 additions & 6 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ def test_command_line_overrides_pip_conf(pip_conf):
assert 'Using indexes:\n http://override.com' in out.output


@pytest.mark.parametrize('cli_args', [
[],
['setup.py'],
])
def test_command_line_setuptools_read(pip_conf, cli_args):
@pytest.mark.usefixtures('pip_conf')
def test_command_line_setuptools_read():
runner = CliRunner()
with runner.isolated_filesystem():
package = open('setup.py', 'w')
Expand All @@ -90,13 +87,42 @@ def test_command_line_setuptools_read(pip_conf, cli_args):
setup(install_requires=[])
"""))
package.close()
out = runner.invoke(cli, cli_args)
out = runner.invoke(cli)

# check that pip-compile generated a configuration
assert 'This file is autogenerated by pip-compile' in out.output
assert os.path.exists('requirements.txt')


@pytest.mark.usefixtures('pip_conf')
@pytest.mark.parametrize('options, expected_output_file', [
# For the `pip-compile` output file should be "requirements.txt"
([], 'requirements.txt'),
# For the `pip-compile --output-file=output.txt` output file should be "output.txt"
(['--output-file', 'output.txt'], 'output.txt'),
# For the `pip-compile setup.py` output file should be "requirements.txt"
(['setup.py'], 'requirements.txt'),
# For the `pip-compile setup.py --output-file=output.txt` output file should be "output.txt"
(['setup.py', '--output-file', 'output.txt'], 'output.txt'),
])
def test_command_line_setuptools_output_file(options, expected_output_file):
"""
Test the output files for setup.py as a requirement file.
"""
runner = CliRunner()
with runner.isolated_filesystem():
package = open('setup.py', 'w')
package.write(dedent("""\
from setuptools import setup
setup(install_requires=[])
"""))
package.close()

out = runner.invoke(cli, options)
assert out.exit_code == 0
assert os.path.exists(expected_output_file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick: the asserts could be dedented.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Let's clean it up in a following PR.

Copy link
Member Author

@atugushev atugushev Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to that, i would also make the runner a fixture and clean up all the tests (which use the runnrt) like this one: https://github.com/jazzband/pip-tools/blob/67edc7d227507f3902090d2db8e129715279ae04/tests/test_cli_compile.py#L442-L449

IMO the tests look more concise in that way, so let's take advantages of the magnificent pytest.



def test_find_links_option(pip_conf):

assert os.path.exists(pip_conf)
Expand Down