From ccf097b02f9fc01264a8d79dd6d6b701f6550ee2 Mon Sep 17 00:00:00 2001 From: Lucas de Sousa Rosa Date: Thu, 21 Sep 2023 20:29:27 -0300 Subject: [PATCH] create test for output_requirements --- tests/test_pipreqs.py | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/test_pipreqs.py b/tests/test_pipreqs.py index 039d4fd..7cb347d 100644 --- a/tests/test_pipreqs.py +++ b/tests/test_pipreqs.py @@ -8,6 +8,8 @@ Tests for `pipreqs` module. """ +import io +import sys import unittest import os import requests @@ -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( + { + "": self.project, + "--savepath": None, + "--print": True, + "--use-local": None, + "--force": None, + "--proxy": None, + "--pypi-server": None, + "--diff": None, + "--clean": None, + "--mode": None, + } + ) + pipreqs.init( + { + "": 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