<s> from testrunner import testhelp <EOL> from conary_test import rephelp <EOL> from conary . local import database <EOL> from conary . deps import deps <EOL> from conary . deps . deps import Flavor <EOL> from conary . deps . deps import parseDep <EOL> from conary import trove <EOL> from conary import versions <EOL> from conary . repository import changeset <EOL> from conary . repository import trovesource <EOL> class DepTableTest ( testhelp . TestCase ) : <EOL> new = versions . NewVersion ( ) <EOL> flv = Flavor ( ) <EOL> def _fixupVersion ( self , version ) : <EOL> if version is None : <EOL> return versions . NewVersion ( ) <EOL> else : <EOL> assert ( isinstance ( version , str ) ) <EOL> return versions . ThawVersion ( "<STR_LIT>" + "<STR_LIT>" + <EOL> version ) <EOL> def reqTrove ( self , troveName , depSet , version = None ) : <EOL> version = self . _fixupVersion ( version ) <EOL> trv = trove . Trove ( troveName , version , Flavor ( ) , None ) <EOL> trv . setRequires ( depSet ) <EOL> return trv <EOL> def prvTrove ( self , troveName , depSet , version = None ) : <EOL> version = self . _fixupVersion ( version ) <EOL> trv = trove . Trove ( troveName , version , Flavor ( ) , None ) <EOL> trv . setProvides ( depSet ) <EOL> return trv <EOL> def prvReqTrove ( self , troveName , prvDepSet , reqDepSet , version = None ) : <EOL> trv = self . prvTrove ( troveName , prvDepSet , version = version ) <EOL> trv . setRequires ( reqDepSet ) <EOL> return trv <EOL> def createJobInfo ( self , db , * troves ) : <EOL> cs = changeset . ChangeSet ( ) <EOL> jobs = [ ] <EOL> for trvInfo in troves : <EOL> if isinstance ( trvInfo , tuple ) : <EOL> oldTrv , newTrv = trvInfo <EOL> else : <EOL> newTrv = trvInfo <EOL> oldTrv = None <EOL> if newTrv is not None : <EOL> trvCs = newTrv . diff ( oldTrv , absolute = False ) [ <NUM_LIT:0> ] <EOL> cs . newTrove ( trvCs ) <EOL> jobs . append ( ( trvCs . getName ( ) , <EOL> ( trvCs . getOldVersion ( ) , trvCs . getOldFlavor ( ) ) , <EOL> ( trvCs . getNewVersion ( ) , trvCs . getNewFlavor ( ) ) , <EOL> False ) ) <EOL> else : <EOL> cs . oldTrove ( oldTrv . getName ( ) , oldTrv . getVersion ( ) , <EOL> oldTrv . getFlavor ( ) ) <EOL> jobs . append ( ( oldTrv . getName ( ) , <EOL> ( oldTrv . getVersion ( ) , oldTrv . getFlavor ( ) ) , <EOL> ( None , None ) , <EOL> False ) ) <EOL> src = trovesource . ChangesetFilesTroveSource ( db ) <EOL> src . addChangeSet ( cs ) <EOL> return ( db . db , jobs , src ) <EOL> def init ( self ) : <EOL> db = database . Database ( None , '<STR_LIT>' ) <EOL> dt = db . db . depTables <EOL> db . commit ( ) <EOL> cu = db . db . db . cursor ( ) <EOL> return dt , db , cu <EOL> def check ( self , db , jobSet , troveSource , findOrdering = False ) : <EOL> checker = db . dependencyChecker ( troveSource , findOrdering = findOrdering ) <EOL> checker . addJobs ( jobSet ) <EOL> result = checker . check ( ) <EOL> checker . done ( ) <EOL> return ( result . unsatisfiedList , result . unresolveableList , <EOL> result . getChangeSetList ( ) ) <EOL> def testSimpleResolution ( self ) : <EOL> dt , db , cu = self . init ( ) <EOL> dep = parseDep ( "<STR_LIT>" ) <EOL> jobInfo = self . createJobInfo ( db , self . reqTrove ( "<STR_LIT:test>" , dep ) ) <EOL> assert ( self . check ( * jobInfo ) [ <NUM_LIT:0> : <NUM_LIT:2> ] == ( [ <EOL> ( ( "<STR_LIT:test>" , self . new , self . flv ) , dep ) ] , [ ] ) ) <EOL> dt . add ( cu , self . prvTrove ( "<STR_LIT>" , dep ) , <NUM_LIT:1> ) <EOL> db . commit ( ) <EOL> assert ( self . check ( * jobInfo ) [ <NUM_LIT:0> : <NUM_LIT:2> ] == ( [ ] , [ ] ) ) <EOL> dt , db , cu = self . init ( ) <EOL> jobInfo = self . createJobInfo ( db , self . reqTrove ( "<STR_LIT:test>" , dep ) , <EOL> self . prvTrove ( "<STR_LIT>" , dep ) ) <EOL> assert ( self . check ( * jobInfo ) [ <NUM_LIT:0> : <NUM_LIT:2> ] == ( [ ] , [ ] ) ) <EOL> def testFlagSets ( self ) : <EOL> dt , db , cu = self . init ( ) <EOL> dep = parseDep ( <EOL> "<STR_LIT>" ) <EOL> jobInfo = self . createJobInfo ( db , self . reqTrove ( "<STR_LIT:test>" , dep ) ) <EOL> assert ( self . check ( * jobInfo ) [ <NUM_LIT:0> : <NUM_LIT:2> ] == ( [ <EOL> ( ( "<STR_LIT:test>" , self . new , self . flv ) , dep ) ] , [ ] ) ) <EOL> prv1 = parseDep ( "<STR_LIT>" ) <EOL> prv2 = parseDep ( "<STR_LIT>" ) <EOL> prv3 = parseDep ( "<STR_LIT>" ) <EOL> dt . add ( cu , self . prvTrove ( "<STR_LIT>" , prv1 ) , <NUM_LIT:1> ) <EOL> dt . add ( cu , self . prvTrove ( "<STR_LIT>" , prv2 ) , <NUM_LIT:2> ) <EOL> dt . add ( cu , self . prvTrove ( "<STR_LIT>" , prv3 ) , <NUM_LIT:3> ) <EOL> db . commit ( ) <EOL> assert ( self . check ( * jobInfo ) [ <NUM_LIT:0> : <NUM_LIT:2> ] == ( [ <EOL> ( ( "<STR_LIT:test>" , self . new , self . flv ) , dep ) ] , [ ] ) ) <EOL> prv = parseDep ( <EOL> "<STR_LIT>" ) <EOL> dt . add ( cu , self . prvTrove ( "<STR_LIT>" , prv ) , <NUM_LIT:4> ) <EOL> db . commit ( ) <EOL> assert ( self . check ( * jobInfo ) [ <NUM_LIT:0> : <NUM_LIT:2> ] == ( [ ] , [ ] ) ) <EOL> def testInfoOrdering ( self ) : <EOL> dt , db , cu = self . init ( ) <EOL> jobInfo = self . createJobInfo ( db , <EOL> self . prvReqTrove ( "<STR_LIT>" , <EOL> parseDep ( "<STR_LIT>" ) , <EOL> parseDep ( "<STR_LIT>" ) ) , <EOL> self . prvTrove ( "<STR_LIT>" , <EOL> parseDep ( "<STR_LIT>" ) ) , <EOL> self . reqTrove ( "<STR_LIT:test>" , <EOL> parseDep ( "<STR_LIT>" ) ) <EOL> ) <EOL> resolvedOrder = self . check ( findOrdering = True , * jobInfo ) [ <NUM_LIT:2> ] <EOL> order = [ [ y [ <NUM_LIT:0> ] for y in x ] for x in resolvedOrder ] <EOL> assert ( order == [ [ '<STR_LIT>' ] , [ '<STR_LIT>' ] , [ '<STR_LIT:test>' ] ] ) <EOL> def testIterativeOrdering ( self ) : <EOL> """<STR_LIT>""" <EOL> dt , db , cu = self . init ( ) <EOL> dep1 = parseDep ( '<STR_LIT>' ) <EOL> dep2 = parseDep ( '<STR_LIT>' ) <EOL> dep3 = parseDep ( '<STR_LIT>' ) <EOL> trv1reqs = deps . DependencySet ( ) <EOL> trv1reqs . union ( dep2 ) <EOL> trv1reqs . union ( dep3 ) <EOL> trv1 = self . prvReqTrove ( '<STR_LIT>' , dep1 , trv1reqs ) <EOL> trv2 = self . prvReqTrove ( '<STR_LIT>' , dep2 , dep1 ) <EOL> trv3 = self . prvTrove ( '<STR_LIT>' , dep3 ) <EOL> _ , job12 , src = self . createJobInfo ( db , trv1 , trv2 ) <EOL> _ , job3 , src3 = self . createJobInfo ( db , trv3 ) <EOL> src . addChangeSets ( src3 . csList ) <EOL> checker = db . db . dependencyChecker ( src , findOrdering = True ) <EOL> checker . addJobs ( job12 ) <EOL> result = checker . check ( ) <EOL> self . assertEqual ( result . unsatisfiedList , <EOL> [ ( ( '<STR_LIT>' , self . new , self . flv ) , dep3 ) ] ) <EOL> checker . addJobs ( job3 ) <EOL> result = checker . check ( ) <EOL> self . assertEqual ( result . unsatisfiedList , [ ] ) <EOL> checker . done ( ) <EOL> self . assertEqual ( result . getChangeSetList ( ) , [ job3 , job12 ] ) <EOL> def testSelf ( self ) : <EOL> dt , db , cu = self . init ( ) <EOL> dep = parseDep ( "<STR_LIT>" ) <EOL> jobInfo = self . createJobInfo ( db , self . reqTrove ( "<STR_LIT:test>" , dep ) ) <EOL> assert ( self . check ( * jobInfo ) [ <NUM_LIT:1> : <NUM_LIT:4> ] == ( [ ] , [ ] ) ) <EOL> def testOldNeedsNew ( self ) : <EOL> dt , db , cu = self . init ( ) <EOL> prv1 = parseDep ( "<STR_LIT>" ) <EOL> prv2 = parseDep ( "<STR_LIT>" ) <EOL> prvTrv1 = self . prvTrove ( "<STR_LIT>" , prv1 , version = "<STR_LIT>" ) <EOL> reqTrv1 = self . reqTrove ( "<STR_LIT>" , prv1 , version = "<STR_LIT>" ) <EOL> troveInfo = db . addTrove ( prvTrv1 ) <EOL> db . addTroveDone ( troveInfo ) <EOL> troveInfo = db . addTrove ( reqTrv1 ) <EOL> db . addTroveDone ( troveInfo ) <EOL> db . commit ( ) <EOL> prvTrv2 = self . prvTrove ( "<STR_LIT>" , prv2 , version = "<STR_LIT>" ) <EOL> reqTrv2 = self . reqTrove ( "<STR_LIT>" , prv2 , version = "<STR_LIT>" ) <EOL> jobInfo = self . createJobInfo ( db , <EOL> ( prvTrv1 , prvTrv2 ) , ( reqTrv1 , reqTrv2 ) ) <EOL> order = self . check ( findOrdering = True , * jobInfo ) [ <NUM_LIT:2> ] <EOL> assert ( len ( order ) == <NUM_LIT:1> ) <EOL> def testOutsiderNeedsOldAndNew ( self ) : <EOL> dt , db , cu = self . init ( ) <EOL> dep = parseDep ( "<STR_LIT>" ) <EOL> reqTrv1 = self . reqTrove ( "<STR_LIT>" , dep , version = "<STR_LIT>" ) <EOL> prvTrv1 = self . prvTrove ( "<STR_LIT>" , dep , version = "<STR_LIT>" ) <EOL> prvTrv2 = self . prvTrove ( "<STR_LIT>" , dep , version = "<STR_LIT>" ) <EOL> troveInfo = db . addTrove ( prvTrv1 ) <EOL> db . addTroveDone ( troveInfo ) <EOL> troveInfo = db . addTrove ( reqTrv1 ) <EOL> db . addTroveDone ( troveInfo ) <EOL> db . commit ( ) <EOL> jobInfo = self . createJobInfo ( db , ( prvTrv1 , None ) , ( None , prvTrv2 ) ) <EOL> ( broken , byErase , order ) = self . check ( findOrdering = True , * jobInfo ) <EOL> assert ( not broken and not byErase ) <EOL> assert ( len ( order ) == <NUM_LIT:1> ) <EOL> class DepTableTestWithHelper ( rephelp . RepositoryHelper ) : <EOL> def testGetLocalProvides ( self ) : <EOL> db = self . openDatabase ( ) <EOL> baz = self . addDbComponent ( db , '<STR_LIT>' , '<STR_LIT:1>' , '<STR_LIT>' , <EOL> provides = parseDep ( '<STR_LIT>' ) ) <EOL> foo2 = self . addDbComponent ( db , '<STR_LIT>' , '<STR_LIT:2>' , '<STR_LIT>' , <EOL> provides = parseDep ( '<STR_LIT>' ) , <EOL> requires = parseDep ( '<STR_LIT>' ) ) <EOL> foo1 = self . addDbComponent ( db , '<STR_LIT>' , '<STR_LIT:1>' , '<STR_LIT>' , <EOL> provides = parseDep ( '<STR_LIT>' ) , <EOL> requires = parseDep ( '<STR_LIT>' ) ) <EOL> bar = self . addDbComponent ( db , '<STR_LIT>' , '<STR_LIT:1>' , '<STR_LIT>' , <EOL> provides = parseDep ( '<STR_LIT>' ) , <EOL> requires = parseDep ( '<STR_LIT>' ) ) <EOL> bam = self . addDbComponent ( db , '<STR_LIT>' , '<STR_LIT:1>' , '<STR_LIT>' , <EOL> provides = parseDep ( '<STR_LIT>' ) , <EOL> requires = parseDep ( '<STR_LIT>' ) ) <EOL> depSet = parseDep ( '<STR_LIT>' ) <EOL> sols = db . getTrovesWithProvides ( [ depSet ] , True ) <EOL> assert ( sols [ depSet ] == [ [ bam . getNameVersionFlavor ( ) ] , <EOL> [ bar . getNameVersionFlavor ( ) ] ] ) <EOL> def testUnknownDepTag ( self ) : <EOL> db = self . openDatabase ( ) <EOL> intTag = <NUM_LIT> <EOL> stringTag = "<STR_LIT>" <EOL> class YetToBeDefinedDependency ( deps . DependencyClass ) : <EOL> tag = intTag <EOL> tagName = stringTag <EOL> justOne = False <EOL> depClass = deps . Dependency <EOL> ds = deps . DependencySet ( ) <EOL> depName = "<STR_LIT>" <EOL> depFlag = "<STR_LIT>" <EOL> ds . addDep ( YetToBeDefinedDependency , deps . Dependency ( depName , <EOL> [ ( depFlag , deps . FLAG_SENSE_REQUIRED ) ] ) ) <EOL> bam = self . addDbComponent ( db , '<STR_LIT>' , '<STR_LIT:1>' , '<STR_LIT>' , <EOL> provides = ds , <EOL> requires = ds ) <EOL> bam2 = db . getTrove ( bam . name ( ) , bam . version ( ) , bam . flavor ( ) ) <EOL> self . assertEqual ( bam . requires . freeze ( ) , bam2 . requires . freeze ( ) ) <EOL> self . assertEqual ( bam . provides . freeze ( ) , bam2 . provides . freeze ( ) ) </s>
