Skip to content

Commit

Permalink
create test for output_requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
fredgrub committed Oct 2, 2023
1 parent cebc3f7 commit ccf097b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/test_pipreqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
Tests for `pipreqs` module.
"""

import io
import sys
import unittest
import os
import requests
Expand Down Expand Up @@ -427,6 +429,49 @@ def test_clean_with_imports_to_clean(self):
data = f.read().lower()
self.assertTrue(cleaned_module not in data)

def test_output_requirements(self):
"""
Test --print parameter
It should print to stdout the same content as requeriments.txt
"""

capturedOutput = io.StringIO()
sys.stdout = capturedOutput

pipreqs.init(
{
"<path>": self.project,
"--savepath": None,
"--print": True,
"--use-local": None,
"--force": None,
"--proxy": None,
"--pypi-server": None,
"--diff": None,
"--clean": None,
"--mode": None,
}
)
pipreqs.init(
{
"<path>": self.project,
"--savepath": None,
"--print": False,
"--use-local": None,
"--force": True,
"--proxy": None,
"--pypi-server": None,
"--diff": None,
"--clean": None,
"--mode": None,
}
)

with open(self.requirements_path, "r") as f:
file_content = f.read().lower()
stdout_content = capturedOutput.getvalue().lower()
self.assertTrue(file_content == stdout_content)

def tearDown(self):
"""
Remove requiremnts.txt files that were written
Expand Down

0 comments on commit ccf097b

Please sign in to comment.