<s> """<STR_LIT>""" <EOL> import unittest <EOL> import os <EOL> import requests <EOL> from pipreqs import pipreqs <EOL> class TestPipreqs ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . modules = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . modules2 = [ '<STR_LIT>' ] <EOL> self . local = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT>' ] <EOL> self . project = os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) <EOL> self . project_invalid = os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) <EOL> self . project_with_ignore_directory = os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) <EOL> self . project_with_duplicated_deps = os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) <EOL> self . requirements_path = os . path . join ( self . project , "<STR_LIT>" ) <EOL> self . alt_requirement_path = os . path . join ( <EOL> self . project , "<STR_LIT>" ) <EOL> def test_get_all_imports ( self ) : <EOL> imports = pipreqs . get_all_imports ( self . project ) <EOL> self . assertEqual ( len ( imports ) , <NUM_LIT> ) <EOL> for item in imports : <EOL> self . assertTrue ( <EOL> item . lower ( ) in self . modules , "<STR_LIT>" + item ) <EOL> self . assertFalse ( "<STR_LIT:time>" in imports ) <EOL> self . assertFalse ( "<STR_LIT>" in imports ) <EOL> self . assertFalse ( "<STR_LIT>" in imports ) <EOL> self . assertFalse ( "<STR_LIT>" in imports ) <EOL> self . assertFalse ( "<STR_LIT>" in imports ) <EOL> self . assertFalse ( "<STR_LIT>" in imports ) <EOL> def test_deduplicate_dependencies ( self ) : <EOL> imports = pipreqs . get_all_imports ( self . project_with_duplicated_deps ) <EOL> pkgs = pipreqs . get_pkg_names ( imports ) <EOL> self . assertEqual ( len ( pkgs ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( "<STR_LIT>" in pkgs ) <EOL> def test_invalid_python ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( SyntaxError , pipreqs . get_all_imports , self . project_invalid ) <EOL> def test_get_imports_info ( self ) : <EOL> """<STR_LIT>""" <EOL> imports = pipreqs . get_all_imports ( self . project ) <EOL> with_info = pipreqs . get_imports_info ( imports ) <EOL> self . assertEqual ( len ( with_info ) , <NUM_LIT:10> ) <EOL> for item in with_info : <EOL> self . assertTrue ( <EOL> item [ '<STR_LIT:name>' ] . lower ( ) in self . modules , <EOL> "<STR_LIT>" + item [ '<STR_LIT:name>' ] ) <EOL> def test_get_use_local_only ( self ) : <EOL> """<STR_LIT>""" <EOL> imports_with_info = pipreqs . get_import_local ( self . modules ) <EOL> for item in imports_with_info : <EOL> self . assertTrue ( item [ '<STR_LIT:name>' ] . lower ( ) in self . local ) <EOL> def test_init ( self ) : <EOL> """<STR_LIT>""" <EOL> pipreqs . init ( { '<STR_LIT>' : self . project , '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , '<STR_LIT>' : True , '<STR_LIT>' : None , '<STR_LIT>' : None } ) <EOL> assert os . path . exists ( self . requirements_path ) == <NUM_LIT:1> <EOL> with open ( self . requirements_path , "<STR_LIT:r>" ) as f : <EOL> data = f . read ( ) . lower ( ) <EOL> for item in self . modules [ : - <NUM_LIT:3> ] : <EOL> self . assertTrue ( item . lower ( ) in data ) <EOL> def test_init_local_only ( self ) : <EOL> """<STR_LIT>""" <EOL> pipreqs . init ( { '<STR_LIT>' : self . project , '<STR_LIT>' : None , <EOL> '<STR_LIT>' : True , '<STR_LIT>' : True , '<STR_LIT>' : None , '<STR_LIT>' : None } ) <EOL> assert os . path . exists ( self . requirements_path ) == <NUM_LIT:1> <EOL> with open ( self . requirements_path , "<STR_LIT:r>" ) as f : <EOL> data = f . readlines ( ) <EOL> for item in data : <EOL> item = item . strip ( ) . split ( "<STR_LIT>" ) <EOL> self . assertTrue ( item [ <NUM_LIT:0> ] . lower ( ) in self . local ) <EOL> def test_init_savepath ( self ) : <EOL> """<STR_LIT>""" <EOL> pipreqs . init ( { '<STR_LIT>' : self . project , '<STR_LIT>' : <EOL> self . alt_requirement_path , '<STR_LIT>' : None , '<STR_LIT>' : None , '<STR_LIT>' : None } ) <EOL> assert os . path . exists ( self . alt_requirement_path ) == <NUM_LIT:1> <EOL> with open ( self . alt_requirement_path , "<STR_LIT:r>" ) as f : <EOL> data = f . read ( ) . lower ( ) <EOL> for item in self . modules [ : - <NUM_LIT:3> ] : <EOL> self . assertTrue ( item . lower ( ) in data ) <EOL> for item in self . modules2 : <EOL> self . assertTrue ( item . lower ( ) in data ) <EOL> def test_init_overwrite ( self ) : <EOL> """<STR_LIT>""" <EOL> with open ( self . requirements_path , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> pipreqs . init ( { '<STR_LIT>' : self . project , '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , '<STR_LIT>' : None , '<STR_LIT>' : None , '<STR_LIT>' : None } ) <EOL> assert os . path . exists ( self . requirements_path ) == <NUM_LIT:1> <EOL> with open ( self . requirements_path , "<STR_LIT:r>" ) as f : <EOL> data = f . read ( ) . lower ( ) <EOL> self . assertEqual ( data , "<STR_LIT>" ) <EOL> def test_get_import_name_without_alias ( self ) : <EOL> """<STR_LIT>""" <EOL> import_name_with_alias = "<STR_LIT>" <EOL> expected_import_name_without_alias = "<STR_LIT>" <EOL> import_name_without_aliases = pipreqs . get_name_without_alias ( <EOL> import_name_with_alias ) <EOL> self . assertEqual ( <EOL> import_name_without_aliases , expected_import_name_without_alias ) <EOL> def test_custom_pypi_server ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( requests . exceptions . MissingSchema , pipreqs . init , { '<STR_LIT>' : self . project , '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , '<STR_LIT>' : True , '<STR_LIT>' : None , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_ignored_directory ( self ) : <EOL> """<STR_LIT>""" <EOL> pipreqs . init ( <EOL> { '<STR_LIT>' : self . project_with_ignore_directory , '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , '<STR_LIT>' : True , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> with open ( os . path . join ( self . project_with_ignore_directory , "<STR_LIT>" ) , "<STR_LIT:r>" ) as f : <EOL> data = f . read ( ) . lower ( ) <EOL> for item in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . assertFalse ( item . lower ( ) in data ) <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> os . remove ( self . requirements_path ) <EOL> except OSError : <EOL> pass <EOL> try : <EOL> os . remove ( self . alt_requirement_path ) <EOL> except OSError : <EOL> pass <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
