<s> import os <EOL> import pytest <EOL> from twitter . common . contextutil import temporary_dir <EOL> from pex . common import safe_copy <EOL> from pex . fetcher import Fetcher <EOL> from pex . package import EggPackage , SourcePackage <EOL> from pex . resolvable import ResolvableRequirement <EOL> from pex . resolver import Unsatisfiable , _ResolvableSet , resolve <EOL> from pex . resolver_options import ResolverOptionsBuilder <EOL> from pex . testing import make_sdist <EOL> def test_empty_resolve ( ) : <EOL> empty_resolve = resolve ( [ ] ) <EOL> assert empty_resolve == [ ] <EOL> with temporary_dir ( ) as td : <EOL> empty_resolve = resolve ( [ ] , cache = td ) <EOL> assert empty_resolve == [ ] <EOL> def test_simple_local_resolve ( ) : <EOL> project_sdist = make_sdist ( name = '<STR_LIT>' ) <EOL> with temporary_dir ( ) as td : <EOL> safe_copy ( project_sdist , os . path . join ( td , os . path . basename ( project_sdist ) ) ) <EOL> fetchers = [ Fetcher ( [ td ] ) ] <EOL> dists = resolve ( [ '<STR_LIT>' ] , fetchers = fetchers ) <EOL> assert len ( dists ) == <NUM_LIT:1> <EOL> def test_diamond_local_resolve_cached ( ) : <EOL> project1_sdist = make_sdist ( name = '<STR_LIT>' , install_reqs = [ '<STR_LIT>' ] ) <EOL> project2_sdist = make_sdist ( name = '<STR_LIT>' ) <EOL> with temporary_dir ( ) as dd : <EOL> for sdist in ( project1_sdist , project2_sdist ) : <EOL> safe_copy ( sdist , os . path . join ( dd , os . path . basename ( sdist ) ) ) <EOL> fetchers = [ Fetcher ( [ dd ] ) ] <EOL> with temporary_dir ( ) as cd : <EOL> dists = resolve ( [ '<STR_LIT>' , '<STR_LIT>' ] , fetchers = fetchers , cache = cd , cache_ttl = <NUM_LIT:1000> ) <EOL> assert len ( dists ) == <NUM_LIT:2> <EOL> def test_resolvable_set ( ) : <EOL> builder = ResolverOptionsBuilder ( ) <EOL> rs = _ResolvableSet ( ) <EOL> rq = ResolvableRequirement . from_string ( '<STR_LIT>' , builder ) <EOL> source_pkg = SourcePackage . from_href ( '<STR_LIT>' ) <EOL> binary_pkg = EggPackage . from_href ( '<STR_LIT>' ) <EOL> rs . merge ( rq , [ source_pkg , binary_pkg ] ) <EOL> assert rs . get ( source_pkg . name ) == set ( [ source_pkg , binary_pkg ] ) <EOL> assert rs . get ( binary_pkg . name ) == set ( [ source_pkg , binary_pkg ] ) <EOL> assert rs . packages ( ) == [ ( rq , set ( [ source_pkg , binary_pkg ] ) , None ) ] <EOL> assert rs . extras ( '<STR_LIT:foo>' ) == set ( [ '<STR_LIT>' ] ) <EOL> assert rs . extras ( '<STR_LIT>' ) == set ( [ '<STR_LIT>' ] ) <EOL> rs . merge ( rq , [ source_pkg ] ) <EOL> assert rs . get ( '<STR_LIT:foo>' ) == set ( [ source_pkg ] ) <EOL> assert rs . get ( '<STR_LIT>' ) == set ( [ source_pkg ] ) <EOL> with pytest . raises ( Unsatisfiable ) : <EOL> rs . merge ( rq , [ binary_pkg ] ) <EOL> def test_resolvable_set_built ( ) : <EOL> builder = ResolverOptionsBuilder ( ) <EOL> rs = _ResolvableSet ( ) <EOL> rq = ResolvableRequirement . from_string ( '<STR_LIT:foo>' , builder ) <EOL> source_pkg = SourcePackage . from_href ( '<STR_LIT>' ) <EOL> binary_pkg = EggPackage . from_href ( '<STR_LIT>' ) <EOL> rs . merge ( rq , [ source_pkg ] ) <EOL> assert rs . get ( '<STR_LIT:foo>' ) == set ( [ source_pkg ] ) <EOL> assert rs . packages ( ) == [ ( rq , set ( [ source_pkg ] ) , None ) ] <EOL> with pytest . raises ( Unsatisfiable ) : <EOL> rs . merge ( rq , [ binary_pkg ] ) <EOL> updated_rs = rs . replace_built ( { source_pkg : binary_pkg } ) <EOL> updated_rs . merge ( rq , [ binary_pkg ] ) <EOL> assert updated_rs . get ( '<STR_LIT:foo>' ) == set ( [ binary_pkg ] ) <EOL> assert updated_rs . packages ( ) == [ ( rq , set ( [ binary_pkg ] ) , None ) ] </s>
