<s> from qisys . test . conftest import * <EOL> import qisys . qixml <EOL> from qisys . qixml import etree <EOL> import qibuild . config <EOL> import qibuild . deps <EOL> import qitoolchain <EOL> import qitoolchain . qipackage <EOL> import qitoolchain . database <EOL> import qitoolchain . toolchain <EOL> class Toolchains ( ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> tmpdir = tempfile . mkdtemp ( prefix = "<STR_LIT>" ) <EOL> self . tmp = py . path . local ( tmpdir ) . realpath ( ) <EOL> def clean ( self ) : <EOL> self . tmp . remove ( ) <EOL> def create ( self , name ) : <EOL> toolchain = qitoolchain . toolchain . Toolchain ( name ) <EOL> return toolchain <EOL> def add_package ( self , name , package_name , package_version = "<STR_LIT>" , <EOL> build_depends = None , run_depends = None , test_depends = None , <EOL> host_depends = None ) : <EOL> toolchain = qitoolchain . get_toolchain ( name ) <EOL> package_path = self . tmp . mkdir ( package_name ) <EOL> package = qitoolchain . qipackage . QiPackage ( package_name , package_version ) <EOL> package . path = package_path . strpath <EOL> for dep_type in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:test>" , "<STR_LIT:host>" ] : <EOL> attr_name = "<STR_LIT>" % dep_type <EOL> value = locals ( ) [ attr_name ] <EOL> if value : <EOL> setattr ( package , attr_name , set ( value ) ) <EOL> else : <EOL> setattr ( package , attr_name , set ( ) ) <EOL> package . write_package_xml ( ) <EOL> toolchain . add_package ( package ) <EOL> return package <EOL> class TestFeed ( ) : <EOL> def __init__ ( self , tmp ) : <EOL> self . tmp = tmp <EOL> self . packages_path = tmp . ensure ( "<STR_LIT>" , dir = True ) <EOL> self . feed_xml = tmp . join ( "<STR_LIT>" ) <EOL> self . feed_xml . write ( "<STR_LIT>" ) <EOL> self . url = "<STR_LIT>" + self . feed_xml . strpath <EOL> def add_package ( self , package , with_path = True , with_url = True ) : <EOL> this_dir = os . path . dirname ( __file__ ) <EOL> this_dir = qisys . sh . to_native_path ( this_dir ) <EOL> package_path = self . tmp . join ( "<STR_LIT>" ) <EOL> package_path . ensure ( "<STR_LIT>" , "<STR_LIT>" % package . name , file = True ) <EOL> package_path . ensure ( "<STR_LIT>" , "<STR_LIT>" % package . name , file = True ) <EOL> package_xml = package_path . join ( "<STR_LIT>" ) <EOL> package_xml . write ( """<STR_LIT>""" % ( package . name , package . version ) ) <EOL> archive_name = "<STR_LIT>" % ( package . name , package . version ) <EOL> output = package_path . join ( archive_name + "<STR_LIT>" ) <EOL> archive = qisys . archive . compress ( package_path . strpath , flat = True , <EOL> output = output . strpath ) <EOL> if with_path : <EOL> package . path = archive <EOL> if with_url : <EOL> base_url = self . url . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> package . url = base_url + "<STR_LIT>" % archive_name <EOL> tree = qisys . qixml . read ( self . feed_xml . strpath ) <EOL> root = tree . getroot ( ) <EOL> package_elem = package . to_xml ( ) <EOL> root . append ( package_elem ) <EOL> qisys . qixml . write ( tree , self . feed_xml . strpath ) <EOL> return package <EOL> def add_svn_package ( self , package ) : <EOL> tree = qisys . qixml . read ( self . feed_xml . strpath ) <EOL> root = tree . getroot ( ) <EOL> svn_elem = etree . SubElement ( root , "<STR_LIT>" ) <EOL> svn_elem . set ( "<STR_LIT:name>" , package . name ) <EOL> svn_elem . set ( "<STR_LIT:url>" , package . url ) <EOL> if package . revision : <EOL> svn_elem . set ( "<STR_LIT>" , package . revision ) <EOL> qisys . qixml . write ( tree , self . feed_xml . strpath ) <EOL> def remove_package ( self , name ) : <EOL> tree = qisys . qixml . read ( self . feed_xml . strpath ) <EOL> root = tree . getroot ( ) <EOL> for elem in root . findall ( "<STR_LIT>" ) : <EOL> if elem . get ( "<STR_LIT:name>" ) == name : <EOL> root . remove ( elem ) <EOL> qisys . qixml . write ( tree , self . feed_xml . strpath ) <EOL> @ pytest . fixture <EOL> def feed ( tmpdir ) : <EOL> res = TestFeed ( tmpdir ) <EOL> return res <EOL> @ pytest . fixture <EOL> def toolchain_db ( tmpdir ) : <EOL> db_path = tmpdir . join ( "<STR_LIT>" ) <EOL> db_path . write ( "<STR_LIT>" ) <EOL> db = qitoolchain . database . DataBase ( "<STR_LIT:bar>" , db_path . strpath ) <EOL> return db <EOL> @ pytest . fixture <EOL> def toolchains ( request ) : <EOL> res = Toolchains ( ) <EOL> request . addfinalizer ( res . clean ) <EOL> return res <EOL> @ pytest . fixture <EOL> def qitoolchain_action ( cd_to_tmpdir ) : <EOL> res = QiToolchainAction ( ) <EOL> return res <EOL> @ pytest . fixture <EOL> def fake_ctc ( ) : <EOL> toolchain = qitoolchain . toolchain . Toolchain ( "<STR_LIT>" ) <EOL> this_dir = os . path . dirname ( __file__ ) <EOL> toolchain . update ( feed_location = os . path . join ( this_dir , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> qibuild . config . add_build_config ( "<STR_LIT>" , toolchain = "<STR_LIT>" ) <EOL> return toolchain <EOL> class QiToolchainAction ( TestAction ) : <EOL> def __init__ ( self ) : <EOL> super ( QiToolchainAction , self ) . __init__ ( "<STR_LIT>" ) <EOL> def get_test_package ( self , name ) : <EOL> this_dir = os . path . dirname ( __file__ ) <EOL> return os . path . join ( this_dir , "<STR_LIT>" , name + "<STR_LIT>" ) </s>
