<s> import json <EOL> import os <EOL> import tempfile <EOL> import unittest <EOL> from zipfile import ZipFile <EOL> import shutil <EOL> from nordicsemi . dfu . package import Package <EOL> class TestPackage ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . work_directory = tempfile . mkdtemp ( prefix = "<STR_LIT>" ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . work_directory , ignore_errors = True ) <EOL> def test_generate_package_application ( self ) : <EOL> self . p = Package ( <EOL> dev_type = <NUM_LIT:1> , <EOL> dev_rev = <NUM_LIT:2> , <EOL> app_version = <NUM_LIT:100> , <EOL> sd_req = [ <NUM_LIT> , <NUM_LIT> ] , <EOL> app_fw = "<STR_LIT>" <EOL> ) <EOL> pkg_name = "<STR_LIT>" <EOL> self . p . generate_package ( pkg_name , preserve_work_directory = False ) <EOL> expected_zip_content = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> with ZipFile ( pkg_name , '<STR_LIT:r>' ) as pkg : <EOL> infolist = pkg . infolist ( ) <EOL> for file_information in infolist : <EOL> self . assertTrue ( file_information . filename in expected_zip_content ) <EOL> self . assertGreater ( file_information . file_size , <NUM_LIT:0> ) <EOL> pkg . extractall ( self . work_directory ) <EOL> with open ( os . path . join ( self . work_directory , '<STR_LIT>' ) , '<STR_LIT:r>' ) as f : <EOL> _json = json . load ( f ) <EOL> self . assertEqual ( u'<STR_LIT>' , _json [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( u'<STR_LIT>' , _json [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( u'<STR_LIT>' not in _json [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( u'<STR_LIT>' not in _json [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( u'<STR_LIT>' not in _json [ '<STR_LIT>' ] ) <EOL> def test_generate_package_sd_bl ( self ) : <EOL> self . p = Package ( dev_type = <NUM_LIT:1> , <EOL> dev_rev = <NUM_LIT:2> , <EOL> app_version = <NUM_LIT:100> , <EOL> sd_req = [ <NUM_LIT> , <NUM_LIT> ] , <EOL> softdevice_fw = "<STR_LIT>" , <EOL> bootloader_fw = "<STR_LIT>" ) <EOL> pkg_name = "<STR_LIT>" <EOL> self . p . generate_package ( pkg_name , preserve_work_directory = False ) <EOL> expected_zip_content = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> with ZipFile ( pkg_name , '<STR_LIT:r>' ) as pkg : <EOL> infolist = pkg . infolist ( ) <EOL> for file_information in infolist : <EOL> self . assertTrue ( file_information . filename in expected_zip_content ) <EOL> self . assertGreater ( file_information . file_size , <NUM_LIT:0> ) <EOL> pkg . extractall ( self . work_directory ) <EOL> with open ( os . path . join ( self . work_directory , '<STR_LIT>' ) , '<STR_LIT:r>' ) as f : <EOL> _json = json . load ( f ) <EOL> self . assertEqual ( u'<STR_LIT>' , _json [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( u'<STR_LIT>' , _json [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_unpack_package_a ( self ) : <EOL> self . p = Package ( dev_type = <NUM_LIT:1> , <EOL> dev_rev = <NUM_LIT:2> , <EOL> app_version = <NUM_LIT:100> , <EOL> sd_req = [ <NUM_LIT> , <NUM_LIT> ] , <EOL> softdevice_fw = "<STR_LIT>" , <EOL> dfu_ver = <NUM_LIT> ) <EOL> pkg_name = os . path . join ( self . work_directory , "<STR_LIT>" ) <EOL> self . p . generate_package ( pkg_name , preserve_work_directory = False ) <EOL> unpacked_dir = os . path . join ( self . work_directory , "<STR_LIT>" ) <EOL> manifest = self . p . unpack_package ( os . path . join ( self . work_directory , pkg_name ) , unpacked_dir ) <EOL> self . assertIsNotNone ( manifest ) <EOL> self . assertEqual ( u'<STR_LIT>' , manifest . softdevice . bin_file ) <EOL> self . assertEqual ( <NUM_LIT:0> , manifest . softdevice . init_packet_data . ext_packet_id ) <EOL> self . assertIsNotNone ( manifest . softdevice . init_packet_data . firmware_crc16 ) <EOL> def test_unpack_package_b ( self ) : <EOL> self . p = Package ( dev_type = <NUM_LIT:1> , <EOL> dev_rev = <NUM_LIT:2> , <EOL> app_version = <NUM_LIT:100> , <EOL> sd_req = [ <NUM_LIT> , <NUM_LIT> ] , <EOL> softdevice_fw = "<STR_LIT>" , <EOL> dfu_ver = <NUM_LIT> ) <EOL> pkg_name = os . path . join ( self . work_directory , "<STR_LIT>" ) <EOL> self . p . generate_package ( pkg_name , preserve_work_directory = False ) <EOL> unpacked_dir = os . path . join ( self . work_directory , "<STR_LIT>" ) <EOL> manifest = self . p . unpack_package ( os . path . join ( self . work_directory , pkg_name ) , unpacked_dir ) <EOL> self . assertIsNotNone ( manifest ) <EOL> self . assertEqual ( u'<STR_LIT>' , manifest . softdevice . bin_file ) <EOL> self . assertEqual ( <NUM_LIT:1> , manifest . softdevice . init_packet_data . ext_packet_id ) <EOL> self . assertIsNone ( manifest . softdevice . init_packet_data . firmware_crc16 ) <EOL> self . assertIsNotNone ( manifest . softdevice . init_packet_data . firmware_hash ) <EOL> def test_unpack_package_c ( self ) : <EOL> self . p = Package ( dev_type = <NUM_LIT:1> , <EOL> dev_rev = <NUM_LIT:2> , <EOL> app_version = <NUM_LIT:100> , <EOL> sd_req = [ <NUM_LIT> , <NUM_LIT> ] , <EOL> softdevice_fw = "<STR_LIT>" , <EOL> key_file = "<STR_LIT>" ) <EOL> pkg_name = os . path . join ( self . work_directory , "<STR_LIT>" ) <EOL> self . p . generate_package ( pkg_name , preserve_work_directory = False ) <EOL> unpacked_dir = os . path . join ( self . work_directory , "<STR_LIT>" ) <EOL> manifest = self . p . unpack_package ( os . path . join ( self . work_directory , pkg_name ) , unpacked_dir ) <EOL> self . assertIsNotNone ( manifest ) <EOL> self . assertEqual ( u'<STR_LIT>' , manifest . softdevice . bin_file ) <EOL> self . assertEqual ( <NUM_LIT:2> , manifest . softdevice . init_packet_data . ext_packet_id ) <EOL> self . assertIsNone ( manifest . softdevice . init_packet_data . firmware_crc16 ) <EOL> self . assertIsNotNone ( manifest . softdevice . init_packet_data . firmware_hash ) <EOL> self . assertIsNotNone ( manifest . softdevice . init_packet_data . init_packet_ecds ) <EOL> self . assertEqual ( manifest . dfu_version , <NUM_LIT> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
