mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +00:00
More --clean tests.
This commit is contained in:
parent
2022f25ae9
commit
386e677d80
65
tests/_data_clean/test.py
Normal file
65
tests/_data_clean/test.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
"""unused import"""
|
||||||
|
# pylint: disable=undefined-all-variable, import-error, no-absolute-import, too-few-public-methods, missing-docstring
|
||||||
|
import xml.etree # [unused-import]
|
||||||
|
import xml.sax # [unused-import]
|
||||||
|
import os.path as test # [unused-import]
|
||||||
|
from sys import argv as test2 # [unused-import]
|
||||||
|
from sys import flags # [unused-import]
|
||||||
|
# +1:[unused-import,unused-import]
|
||||||
|
from collections import deque, OrderedDict, Counter
|
||||||
|
# All imports above should be ignored
|
||||||
|
import requests # [unused-import]
|
||||||
|
|
||||||
|
# setuptools
|
||||||
|
import zipimport # command/easy_install.py
|
||||||
|
|
||||||
|
# twisted
|
||||||
|
from importlib import invalidate_caches # python/test/test_deprecate.py
|
||||||
|
|
||||||
|
# astroid
|
||||||
|
import zipimport # manager.py
|
||||||
|
# IPython
|
||||||
|
from importlib.machinery import all_suffixes # core/completerlib.py
|
||||||
|
import importlib # html/notebookapp.py
|
||||||
|
|
||||||
|
from IPython.utils.importstring import import_item # Many files
|
||||||
|
|
||||||
|
# pyflakes
|
||||||
|
# test/test_doctests.py
|
||||||
|
from pyflakes.test.test_imports import Test as TestImports
|
||||||
|
|
||||||
|
# Nose
|
||||||
|
from nose.importer import Importer, add_path, remove_path # loader.py
|
||||||
|
|
||||||
|
# see issue #88
|
||||||
|
import analytics
|
||||||
|
import flask_seasurf
|
||||||
|
|
||||||
|
import atexit
|
||||||
|
from __future__ import print_function
|
||||||
|
from docopt import docopt
|
||||||
|
import curses, logging, sqlite3
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import sqlite3
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
import signal
|
||||||
|
import bs4
|
||||||
|
import nonexistendmodule
|
||||||
|
import boto as b, peewee as p
|
||||||
|
# import django
|
||||||
|
import flask.ext.somext # # #
|
||||||
|
# from sqlalchemy import model
|
||||||
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
|
|
||||||
|
import models
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
pass
|
||||||
|
|
||||||
|
import after_method_is_valid_even_if_not_pep8
|
@ -19,11 +19,12 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.modules = ['flask', 'requests', 'sqlalchemy',
|
self.modules = ['flask', 'requests', 'sqlalchemy',
|
||||||
'docopt', 'boto', 'ipython', 'pyflakes', 'nose', 'analytics_python', 'flask_seasurf',
|
'docopt', 'boto', 'ipython', 'pyflakes', 'nose', 'analytics', 'flask_seasurf',
|
||||||
'peewee', 'ujson', 'nonexistendmodule', 'bs4', 'after_method_is_valid_even_if_not_pep8' ]
|
'peewee', 'ujson', 'nonexistendmodule', 'bs4', 'after_method_is_valid_even_if_not_pep8' ]
|
||||||
self.modules2 = ['beautifulsoup4']
|
self.modules2 = ['beautifulsoup4']
|
||||||
self.local = ["docopt", "requests", "nose", 'pyflakes']
|
self.local = ["docopt", "requests", "nose", 'pyflakes']
|
||||||
self.project = os.path.join(os.path.dirname(__file__), "_data")
|
self.project = os.path.join(os.path.dirname(__file__), "_data")
|
||||||
|
self.project_clean = os.path.join(os.path.dirname(__file__), "_data_clean")
|
||||||
self.project_invalid = os.path.join(os.path.dirname(__file__), "_invalid_data")
|
self.project_invalid = os.path.join(os.path.dirname(__file__), "_invalid_data")
|
||||||
self.project_with_ignore_directory = os.path.join(os.path.dirname(__file__), "_data_ignore")
|
self.project_with_ignore_directory = os.path.join(os.path.dirname(__file__), "_data_ignore")
|
||||||
self.project_with_duplicated_deps = os.path.join(os.path.dirname(__file__), "_data_duplicated_deps")
|
self.project_with_duplicated_deps = os.path.join(os.path.dirname(__file__), "_data_duplicated_deps")
|
||||||
@ -33,6 +34,7 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_all_imports(self):
|
def test_get_all_imports(self):
|
||||||
imports = pipreqs.get_all_imports(self.project)
|
imports = pipreqs.get_all_imports(self.project)
|
||||||
|
print(imports)
|
||||||
self.assertEqual(len(imports), 15) # old value, 13
|
self.assertEqual(len(imports), 15) # old value, 13
|
||||||
for item in imports:
|
for item in imports:
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
@ -208,16 +210,29 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
'--use-local': None, '--force': True, '--proxy': None,
|
'--use-local': None, '--force': True, '--proxy': None,
|
||||||
'--pypi-server': None, '--diff': None, '--clean': None})
|
'--pypi-server': None, '--diff': None, '--clean': None})
|
||||||
assert os.path.exists(self.requirements_path) == 1
|
assert os.path.exists(self.requirements_path) == 1
|
||||||
# with open(self.requirements_path, "r") as f:
|
|
||||||
# print('A')
|
|
||||||
# for l in f: print(l)
|
|
||||||
pipreqs.init({'<path>': self.project, '--savepath': None, '--print': False,
|
pipreqs.init({'<path>': self.project, '--savepath': None, '--print': False,
|
||||||
'--use-local': None, '--force': None, '--proxy': None,
|
'--use-local': None, '--force': None, '--proxy': None,
|
||||||
'--pypi-server': None, '--diff': None,
|
'--pypi-server': None, '--diff': None,
|
||||||
'--clean': self.requirements_path, '--no-pin': True})
|
'--clean': self.requirements_path, '--no-pin': True})
|
||||||
# with open(self.requirements_path, "r") as f:
|
with open(self.requirements_path, "r") as f:
|
||||||
# print('B')
|
data = f.read().lower()
|
||||||
# for l in f: print(l)
|
print(data)
|
||||||
|
for item in self.modules[:-3]: # ['analytics_python', 'flask_seasurf']:
|
||||||
|
self.assertTrue(item.lower() in data)
|
||||||
|
|
||||||
|
def test_clean_with_extras(self):
|
||||||
|
"""
|
||||||
|
Test --clean parameter when there are imports to clean
|
||||||
|
"""
|
||||||
|
pipreqs.init({'<path>': self.project, '--savepath': None, '--print': False,
|
||||||
|
'--use-local': None, '--force': True, '--proxy': None,
|
||||||
|
'--pypi-server': None, '--diff': None, '--clean': None})
|
||||||
|
assert os.path.exists(self.requirements_path) == 1
|
||||||
|
# Continua...
|
||||||
|
pipreqs.init({'<path>': self.project, '--savepath': None, '--print': False,
|
||||||
|
'--use-local': None, '--force': None, '--proxy': None,
|
||||||
|
'--pypi-server': None, '--diff': None,
|
||||||
|
'--clean': self.requirements_path, '--no-pin': True})
|
||||||
with open(self.requirements_path, "r") as f:
|
with open(self.requirements_path, "r") as f:
|
||||||
data = f.read().lower()
|
data = f.read().lower()
|
||||||
print(data)
|
print(data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user