<s> import os <EOL> import sys <EOL> import tempfile <EOL> import shutil <EOL> import string <EOL> import pytest <EOL> import pkg_resources <EOL> from pkg_resources import ( parse_requirements , VersionConflict , parse_version , <EOL> Distribution , EntryPoint , Requirement , safe_version , safe_name , <EOL> WorkingSet ) <EOL> packaging = pkg_resources . packaging <EOL> def safe_repr ( obj , short = False ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> result = repr ( obj ) <EOL> except Exception : <EOL> result = object . __repr__ ( obj ) <EOL> if not short or len ( result ) < pkg_resources . _MAX_LENGTH : <EOL> return result <EOL> return result [ : pkg_resources . _MAX_LENGTH ] + '<STR_LIT>' <EOL> class Metadata ( pkg_resources . EmptyProvider ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * pairs ) : <EOL> self . metadata = dict ( pairs ) <EOL> def has_metadata ( self , name ) : <EOL> return name in self . metadata <EOL> def get_metadata ( self , name ) : <EOL> return self . metadata [ name ] <EOL> def get_metadata_lines ( self , name ) : <EOL> return pkg_resources . yield_lines ( self . get_metadata ( name ) ) <EOL> dist_from_fn = pkg_resources . Distribution . from_filename <EOL> class TestDistro : <EOL> def testCollection ( self ) : <EOL> ad = pkg_resources . Environment ( [ ] , platform = None , python = None ) <EOL> assert list ( ad ) == [ ] <EOL> assert ad [ '<STR_LIT>' ] == [ ] <EOL> ad . add ( dist_from_fn ( "<STR_LIT>" ) ) <EOL> ad . add ( dist_from_fn ( "<STR_LIT>" ) ) <EOL> ad . add ( dist_from_fn ( "<STR_LIT>" ) ) <EOL> assert ad [ '<STR_LIT>' ] <EOL> assert list ( ad ) == [ '<STR_LIT>' ] <EOL> assert [ dist . version for dist in ad [ '<STR_LIT>' ] ] == [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ad . remove ( ad [ '<STR_LIT>' ] [ <NUM_LIT:1> ] ) <EOL> assert [ dist . version for dist in ad [ '<STR_LIT>' ] ] == [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ad . add ( dist_from_fn ( "<STR_LIT>" ) ) <EOL> assert [ dist . version for dist in ad [ '<STR_LIT>' ] ] == [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ws = WorkingSet ( [ ] ) <EOL> foo12 = dist_from_fn ( "<STR_LIT>" ) <EOL> foo14 = dist_from_fn ( "<STR_LIT>" ) <EOL> req , = parse_requirements ( "<STR_LIT>" ) <EOL> assert ad . best_match ( req , ws ) . version == '<STR_LIT>' <EOL> ws . add ( foo14 ) <EOL> assert ad . best_match ( req , ws ) . version == '<STR_LIT>' <EOL> ws = WorkingSet ( [ ] ) <EOL> ws . add ( foo12 ) <EOL> ws . add ( foo14 ) <EOL> with pytest . raises ( VersionConflict ) : <EOL> ad . best_match ( req , ws ) <EOL> ws = WorkingSet ( [ ] ) <EOL> ws . add ( foo14 ) <EOL> ws . add ( foo12 ) <EOL> ws . add ( foo14 ) <EOL> assert ad . best_match ( req , ws ) . version == '<STR_LIT>' <EOL> def checkFooPkg ( self , d ) : <EOL> assert d . project_name == "<STR_LIT>" <EOL> assert d . key == "<STR_LIT>" <EOL> assert d . version == "<STR_LIT>" <EOL> assert d . py_version == "<STR_LIT>" <EOL> assert d . platform == "<STR_LIT:win32>" <EOL> assert d . parsed_version == parse_version ( "<STR_LIT>" ) <EOL> def testDistroBasics ( self ) : <EOL> d = Distribution ( <EOL> "<STR_LIT>" , <EOL> project_name = "<STR_LIT>" , version = "<STR_LIT>" , py_version = "<STR_LIT>" , platform = "<STR_LIT:win32>" <EOL> ) <EOL> self . checkFooPkg ( d ) <EOL> d = Distribution ( "<STR_LIT>" ) <EOL> assert d . py_version == sys . version [ : <NUM_LIT:3> ] <EOL> assert d . platform == None <EOL> def testDistroParse ( self ) : <EOL> d = dist_from_fn ( "<STR_LIT>" ) <EOL> self . checkFooPkg ( d ) <EOL> d = dist_from_fn ( "<STR_LIT>" ) <EOL> self . checkFooPkg ( d ) <EOL> def testDistroMetadata ( self ) : <EOL> d = Distribution ( <EOL> "<STR_LIT>" , project_name = "<STR_LIT>" , py_version = "<STR_LIT>" , platform = "<STR_LIT:win32>" , <EOL> metadata = Metadata ( <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> ) <EOL> ) <EOL> self . checkFooPkg ( d ) <EOL> def distRequires ( self , txt ) : <EOL> return Distribution ( "<STR_LIT>" , metadata = Metadata ( ( '<STR_LIT>' , txt ) ) ) <EOL> def checkRequires ( self , dist , txt , extras = ( ) ) : <EOL> assert list ( dist . requires ( extras ) ) == list ( parse_requirements ( txt ) ) <EOL> def testDistroDependsSimple ( self ) : <EOL> for v in "<STR_LIT>" , "<STR_LIT>" : <EOL> self . checkRequires ( self . distRequires ( v ) , v ) <EOL> def testResolve ( self ) : <EOL> ad = pkg_resources . Environment ( [ ] ) <EOL> ws = WorkingSet ( [ ] ) <EOL> assert list ( ws . resolve ( [ ] , ad ) ) == [ ] <EOL> with pytest . raises ( pkg_resources . DistributionNotFound ) : <EOL> ws . resolve ( parse_requirements ( "<STR_LIT>" ) , ad ) <EOL> Foo = Distribution . from_filename ( <EOL> "<STR_LIT>" , <EOL> metadata = Metadata ( ( '<STR_LIT>' , "<STR_LIT>" ) ) <EOL> ) <EOL> ad . add ( Foo ) <EOL> ad . add ( Distribution . from_filename ( "<STR_LIT>" ) ) <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> targets = list ( ws . resolve ( parse_requirements ( "<STR_LIT>" ) , ad ) ) <EOL> assert targets == [ Foo ] <EOL> list ( map ( ws . add , targets ) ) <EOL> with pytest . raises ( VersionConflict ) : <EOL> ws . resolve ( parse_requirements ( "<STR_LIT>" ) , ad ) <EOL> ws = WorkingSet ( [ ] ) <EOL> with pytest . raises ( pkg_resources . DistributionNotFound ) : <EOL> ws . resolve ( parse_requirements ( "<STR_LIT>" ) , ad ) <EOL> Baz = Distribution . from_filename ( <EOL> "<STR_LIT>" , metadata = Metadata ( ( '<STR_LIT>' , "<STR_LIT>" ) ) <EOL> ) <EOL> ad . add ( Baz ) <EOL> assert list ( ws . resolve ( parse_requirements ( "<STR_LIT>" ) , ad ) ) == [ Foo , Baz ] <EOL> with pytest . raises ( VersionConflict ) as vc : <EOL> ws . resolve ( parse_requirements ( "<STR_LIT>" ) , ad ) <EOL> msg = '<STR_LIT>' <EOL> assert vc . value . report ( ) == msg <EOL> def testDistroDependsOptions ( self ) : <EOL> d = self . distRequires ( """<STR_LIT>""" ) <EOL> self . checkRequires ( d , "<STR_LIT>" ) <EOL> self . checkRequires ( <EOL> d , "<STR_LIT>" . split ( ) , [ "<STR_LIT>" ] <EOL> ) <EOL> self . checkRequires ( <EOL> d , "<STR_LIT>" . split ( ) , [ "<STR_LIT>" ] <EOL> ) <EOL> self . checkRequires ( <EOL> d , "<STR_LIT>" . split ( ) , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ) <EOL> self . checkRequires ( <EOL> d , "<STR_LIT>" . split ( ) , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ) <EOL> with pytest . raises ( pkg_resources . UnknownExtra ) : <EOL> d . requires ( [ "<STR_LIT:foo>" ] ) <EOL> class TestWorkingSet : <EOL> def test_find_conflicting ( self ) : <EOL> ws = WorkingSet ( [ ] ) <EOL> Foo = Distribution . from_filename ( "<STR_LIT>" ) <EOL> ws . add ( Foo ) <EOL> req = next ( parse_requirements ( "<STR_LIT>" ) ) <EOL> with pytest . raises ( VersionConflict ) as vc : <EOL> ws . find ( req ) <EOL> msg = '<STR_LIT>' <EOL> assert vc . value . report ( ) == msg <EOL> def test_resolve_conflicts_with_prior ( self ) : <EOL> """<STR_LIT>""" <EOL> ws = WorkingSet ( [ ] ) <EOL> md = Metadata ( ( '<STR_LIT>' , "<STR_LIT>" ) ) <EOL> Foo = Distribution . from_filename ( "<STR_LIT>" , metadata = md ) <EOL> ws . add ( Foo ) <EOL> md = Metadata ( ( '<STR_LIT>' , "<STR_LIT>" ) ) <EOL> Bar = Distribution . from_filename ( "<STR_LIT>" , metadata = md ) <EOL> ws . add ( Bar ) <EOL> Baz = Distribution . from_filename ( "<STR_LIT>" ) <EOL> ws . add ( Baz ) <EOL> Baz = Distribution . from_filename ( "<STR_LIT>" ) <EOL> ws . add ( Baz ) <EOL> with pytest . raises ( VersionConflict ) as vc : <EOL> ws . resolve ( parse_requirements ( "<STR_LIT>" ) ) <EOL> msg = "<STR_LIT>" <EOL> if pkg_resources . PY2 : <EOL> msg = msg . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> assert vc . value . report ( ) == msg <EOL> class TestEntryPoints : <EOL> def assertfields ( self , ep ) : <EOL> assert ep . name == "<STR_LIT:foo>" <EOL> assert ep . module_name == "<STR_LIT>" <EOL> assert ep . attrs == ( "<STR_LIT>" , ) <EOL> assert ep . extras == ( "<STR_LIT:x>" , ) <EOL> assert ep . load ( ) is TestEntryPoints <EOL> expect = "<STR_LIT>" <EOL> assert str ( ep ) == expect <EOL> def setup_method ( self , method ) : <EOL> self . dist = Distribution . from_filename ( <EOL> "<STR_LIT>" , metadata = Metadata ( ( '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> def testBasics ( self ) : <EOL> ep = EntryPoint ( <EOL> "<STR_LIT:foo>" , "<STR_LIT>" , [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT:x>" ] , self . dist <EOL> ) <EOL> self . assertfields ( ep ) <EOL> def testParse ( self ) : <EOL> s = "<STR_LIT>" <EOL> ep = EntryPoint . parse ( s , self . dist ) <EOL> self . assertfields ( ep ) <EOL> ep = EntryPoint . parse ( "<STR_LIT>" ) <EOL> assert ep . name == "<STR_LIT>" <EOL> assert ep . module_name == "<STR_LIT>" <EOL> assert ep . attrs == ( ) <EOL> assert ep . extras == ( "<STR_LIT>" , ) <EOL> ep = EntryPoint . parse ( "<STR_LIT>" ) <EOL> assert ep . name == "<STR_LIT>" <EOL> assert ep . module_name == "<STR_LIT>" <EOL> assert ep . attrs == ( "<STR_LIT:foo>" , ) <EOL> assert ep . extras == ( ) <EOL> spec = "<STR_LIT>" <EOL> ep = EntryPoint . parse ( spec ) <EOL> assert ep . name == '<STR_LIT>' <EOL> reject_specs = "<STR_LIT:foo>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> @ pytest . mark . parametrize ( "<STR_LIT>" , reject_specs ) <EOL> def test_reject_spec ( self , reject_spec ) : <EOL> with pytest . raises ( ValueError ) : <EOL> EntryPoint . parse ( reject_spec ) <EOL> def test_printable_name ( self ) : <EOL> """<STR_LIT>""" <EOL> name = string . printable . strip ( ) <EOL> spec = "<STR_LIT>" . format ( ** locals ( ) ) <EOL> ep = EntryPoint . parse ( spec ) <EOL> assert ep . name == name <EOL> def checkSubMap ( self , m ) : <EOL> assert len ( m ) == len ( self . submap_expect ) <EOL> for key , ep in pkg_resources . iteritems ( self . submap_expect ) : <EOL> assert repr ( m . get ( key ) ) == repr ( ep ) <EOL> submap_expect = dict ( <EOL> feature1 = EntryPoint ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT>' ] ) , <EOL> feature2 = EntryPoint ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT>' ] , [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> feature3 = EntryPoint ( '<STR_LIT>' , '<STR_LIT>' , extras = [ '<STR_LIT>' ] ) <EOL> ) <EOL> submap_str = """<STR_LIT>""" <EOL> def testParseList ( self ) : <EOL> self . checkSubMap ( EntryPoint . parse_group ( "<STR_LIT>" , self . submap_str ) ) <EOL> with pytest . raises ( ValueError ) : <EOL> EntryPoint . parse_group ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> with pytest . raises ( ValueError ) : <EOL> EntryPoint . parse_group ( "<STR_LIT:x>" , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def testParseMap ( self ) : <EOL> m = EntryPoint . parse_map ( { '<STR_LIT>' : self . submap_str } ) <EOL> self . checkSubMap ( m [ '<STR_LIT>' ] ) <EOL> assert list ( m . keys ( ) ) == [ '<STR_LIT>' ] <EOL> m = EntryPoint . parse_map ( "<STR_LIT>" + self . submap_str ) <EOL> self . checkSubMap ( m [ '<STR_LIT>' ] ) <EOL> assert list ( m . keys ( ) ) == [ '<STR_LIT>' ] <EOL> with pytest . raises ( ValueError ) : <EOL> EntryPoint . parse_map ( [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> with pytest . raises ( ValueError ) : <EOL> EntryPoint . parse_map ( self . submap_str ) <EOL> class TestRequirements : <EOL> def testBasics ( self ) : <EOL> r = Requirement . parse ( "<STR_LIT>" ) <EOL> assert str ( r ) == "<STR_LIT>" <EOL> assert repr ( r ) == "<STR_LIT>" <EOL> assert r == Requirement ( "<STR_LIT>" , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] , ( ) ) <EOL> assert r == Requirement ( "<STR_LIT>" , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] , ( ) ) <EOL> assert r != Requirement ( "<STR_LIT>" , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] , ( ) ) <EOL> assert r != Requirement ( "<STR_LIT>" , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] , ( ) ) <EOL> assert r != Requirement ( "<STR_LIT>" , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] , ( ) ) <EOL> assert r != Requirement . parse ( "<STR_LIT>" ) <EOL> def testOrdering ( self ) : <EOL> r1 = Requirement ( "<STR_LIT>" , [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] , ( ) ) <EOL> r2 = Requirement ( "<STR_LIT>" , [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] , ( ) ) <EOL> assert r1 == r2 <EOL> assert str ( r1 ) == str ( r2 ) <EOL> assert str ( r2 ) == "<STR_LIT>" <EOL> def testBasicContains ( self ) : <EOL> r = Requirement ( "<STR_LIT>" , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] , ( ) ) <EOL> foo_dist = Distribution . from_filename ( "<STR_LIT>" ) <EOL> twist11 = Distribution . from_filename ( "<STR_LIT>" ) <EOL> twist12 = Distribution . from_filename ( "<STR_LIT>" ) <EOL> assert parse_version ( '<STR_LIT>' ) in r <EOL> assert parse_version ( '<STR_LIT>' ) not in r <EOL> assert '<STR_LIT>' in r <EOL> assert '<STR_LIT>' not in r <EOL> assert foo_dist not in r <EOL> assert twist11 not in r <EOL> assert twist12 in r <EOL> def testOptionsAndHashing ( self ) : <EOL> r1 = Requirement . parse ( "<STR_LIT>" ) <EOL> r2 = Requirement . parse ( "<STR_LIT>" ) <EOL> assert r1 == r2 <EOL> assert r1 . extras == ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) <EOL> assert r2 . extras == ( "<STR_LIT:bar>" , "<STR_LIT:foo>" ) <EOL> assert hash ( r1 ) == hash ( r2 ) <EOL> assert ( <EOL> hash ( r1 ) <EOL> == <EOL> hash ( ( <EOL> "<STR_LIT>" , <EOL> packaging . specifiers . SpecifierSet ( "<STR_LIT>" ) , <EOL> frozenset ( [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] ) , <EOL> ) ) <EOL> ) <EOL> def testVersionEquality ( self ) : <EOL> r1 = Requirement . parse ( "<STR_LIT>" ) <EOL> r2 = Requirement . parse ( "<STR_LIT>" ) <EOL> d = Distribution . from_filename <EOL> assert d ( "<STR_LIT>" ) not in r1 <EOL> assert d ( "<STR_LIT>" ) not in r1 <EOL> assert d ( "<STR_LIT>" ) not in r2 <EOL> assert d ( "<STR_LIT>" ) in r1 <EOL> assert d ( "<STR_LIT>" ) in r2 <EOL> assert d ( "<STR_LIT>" ) in r2 <EOL> assert d ( "<STR_LIT>" ) in r2 <EOL> def testSetuptoolsProjectName ( self ) : <EOL> """<STR_LIT>""" <EOL> assert ( <EOL> Requirement . parse ( '<STR_LIT>' ) . project_name == '<STR_LIT>' ) <EOL> assert ( <EOL> Requirement . parse ( '<STR_LIT>' ) . project_name == '<STR_LIT>' ) <EOL> assert ( <EOL> Requirement . parse ( '<STR_LIT>' ) . project_name == '<STR_LIT>' ) <EOL> assert ( <EOL> Requirement . parse ( '<STR_LIT>' ) . project_name == '<STR_LIT>' ) <EOL> class TestParsing : <EOL> def testEmptyParse ( self ) : <EOL> assert list ( parse_requirements ( '<STR_LIT>' ) ) == [ ] <EOL> def testYielding ( self ) : <EOL> for inp , out in [ <EOL> ( [ ] , [ ] ) , ( '<STR_LIT:x>' , [ '<STR_LIT:x>' ] ) , ( [ [ ] ] , [ ] ) , ( '<STR_LIT>' , [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) , <EOL> ( [ '<STR_LIT>' , '<STR_LIT:y>' ] , [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) , <EOL> ] : <EOL> assert list ( pkg_resources . yield_lines ( inp ) ) == out <EOL> def testSplitting ( self ) : <EOL> sample = """<STR_LIT>""" <EOL> assert ( <EOL> list ( pkg_resources . split_sections ( sample ) ) <EOL> == <EOL> [ <EOL> ( None , [ "<STR_LIT:x>" ] ) , <EOL> ( "<STR_LIT:Y>" , [ "<STR_LIT:z>" , "<STR_LIT:a>" ] ) , <EOL> ( "<STR_LIT:b>" , [ "<STR_LIT:c>" ] ) , <EOL> ( "<STR_LIT:d>" , [ ] ) , <EOL> ( "<STR_LIT:q>" , [ "<STR_LIT:v>" ] ) , <EOL> ] <EOL> ) <EOL> with pytest . raises ( ValueError ) : <EOL> list ( pkg_resources . split_sections ( "<STR_LIT>" ) ) <EOL> def testSafeName ( self ) : <EOL> assert safe_name ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert safe_name ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert safe_name ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert safe_name ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert safe_name ( "<STR_LIT>" ) != "<STR_LIT>" <EOL> def testSafeVersion ( self ) : <EOL> assert safe_version ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert safe_version ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert safe_version ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert safe_version ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert safe_version ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> def testSimpleRequirements ( self ) : <EOL> assert ( <EOL> list ( parse_requirements ( '<STR_LIT>' ) ) <EOL> == <EOL> [ Requirement ( '<STR_LIT>' , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] , ( ) ) ] <EOL> ) <EOL> assert ( <EOL> list ( parse_requirements ( '<STR_LIT>' ) ) <EOL> == <EOL> [ Requirement ( '<STR_LIT>' , [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT:<>' , '<STR_LIT>' ) ] , ( ) ) ] <EOL> ) <EOL> assert ( <EOL> Requirement . parse ( "<STR_LIT>" ) <EOL> == <EOL> Requirement ( "<STR_LIT>" , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] , ( ) ) <EOL> ) <EOL> with pytest . raises ( ValueError ) : <EOL> Requirement . parse ( "<STR_LIT>" ) <EOL> with pytest . raises ( ValueError ) : <EOL> Requirement . parse ( "<STR_LIT>" ) <EOL> with pytest . raises ( ValueError ) : <EOL> Requirement . parse ( "<STR_LIT>" ) <EOL> with pytest . raises ( ValueError ) : <EOL> Requirement . parse ( "<STR_LIT>" ) <EOL> with pytest . raises ( ValueError ) : <EOL> Requirement . parse ( "<STR_LIT:#>" ) <EOL> def testVersionEquality ( self ) : <EOL> def c ( s1 , s2 ) : <EOL> p1 , p2 = parse_version ( s1 ) , parse_version ( s2 ) <EOL> assert p1 == p2 , ( s1 , s2 , p1 , p2 ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def testVersionOrdering ( self ) : <EOL> def c ( s1 , s2 ) : <EOL> p1 , p2 = parse_version ( s1 ) , parse_version ( s2 ) <EOL> assert p1 < p2 , ( s1 , s2 , p1 , p2 ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> torture = """<STR_LIT>""" . split ( ) <EOL> for p , v1 in enumerate ( torture ) : <EOL> for v2 in torture [ p + <NUM_LIT:1> : ] : <EOL> c ( v2 , v1 ) <EOL> def testVersionBuildout ( self ) : <EOL> """<STR_LIT>""" <EOL> def buildout ( parsed_version ) : <EOL> _final_parts = '<STR_LIT>' , '<STR_LIT>' <EOL> def _final_version ( parsed_version ) : <EOL> for part in parsed_version : <EOL> if ( part [ : <NUM_LIT:1> ] == '<STR_LIT:*>' ) and ( part not in _final_parts ) : <EOL> return False <EOL> return True <EOL> return _final_version ( parsed_version ) <EOL> assert buildout ( parse_version ( "<STR_LIT:1.0>" ) ) <EOL> assert not buildout ( parse_version ( "<STR_LIT>" ) ) <EOL> def testVersionIndexable ( self ) : <EOL> """<STR_LIT>""" <EOL> assert parse_version ( "<STR_LIT:1.0>" ) [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> def testVersionTupleSort ( self ) : <EOL> """<STR_LIT>""" <EOL> assert parse_version ( "<STR_LIT:1.0>" ) < tuple ( parse_version ( "<STR_LIT>" ) ) <EOL> assert parse_version ( "<STR_LIT:1.0>" ) <= tuple ( parse_version ( "<STR_LIT>" ) ) <EOL> assert parse_version ( "<STR_LIT:1.0>" ) == tuple ( parse_version ( "<STR_LIT:1.0>" ) ) <EOL> assert parse_version ( "<STR_LIT>" ) > tuple ( parse_version ( "<STR_LIT>" ) ) <EOL> assert parse_version ( "<STR_LIT>" ) >= tuple ( parse_version ( "<STR_LIT>" ) ) <EOL> assert parse_version ( "<STR_LIT>" ) != tuple ( parse_version ( "<STR_LIT>" ) ) <EOL> assert not ( parse_version ( "<STR_LIT>" ) != tuple ( parse_version ( "<STR_LIT>" ) ) ) <EOL> def testVersionHashable ( self ) : <EOL> """<STR_LIT>""" <EOL> assert ( <EOL> hash ( parse_version ( "<STR_LIT:1.0>" ) ) <EOL> == <EOL> hash ( parse_version ( "<STR_LIT:1.0>" ) ) <EOL> ) <EOL> class TestNamespaces : <EOL> def setup_method ( self , method ) : <EOL> self . _ns_pkgs = pkg_resources . _namespace_packages . copy ( ) <EOL> self . _tmpdir = tempfile . mkdtemp ( prefix = "<STR_LIT>" ) <EOL> os . makedirs ( os . path . join ( self . _tmpdir , "<STR_LIT>" ) ) <EOL> self . _prev_sys_path = sys . path [ : ] <EOL> sys . path . append ( os . path . join ( self . _tmpdir , "<STR_LIT>" ) ) <EOL> def teardown_method ( self , method ) : <EOL> shutil . rmtree ( self . _tmpdir ) <EOL> pkg_resources . _namespace_packages = self . _ns_pkgs . copy ( ) <EOL> sys . path = self . _prev_sys_path [ : ] <EOL> @ pytest . mark . skipif ( os . path . islink ( tempfile . gettempdir ( ) ) , <EOL> reason = "<STR_LIT>" ) <EOL> def test_two_levels_deep ( self ) : <EOL> """<STR_LIT>""" <EOL> sys . path . append ( os . path . join ( self . _tmpdir , "<STR_LIT>" ) ) <EOL> os . makedirs ( os . path . join ( self . _tmpdir , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> os . makedirs ( os . path . join ( self . _tmpdir , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> ns_str = "<STR_LIT>" <EOL> for site in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> pkg1_init = open ( os . path . join ( self . _tmpdir , site , <EOL> "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT:w>" ) <EOL> pkg1_init . write ( ns_str ) <EOL> pkg1_init . close ( ) <EOL> pkg2_init = open ( os . path . join ( self . _tmpdir , site , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT:w>" ) <EOL> pkg2_init . write ( ns_str ) <EOL> pkg2_init . close ( ) <EOL> import pkg1 <EOL> assert "<STR_LIT>" in pkg_resources . _namespace_packages <EOL> import pkg1 . pkg2 <EOL> assert "<STR_LIT>" in pkg_resources . _namespace_packages <EOL> assert pkg_resources . _namespace_packages [ "<STR_LIT>" ] == [ "<STR_LIT>" ] <EOL> expected = [ <EOL> os . path . join ( self . _tmpdir , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> os . path . join ( self . _tmpdir , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ] <EOL> assert pkg1 . pkg2 . __path__ == expected </s>
