<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> from collections import OrderedDict <EOL> from contextlib import contextmanager <EOL> from textwrap import dedent <EOL> from mock import Mock <EOL> from twitter . common . collections import OrderedSet <EOL> from twitter . common . dirutil . chroot import Chroot <EOL> from pants . backend . codegen . targets . python_antlr_library import PythonAntlrLibrary <EOL> from pants . backend . codegen . targets . python_thrift_library import PythonThriftLibrary <EOL> from pants . backend . jvm . subsystems . jvm import JVM <EOL> from pants . backend . python . python_artifact import PythonArtifact <EOL> from pants . backend . python . tasks . setup_py import SetupPy <EOL> from pants . base . exceptions import TaskError <EOL> from pants . build_graph . build_file_aliases import BuildFileAliases <EOL> from pants . build_graph . resources import Resources <EOL> from pants . fs . archive import TGZ <EOL> from pants . util . contextutil import temporary_dir , temporary_file <EOL> from pants . util . dirutil import safe_mkdir <EOL> from pants_test . backend . python . tasks . python_task_test_base import PythonTaskTestBase <EOL> from pants_test . subsystem . subsystem_util import subsystem_instance <EOL> class TestSetupPy ( PythonTaskTestBase ) : <EOL> @ classmethod <EOL> def task_type ( cls ) : <EOL> return SetupPy <EOL> def setUp ( self ) : <EOL> super ( TestSetupPy , self ) . setUp ( ) <EOL> distdir = os . path . join ( self . build_root , '<STR_LIT>' ) <EOL> self . set_options ( pants_distdir = distdir ) <EOL> self . dependency_calculator = SetupPy . DependencyCalculator ( self . build_graph ) <EOL> @ property <EOL> def alias_groups ( self ) : <EOL> resources = BuildFileAliases ( targets = { '<STR_LIT>' : Resources } ) <EOL> return super ( TestSetupPy , self ) . alias_groups . merge ( resources ) <EOL> def create_dependencies ( self , depmap ) : <EOL> target_map = { } <EOL> for name , deps in depmap . items ( ) : <EOL> target_map [ name ] = self . create_python_library ( <EOL> relpath = name , <EOL> name = name , <EOL> provides = '<STR_LIT>' . format ( name = name ) <EOL> ) <EOL> for name , deps in depmap . items ( ) : <EOL> target = target_map [ name ] <EOL> dep_targets = [ target_map [ name ] for name in deps ] <EOL> for dep in dep_targets : <EOL> self . build_graph . inject_dependency ( target . address , dep . address ) <EOL> return target_map <EOL> def assert_requirements ( self , target , expected ) : <EOL> reduced_dependencies = self . dependency_calculator . reduced_dependencies ( target ) <EOL> self . assertEqual ( SetupPy . install_requires ( reduced_dependencies ) , expected ) <EOL> def test_reduced_dependencies_1 ( self ) : <EOL> dep_map = OrderedDict ( foo = [ '<STR_LIT:bar>' ] , bar = [ '<STR_LIT>' ] , baz = [ ] ) <EOL> target_map = self . create_dependencies ( dep_map ) <EOL> self . assertEqual ( self . dependency_calculator . reduced_dependencies ( target_map [ '<STR_LIT:foo>' ] ) , <EOL> OrderedSet ( [ target_map [ '<STR_LIT:bar>' ] ] ) ) <EOL> self . assertEqual ( self . dependency_calculator . reduced_dependencies ( target_map [ '<STR_LIT:bar>' ] ) , <EOL> OrderedSet ( [ target_map [ '<STR_LIT>' ] ] ) ) <EOL> self . assertEqual ( self . dependency_calculator . reduced_dependencies ( target_map [ '<STR_LIT>' ] ) , <EOL> OrderedSet ( ) ) <EOL> self . assert_requirements ( target_map [ '<STR_LIT:foo>' ] , { '<STR_LIT>' } ) <EOL> self . assert_requirements ( target_map [ '<STR_LIT:bar>' ] , { '<STR_LIT>' } ) <EOL> self . assert_requirements ( target_map [ '<STR_LIT>' ] , set ( ) ) <EOL> @ contextmanager <EOL> def run_execute ( self , target , recursive = False ) : <EOL> self . set_options ( recursive = recursive ) <EOL> context = self . context ( target_roots = [ target ] ) <EOL> setup_py = self . create_task ( context ) <EOL> yield setup_py . execute ( ) <EOL> def test_execution_reduced_dependencies_1 ( self ) : <EOL> dep_map = OrderedDict ( foo = [ '<STR_LIT:bar>' ] , bar = [ '<STR_LIT>' ] , baz = [ ] ) <EOL> target_map = self . create_dependencies ( dep_map ) <EOL> with self . run_execute ( target_map [ '<STR_LIT:foo>' ] , recursive = False ) as created : <EOL> self . assertEqual ( [ target_map [ '<STR_LIT:foo>' ] ] , created . keys ( ) ) <EOL> with self . run_execute ( target_map [ '<STR_LIT:foo>' ] , recursive = True ) as created : <EOL> self . assertEqual ( { target_map [ '<STR_LIT>' ] , target_map [ '<STR_LIT:bar>' ] , target_map [ '<STR_LIT:foo>' ] } , <EOL> set ( created . keys ( ) ) ) <EOL> def test_reduced_dependencies_2 ( self ) : <EOL> dep_map = OrderedDict ( foo = [ '<STR_LIT:bar>' , '<STR_LIT>' ] , bar = [ '<STR_LIT>' ] , baz = [ ] ) <EOL> target_map = self . create_dependencies ( dep_map ) <EOL> self . assertEqual ( self . dependency_calculator . reduced_dependencies ( target_map [ '<STR_LIT:foo>' ] ) , <EOL> OrderedSet ( [ target_map [ '<STR_LIT:bar>' ] , target_map [ '<STR_LIT>' ] ] ) ) <EOL> self . assertEqual ( self . dependency_calculator . reduced_dependencies ( target_map [ '<STR_LIT:bar>' ] ) , <EOL> OrderedSet ( [ target_map [ '<STR_LIT>' ] ] ) ) <EOL> self . assertEqual ( self . dependency_calculator . reduced_dependencies ( target_map [ '<STR_LIT>' ] ) , <EOL> OrderedSet ( ) ) <EOL> def test_reduced_dependencies_diamond ( self ) : <EOL> dep_map = OrderedDict ( foo = [ '<STR_LIT:bar>' , '<STR_LIT>' ] , bar = [ '<STR_LIT>' ] , baz = [ '<STR_LIT>' ] , bak = [ ] ) <EOL> target_map = self . create_dependencies ( dep_map ) <EOL> self . assertEqual ( self . dependency_calculator . reduced_dependencies ( target_map [ '<STR_LIT:foo>' ] ) , <EOL> OrderedSet ( [ target_map [ '<STR_LIT:bar>' ] , target_map [ '<STR_LIT>' ] ] ) ) <EOL> self . assertEqual ( self . dependency_calculator . reduced_dependencies ( target_map [ '<STR_LIT:bar>' ] ) , <EOL> OrderedSet ( [ target_map [ '<STR_LIT>' ] ] ) ) <EOL> self . assertEqual ( self . dependency_calculator . reduced_dependencies ( target_map [ '<STR_LIT>' ] ) , <EOL> OrderedSet ( [ target_map [ '<STR_LIT>' ] ] ) ) <EOL> self . assert_requirements ( target_map [ '<STR_LIT:foo>' ] , { '<STR_LIT>' , '<STR_LIT>' } ) <EOL> self . assert_requirements ( target_map [ '<STR_LIT:bar>' ] , { '<STR_LIT>' } ) <EOL> self . assert_requirements ( target_map [ '<STR_LIT>' ] , { '<STR_LIT>' } ) <EOL> def test_binary_target_injected_into_reduced_dependencies ( self ) : <EOL> foo_bin_dep = self . create_python_library ( relpath = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> foo_bin = self . create_python_binary ( <EOL> relpath = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> entry_point = '<STR_LIT>' , <EOL> dependencies = [ <EOL> '<STR_LIT>' , <EOL> ] <EOL> ) <EOL> foo = self . create_python_library ( <EOL> relpath = '<STR_LIT:foo>' , <EOL> name = '<STR_LIT:foo>' , <EOL> provides = dedent ( """<STR_LIT>""" ) <EOL> ) <EOL> self . assertEqual ( self . dependency_calculator . reduced_dependencies ( foo ) , <EOL> OrderedSet ( [ foo_bin , foo_bin_dep ] ) ) <EOL> entry_points = dict ( SetupPy . iter_entry_points ( foo ) ) <EOL> self . assertEqual ( entry_points , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> with self . run_execute ( foo , recursive = False ) as created : <EOL> self . assertEqual ( [ foo ] , created . keys ( ) ) <EOL> with self . run_execute ( foo , recursive = True ) as created : <EOL> self . assertEqual ( [ foo ] , created . keys ( ) ) <EOL> def test_binary_target_injected_into_reduced_dependencies_with_provider ( self ) : <EOL> bar_bin_dep = self . create_python_library ( <EOL> relpath = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> provides = dedent ( """<STR_LIT>""" ) <EOL> ) <EOL> bar_bin = self . create_python_binary ( <EOL> relpath = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> entry_point = '<STR_LIT>' , <EOL> dependencies = [ <EOL> '<STR_LIT>' <EOL> ] , <EOL> ) <EOL> bar = self . create_python_library ( <EOL> relpath = '<STR_LIT:bar>' , <EOL> name = '<STR_LIT:bar>' , <EOL> provides = dedent ( """<STR_LIT>""" ) <EOL> ) <EOL> self . assertEqual ( self . dependency_calculator . reduced_dependencies ( bar ) , <EOL> OrderedSet ( [ bar_bin , bar_bin_dep ] ) ) <EOL> self . assert_requirements ( bar , { '<STR_LIT>' } ) <EOL> entry_points = dict ( SetupPy . iter_entry_points ( bar ) ) <EOL> self . assertEqual ( entry_points , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> with self . run_execute ( bar , recursive = False ) as created : <EOL> self . assertEqual ( [ bar ] , created . keys ( ) ) <EOL> with self . run_execute ( bar , recursive = True ) as created : <EOL> self . assertEqual ( { bar_bin_dep , bar } , set ( created . keys ( ) ) ) <EOL> def test_pants_contrib_case ( self ) : <EOL> def create_requirement_lib ( name ) : <EOL> return self . create_python_requirement_library ( <EOL> relpath = name , <EOL> name = name , <EOL> requirements = [ <EOL> '<STR_LIT>' . format ( name ) <EOL> ] <EOL> ) <EOL> req1 = create_requirement_lib ( '<STR_LIT>' ) <EOL> create_requirement_lib ( '<STR_LIT>' ) <EOL> req3 = create_requirement_lib ( '<STR_LIT>' ) <EOL> self . create_python_library ( <EOL> relpath = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> dependencies = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> ) <EOL> self . create_python_binary ( <EOL> relpath = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> entry_point = '<STR_LIT>' , <EOL> dependencies = [ <EOL> '<STR_LIT>' , <EOL> ] <EOL> ) <EOL> pants_packaged = self . create_python_library ( <EOL> relpath = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> provides = dedent ( """<STR_LIT>""" ) <EOL> ) <EOL> contrib_lib = self . create_python_library ( <EOL> relpath = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> dependencies = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> ) <EOL> contrib_plugin = self . create_python_library ( <EOL> relpath = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> provides = dedent ( """<STR_LIT>""" ) , <EOL> dependencies = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> ) <EOL> reduced_dependencies = self . dependency_calculator . reduced_dependencies ( contrib_plugin ) <EOL> self . assertEqual ( reduced_dependencies , OrderedSet ( [ contrib_lib , req3 , pants_packaged , req1 ] ) ) <EOL> def test_no_exported ( self ) : <EOL> foo = self . create_python_library ( relpath = '<STR_LIT:foo>' , name = '<STR_LIT:foo>' ) <EOL> with self . assertRaises ( TaskError ) : <EOL> with self . run_execute ( foo ) : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_no_owner ( self ) : <EOL> self . create_python_library ( relpath = '<STR_LIT:foo>' , name = '<STR_LIT:foo>' ) <EOL> exported = self . create_python_library ( <EOL> relpath = '<STR_LIT:bar>' , <EOL> name = '<STR_LIT:bar>' , <EOL> dependencies = [ <EOL> '<STR_LIT:foo>' <EOL> ] , <EOL> provides = dedent ( """<STR_LIT>""" ) , <EOL> ) <EOL> with self . assertRaises ( self . dependency_calculator . NoOwnerError ) : <EOL> self . dependency_calculator . reduced_dependencies ( exported ) <EOL> def test_ambiguous_owner ( self ) : <EOL> self . create_python_library ( relpath = '<STR_LIT>' , name = '<STR_LIT:bar>' ) <EOL> self . create_file ( relpath = self . build_path ( '<STR_LIT:foo>' ) , contents = dedent ( """<STR_LIT>""" ) ) <EOL> with self . assertRaises ( self . dependency_calculator . AmbiguousOwnerError ) : <EOL> self . dependency_calculator . reduced_dependencies ( self . target ( '<STR_LIT>' ) ) <EOL> with self . assertRaises ( self . dependency_calculator . AmbiguousOwnerError ) : <EOL> self . dependency_calculator . reduced_dependencies ( self . target ( '<STR_LIT>' ) ) <EOL> @ contextmanager <EOL> def extracted_sdist ( src , sdist , expected_prefix , collect_suffixes = None ) : <EOL> collect_suffixes = collect_suffixes or ( '<STR_LIT>' , ) <EOL> def collect ( path ) : <EOL> for suffix in collect_suffixes : <EOL> if path . endswith ( suffix ) : <EOL> return True <EOL> return False <EOL> with temporary_dir ( ) as chroot : <EOL> TGZ . extract ( sdist , chroot ) <EOL> all_py_files = set ( ) <EOL> for root , _ , files in os . walk ( chroot ) : <EOL> all_py_files . update ( os . path . join ( root , f ) for f in files if collect ( f ) ) <EOL> def as_full_path ( p ) : <EOL> return os . path . join ( chroot , expected_prefix , p ) <EOL> yield all_py_files , as_full_path <EOL> def test_resources ( self ) : <EOL> self . create_file ( relpath = '<STR_LIT>' , contents = '<STR_LIT>' ) <EOL> self . create_file ( relpath = '<STR_LIT>' , contents = '<STR_LIT>' ) <EOL> self . create_file ( relpath = '<STR_LIT>' , contents = '<STR_LIT>' ) <EOL> self . create_file ( relpath = '<STR_LIT>' , <EOL> contents = '<STR_LIT>' ) <EOL> self . add_to_build_file ( '<STR_LIT>' , dedent ( """<STR_LIT>""" ) ) <EOL> conway = self . target ( '<STR_LIT>' ) <EOL> with self . run_execute ( conway ) as created : <EOL> self . assertEqual ( [ conway ] , created . keys ( ) ) <EOL> with self . extracted_sdist ( sdist = created [ conway ] , <EOL> expected_prefix = '<STR_LIT>' , <EOL> collect_suffixes = ( '<STR_LIT>' , '<STR_LIT>' ) ) as ( py_files , path ) : <EOL> self . assertEqual ( { path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) } , <EOL> py_files ) <EOL> with open ( path ( '<STR_LIT>' ) ) as fp : <EOL> self . assertEqual ( '<STR_LIT>' , fp . read ( ) ) <EOL> with open ( path ( '<STR_LIT>' ) ) as fp : <EOL> self . assertEqual ( '<STR_LIT>' , fp . read ( ) ) <EOL> def test_symlinks_issues_2815 ( self ) : <EOL> res = self . create_file ( relpath = '<STR_LIT>' , contents = '<STR_LIT>' ) <EOL> os . symlink ( res , os . path . join ( self . build_root , '<STR_LIT>' ) ) <EOL> self . create_file ( relpath = '<STR_LIT>' , contents = '<STR_LIT>' ) <EOL> self . create_file ( relpath = '<STR_LIT>' , <EOL> contents = '<STR_LIT>' ) <EOL> self . add_to_build_file ( '<STR_LIT>' , dedent ( """<STR_LIT>""" ) ) <EOL> conway = self . target ( '<STR_LIT>' ) <EOL> with self . run_execute ( conway ) as created : <EOL> self . assertEqual ( [ conway ] , created . keys ( ) ) <EOL> os . unlink ( res ) <EOL> with self . extracted_sdist ( sdist = created [ conway ] , <EOL> expected_prefix = '<STR_LIT>' , <EOL> collect_suffixes = ( '<STR_LIT>' , '<STR_LIT>' ) ) as ( py_files , path ) : <EOL> res_link_path = path ( '<STR_LIT>' ) <EOL> self . assertFalse ( os . path . islink ( res_link_path ) ) <EOL> self . assertEqual ( { path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) , <EOL> res_link_path } , <EOL> py_files ) <EOL> with open ( res_link_path ) as fp : <EOL> self . assertEqual ( '<STR_LIT>' , fp . read ( ) ) <EOL> def test_exported_antlr ( self ) : <EOL> self . create_file ( relpath = '<STR_LIT>' , contents = dedent ( """<STR_LIT>""" ) ) <EOL> target = self . make_target ( spec = '<STR_LIT>' , <EOL> target_type = PythonAntlrLibrary , <EOL> antlr_version = '<STR_LIT>' , <EOL> sources = [ '<STR_LIT>' ] , <EOL> module = '<STR_LIT>' , <EOL> provides = PythonArtifact ( name = '<STR_LIT>' , version = '<STR_LIT>' ) ) <EOL> with subsystem_instance ( JVM ) : <EOL> with self . run_execute ( target ) as created : <EOL> self . assertEqual ( [ target ] , created . keys ( ) ) <EOL> def test_exported_thrift ( self ) : <EOL> self . create_file ( relpath = '<STR_LIT>' , contents = dedent ( """<STR_LIT>""" ) ) <EOL> target = self . make_target ( spec = '<STR_LIT>' , <EOL> target_type = PythonThriftLibrary , <EOL> sources = [ '<STR_LIT>' ] , <EOL> provides = PythonArtifact ( name = '<STR_LIT>' , version = '<STR_LIT>' ) ) <EOL> with self . run_execute ( target ) as created : <EOL> self . assertEqual ( [ target ] , created . keys ( ) ) <EOL> def test_exported_thrift_issues_2005 ( self ) : <EOL> self . create_file ( relpath = '<STR_LIT>' , contents = dedent ( """<STR_LIT>""" ) ) <EOL> target1 = self . make_target ( spec = '<STR_LIT>' , <EOL> target_type = PythonThriftLibrary , <EOL> sources = [ '<STR_LIT>' ] , <EOL> provides = PythonArtifact ( name = '<STR_LIT>' , version = '<STR_LIT>' ) ) <EOL> self . create_file ( relpath = '<STR_LIT>' , <EOL> contents = dedent ( """<STR_LIT>""" ) ) <EOL> target2 = self . make_target ( spec = '<STR_LIT>' , <EOL> target_type = PythonThriftLibrary , <EOL> sources = [ '<STR_LIT>' ] , <EOL> dependencies = [ target1 ] , <EOL> provides = PythonArtifact ( name = '<STR_LIT>' , <EOL> version = '<STR_LIT>' ) ) <EOL> with self . run_execute ( target2 , recursive = True ) as created : <EOL> self . assertEqual ( { target2 , target1 } , set ( created . keys ( ) ) ) <EOL> with self . extracted_sdist ( sdist = created [ target1 ] , <EOL> expected_prefix = '<STR_LIT>' ) as ( py_files , path ) : <EOL> self . assertEqual ( { path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) } , <EOL> py_files ) <EOL> self . assertFalse ( os . path . exists ( path ( '<STR_LIT>' ) ) ) <EOL> with self . extracted_sdist ( sdist = created [ target2 ] , <EOL> expected_prefix = '<STR_LIT>' ) as ( py_files , path ) : <EOL> self . assertEqual ( { path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) , <EOL> path ( '<STR_LIT>' ) } , <EOL> py_files ) <EOL> requirements = path ( '<STR_LIT>' ) <EOL> self . assertTrue ( os . path . exists ( requirements ) ) <EOL> with open ( requirements ) as fp : <EOL> self . assertEqual ( '<STR_LIT>' , fp . read ( ) . strip ( ) ) <EOL> def test_detect_namespace_packages ( ) : <EOL> def has_ns ( stmt ) : <EOL> with temporary_file ( ) as fp : <EOL> fp . write ( stmt ) <EOL> fp . flush ( ) <EOL> return SetupPy . declares_namespace_package ( fp . name ) <EOL> assert not has_ns ( '<STR_LIT>' ) <EOL> assert not has_ns ( '<STR_LIT>' ) <EOL> assert not has_ns ( '<STR_LIT>' ) <EOL> assert has_ns ( '<STR_LIT>' ) <EOL> assert has_ns ( '<STR_LIT>' ) <EOL> assert has_ns ( '<STR_LIT>' ) <EOL> @ contextmanager <EOL> def yield_chroot ( packages , namespace_packages , resources ) : <EOL> def to_path ( package ) : <EOL> return package . replace ( '<STR_LIT:.>' , os . path . sep ) <EOL> with temporary_dir ( ) as td : <EOL> def write ( package , name , content ) : <EOL> package_path = os . path . join ( td , SetupPy . SOURCE_ROOT , to_path ( package ) ) <EOL> safe_mkdir ( os . path . dirname ( os . path . join ( package_path , name ) ) ) <EOL> with open ( os . path . join ( package_path , name ) , '<STR_LIT:w>' ) as fp : <EOL> fp . write ( content ) <EOL> for package in packages : <EOL> write ( package , '<STR_LIT>' , '<STR_LIT>' ) <EOL> for package in namespace_packages : <EOL> write ( package , '<STR_LIT>' , '<STR_LIT>' ) <EOL> for package , resource_list in resources . items ( ) : <EOL> for resource in resource_list : <EOL> write ( package , resource , '<STR_LIT>' ) <EOL> chroot_mock = Mock ( spec = Chroot ) <EOL> chroot_mock . path . return_value = td <EOL> yield chroot_mock <EOL> def test_find_packages ( ) : <EOL> def assert_single_chroot ( packages , namespace_packages , resources ) : <EOL> with yield_chroot ( packages , namespace_packages , resources ) as chroot : <EOL> p , n_p , r = SetupPy . find_packages ( chroot ) <EOL> assert p == set ( packages + namespace_packages ) <EOL> assert n_p == set ( namespace_packages ) <EOL> assert r == dict ( ( k , set ( v ) ) for ( k , v ) in resources . items ( ) ) <EOL> assert_single_chroot ( [ '<STR_LIT:foo>' ] , [ ] , { } ) <EOL> assert_single_chroot ( [ '<STR_LIT:foo>' ] , [ '<STR_LIT:foo>' ] , { } ) <EOL> assert_single_chroot ( [ '<STR_LIT:foo>' ] , [ ] , { '<STR_LIT:foo>' : [ '<STR_LIT>' ] } ) <EOL> resources = { <EOL> '<STR_LIT:foo>' : [ <EOL> '<STR_LIT>' , <EOL> os . path . join ( '<STR_LIT:bar>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> os . path . join ( '<STR_LIT:bar>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> } <EOL> assert_single_chroot ( [ '<STR_LIT:foo>' ] , [ ] , resources ) <EOL> with yield_chroot ( [ '<STR_LIT:foo>' , '<STR_LIT>' ] , [ ] , resources ) as chroot : <EOL> _ , _ , r = SetupPy . find_packages ( chroot ) <EOL> assert r == { <EOL> '<STR_LIT:foo>' : { '<STR_LIT>' } , <EOL> '<STR_LIT>' : { os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) , os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) } <EOL> } <EOL> with yield_chroot ( <EOL> [ '<STR_LIT:foo>' , '<STR_LIT>' ] , <EOL> [ ] , <EOL> { '<STR_LIT>' : [ '<STR_LIT>' ] } ) as chroot : <EOL> _ , _ , r = SetupPy . find_packages ( chroot ) <EOL> assert r == { '<STR_LIT:foo>' : { '<STR_LIT>' } } <EOL> def test_nearest_subpackage ( ) : <EOL> assert SetupPy . nearest_subpackage ( '<STR_LIT:foo>' , [ ] ) == '<STR_LIT:foo>' <EOL> assert SetupPy . nearest_subpackage ( '<STR_LIT:foo>' , [ '<STR_LIT:foo>' ] ) == '<STR_LIT:foo>' <EOL> assert SetupPy . nearest_subpackage ( '<STR_LIT:foo>' , [ '<STR_LIT:bar>' ] ) == '<STR_LIT:foo>' <EOL> assert '<STR_LIT:foo>' == SetupPy . nearest_subpackage ( '<STR_LIT>' , [ '<STR_LIT:foo>' ] ) <EOL> assert '<STR_LIT>' == SetupPy . nearest_subpackage ( <EOL> '<STR_LIT>' , [ '<STR_LIT:foo>' , '<STR_LIT>' ] ) <EOL> assert '<STR_LIT>' == SetupPy . nearest_subpackage ( <EOL> '<STR_LIT>' , [ '<STR_LIT:foo>' , '<STR_LIT>' ] ) <EOL> assert '<STR_LIT:foo>' == SetupPy . nearest_subpackage ( <EOL> '<STR_LIT>' , [ '<STR_LIT:foo>' , '<STR_LIT>' ] ) </s>
