<s> import six <EOL> if six . PY3 : <EOL> import unittest <EOL> else : <EOL> import unittest2 as unittest <EOL> import os . path as op <EOL> from depsolver . compat import OrderedDict <EOL> from depsolver . package import PackageInfo <EOL> from depsolver . pool import Pool <EOL> from depsolver . repository import Repository <EOL> from depsolver . request import Request <EOL> from depsolver . requirement import Requirement <EOL> from depsolver . solver . rules_generator import RulesSet , RulesGenerator <EOL> from depsolver . solver . rule import PackageRule <EOL> from depsolver . solver . tests . scenarios . rules_generator import DATA , RulesGeneratorScenario <EOL> P = PackageInfo . from_string <EOL> R = Requirement . from_string <EOL> class TestPackageRule ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . mkl_10_1_0 = P ( "<STR_LIT>" ) <EOL> self . mkl_10_2_0 = P ( "<STR_LIT>" ) <EOL> self . mkl_10_3_0 = P ( "<STR_LIT>" ) <EOL> self . mkl_11_0_0 = P ( "<STR_LIT>" ) <EOL> self . numpy_1_6_0 = P ( "<STR_LIT>" ) <EOL> self . numpy_1_6_1 = P ( "<STR_LIT>" ) <EOL> self . numpy_1_7_0 = P ( "<STR_LIT>" ) <EOL> self . nomkl_numpy_1_6_0 = P ( "<STR_LIT>" ) <EOL> self . nomkl_numpy_1_6_1 = P ( "<STR_LIT>" ) <EOL> self . nomkl_numpy_1_7_0 = P ( "<STR_LIT>" ) <EOL> self . mkl_numpy_1_6_1 = P ( "<STR_LIT>" ) <EOL> self . mkl_numpy_1_7_0 = P ( "<STR_LIT>" ) <EOL> self . scipy_0_11_0 = P ( "<STR_LIT>" ) <EOL> self . scipy_0_12_0 = P ( "<STR_LIT>" ) <EOL> self . matplotlib_1_2_0 = P ( "<STR_LIT>" ) <EOL> repo = Repository ( [ self . mkl_10_1_0 , self . mkl_10_2_0 , self . mkl_10_3_0 , <EOL> self . mkl_11_0_0 , self . numpy_1_6_0 ] ) <EOL> pool = Pool ( ) <EOL> pool . add_repository ( repo ) <EOL> self . pool = pool <EOL> def test_str ( self ) : <EOL> rule = PackageRule . from_packages ( self . pool , [ self . mkl_11_0_0 , <EOL> self . mkl_10_1_0 , self . mkl_10_2_0 ] , None ) <EOL> rule_repr = str ( rule ) <EOL> self . assertEqual ( rule_repr , "<STR_LIT>" ) <EOL> rule_repr = str ( PackageRule ( self . pool , [ - self . mkl_10_2_0 . id , self . mkl_11_0_0 . id ] , None ) ) <EOL> self . assertEqual ( rule_repr , "<STR_LIT>" ) <EOL> def test_from_package_string ( self ) : <EOL> r_rule = PackageRule . from_packages ( self . pool , [ self . mkl_11_0_0 ] , None ) <EOL> rule = PackageRule . from_string ( self . pool , "<STR_LIT>" , None ) <EOL> self . assertTrue ( rule . is_equivalent ( r_rule ) ) <EOL> r_rule = PackageRule . from_packages ( self . pool , [ self . mkl_10_2_0 , self . mkl_11_0_0 ] , None ) <EOL> rule = PackageRule . from_string ( self . pool , "<STR_LIT>" , None ) <EOL> self . assertTrue ( rule . is_equivalent ( r_rule ) ) <EOL> r_rule = PackageRule ( self . pool , [ - self . mkl_10_2_0 . id , self . mkl_11_0_0 . id ] , None ) <EOL> rule = PackageRule . from_string ( self . pool , "<STR_LIT>" , None ) <EOL> self . assertTrue ( rule . is_equivalent ( r_rule ) ) <EOL> r_rule = PackageRule ( self . pool , [ - self . mkl_10_2_0 . id , - self . mkl_11_0_0 . id ] , None ) <EOL> rule = PackageRule . from_string ( self . pool , "<STR_LIT>" , None ) <EOL> self . assertTrue ( rule . is_equivalent ( r_rule ) ) <EOL> class TestCreateClauses ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . mkl_10_1_0 = P ( "<STR_LIT>" ) <EOL> self . mkl_10_2_0 = P ( "<STR_LIT>" ) <EOL> self . mkl_10_3_0 = P ( "<STR_LIT>" ) <EOL> self . mkl_11_0_0 = P ( "<STR_LIT>" ) <EOL> self . numpy_1_6_0 = P ( "<STR_LIT>" ) <EOL> repo = Repository ( [ self . mkl_10_1_0 , self . mkl_10_2_0 , self . mkl_10_3_0 , <EOL> self . mkl_11_0_0 , self . numpy_1_6_0 ] ) <EOL> pool = Pool ( ) <EOL> pool . add_repository ( repo ) <EOL> self . pool = pool <EOL> def test_create_depends_rule ( self ) : <EOL> r_rule = PackageRule . from_string ( self . pool , <EOL> "<STR_LIT>" , <EOL> None ) <EOL> req = R ( "<STR_LIT>" ) <EOL> request = Request ( self . pool ) <EOL> request . install ( req ) <EOL> rules_generator = RulesGenerator ( self . pool , request , OrderedDict ( ) ) <EOL> dependencies = self . pool . what_provides ( self . numpy_1_6_0 . dependencies [ <NUM_LIT:0> ] ) <EOL> rule = rules_generator . _create_dependency_rule ( self . numpy_1_6_0 , dependencies , None ) <EOL> self . assertTrue ( rule . is_equivalent ( r_rule ) ) <EOL> @ unittest . expectedFailure <EOL> def test_iter_conflict_rules ( self ) : <EOL> self . assertEqual ( set ( ) , set ( iter_conflict_rules ( self . pool , [ mkl_10_1_0 ] ) ) ) <EOL> r_rules = set ( ) <EOL> r_rules . add ( PackageRule . from_string ( "<STR_LIT>" , self . pool ) ) <EOL> r_rules . add ( PackageRule . from_string ( "<STR_LIT>" , self . pool ) ) <EOL> r_rules . add ( PackageRule . from_string ( "<STR_LIT>" , self . pool ) ) <EOL> self . assertEqual ( r_rules , <EOL> set ( iter_conflict_rules ( self . pool , [ mkl_10_1_0 , mkl_10_2_0 , mkl_10_3_0 ] ) ) ) <EOL> class TestRulesSet ( unittest . TestCase ) : <EOL> def test_simple ( self ) : <EOL> repository = Repository ( [ P ( "<STR_LIT>" ) , <EOL> P ( "<STR_LIT>" ) , <EOL> P ( "<STR_LIT>" ) ] ) <EOL> pool = Pool ( [ repository ] ) <EOL> rule = PackageRule ( pool , [ <NUM_LIT:1> , <NUM_LIT:2> ] , "<STR_LIT>" , "<STR_LIT>" ) <EOL> rules_set = RulesSet ( ) <EOL> rules_set . add_rule ( rule , "<STR_LIT>" ) <EOL> self . assertEqual ( len ( rules_set ) , <NUM_LIT:1> ) <EOL> class TestRulesGeneratorScenarios ( unittest . TestCase ) : <EOL> def _compute_rules ( self , scenario_description ) : <EOL> filename = op . join ( DATA , scenario_description ) <EOL> fp = open ( op . join ( DATA , op . splitext ( scenario_description ) [ <NUM_LIT:0> ] + "<STR_LIT>" ) ) <EOL> try : <EOL> r_rules = [ line . rstrip ( ) for line in fp ] <EOL> finally : <EOL> fp . close ( ) <EOL> scenario = RulesGeneratorScenario . from_yaml ( filename ) <EOL> rules = [ str ( r ) for r in scenario . compute_rules ( ) ] <EOL> self . assertEqual ( r_rules , rules ) <EOL> def test_buggy_scenario ( self ) : <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) <EOL> def test_complex_scenario1 ( self ) : <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) <EOL> def test_complex_scenario2 ( self ) : <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) <EOL> def test_conflict_scenario1 ( self ) : <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) <EOL> def test_multiple_provides_4_candidates ( self ) : <EOL> """<STR_LIT>""" <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) <EOL> def test_multiple_provides_numpy ( self ) : <EOL> """<STR_LIT>""" <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) <EOL> def test_multiple_provides_single_fulfilled_provides ( self ) : <EOL> """<STR_LIT>""" <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) <EOL> def test_multiple_provides_simple ( self ) : <EOL> """<STR_LIT>""" <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) <EOL> def test_already_installed_indirect_provided ( self ) : <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) <EOL> def test_replace_scenario1 ( self ) : <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) <EOL> def test_replace_scenario2 ( self ) : <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) <EOL> def test_single_dependency_simple ( self ) : <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) <EOL> def test_single_dependency_installed_simple ( self ) : <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) <EOL> def test_single_dependency_multiple_provides ( self ) : <EOL> scenario = "<STR_LIT>" <EOL> self . _compute_rules ( scenario ) </s>
