How to use xxd method in fMBT

Best Python code snippet using fMBT_python

test_xxd.py

Source:test_xxd.py Github

copy

Full Screen

...59 parser.add_argument('infile', nargs='?', default='-')60 parser.add_argument('outfile', nargs='?', default='-')61 args = parser.parse_args(args, namespace)62 kwargs = vars(args)63 xxd(**kwargs)64# ============================================================================65def test_parse_seek():66 assert parse_seek(None) == ('', 0)67# ============================================================================68def test_by_filename_xxd(tmppath, datapath):69 prefix = 'test_xxd_'70 test_filenames = glob.glob(str(datapath / (prefix + '*.xxd')))71 for filename in test_filenames:72 filename = os.path.basename(filename)73 path_out = tmppath / filename74 path_ref = datapath / filename75 cmdline = filename[len(prefix):].replace('_', ' ')76 args = cmdline.split()77 path_in = datapath / os.path.splitext(args[-1])[0]78 args = args[:-1] + [str(path_in), str(path_out)]79 run_cli(args)80 ans_out = read_text(path_out)81 ans_ref = read_text(path_ref)82 #if ans_out != ans_ref: raise AssertionError(str(path_ref))83 assert ans_out == ans_ref84def test_by_filename_bin(tmppath, datapath):85 prefix = 'test_xxd_'86 test_filenames = glob.glob(str(datapath / (prefix + '*.bin')))87 for filename in test_filenames:88 filename = os.path.basename(filename)89 path_out = tmppath / filename90 path_ref = datapath / filename91 cmdline = filename[len(prefix):].replace('_', ' ')92 args = cmdline.split()93 path_in = datapath / os.path.splitext(args[-1])[0]94 args = args[:-1] + [str(path_in), str(path_out)]95 run_cli(args)96 ans_out = read_bytes(path_out)97 ans_ref = read_bytes(path_ref)98 #if ans_out != ans_ref: raise AssertionError(str(path_ref))99 assert ans_out == ans_ref100def test_by_filename_c(tmppath, datapath):101 prefix = 'test_xxd_'102 test_filenames = glob.glob(str(datapath / (prefix + '*.c')))103 for filename in test_filenames:104 filename = os.path.basename(filename)105 path_out = tmppath / filename106 path_ref = datapath / filename107 cmdline = filename[len(prefix):].replace('_', ' ')108 args = cmdline.split()109 path_in = datapath / os.path.splitext(args[-1])[0]110 args = args[:-1] + [str(path_in), str(path_out)]111 run_cli(args)112 ans_out = read_text(path_out)113 ans_ref = read_text(path_ref)114 #if ans_out != ans_ref: raise AssertionError(str(path_ref))115 assert ans_out == ans_ref116def test_xxd(datapath):117 with open(str(datapath / 'bytes.bin'), 'rb') as stream:118 data_in = memoryview(stream.read())119 with pytest.raises(ValueError, match='invalid column count'):120 xxd(cols=-1)121 with pytest.raises(ValueError, match='invalid column count'):122 xxd(cols=257)123 with pytest.raises(ValueError, match='incompatible options'):124 xxd(bits=True, postscript=True)125 with pytest.raises(ValueError, match='incompatible options'):126 xxd(bits=True, include=True)127 with pytest.raises(ValueError, match='incompatible options'):128 xxd(bits=True, revert=True)129 with pytest.raises(ValueError, match='incompatible options'):130 xxd(endian=True, postscript=True)131 with pytest.raises(ValueError, match='incompatible options'):132 xxd(endian=True, include=True)133 with pytest.raises(ValueError, match='incompatible options'):134 xxd(endian=True, revert=True)135 with pytest.raises(ValueError, match='incompatible options'):136 xxd(postscript=True, include=True)137 with pytest.raises(ValueError, match='incompatible options'):138 xxd(postscript=True, bits=True)139 with pytest.raises(ValueError, match='incompatible options'):140 xxd(include=True, bits=True)141 with pytest.raises(ValueError, match='incompatible options'):142 xxd(revert=False, oseek=0)143 with pytest.raises(ValueError, match='invalid seeking'):144 xxd(revert=True, oseek=-1)145 with pytest.raises(ValueError, match='invalid syntax'):146 xxd(data_in, iseek='invalid')147 with pytest.raises(ValueError, match='invalid seeking'):148 xxd(data_in, iseek='+')149 with pytest.raises(ValueError, match='invalid grouping'):150 xxd(data_in, groupsize=-1)151 with pytest.raises(ValueError, match='invalid grouping'):152 xxd(data_in, groupsize=257)153 with pytest.raises(ValueError, match='offset overflow'):154 xxd(data_in, offset=-1)155 with pytest.raises(ValueError, match='offset overflow'):156 xxd(data_in, offset=(1 << 32))157def test_xxd_stdinout(datapath):158 stdin_backup = sys.stdin159 stdout_backup = sys.stdout160 text_out = None161 text_ref = None162 try:163 with open(str(datapath / 'bytes.bin'), 'rb') as stream:164 data_in = memoryview(stream.read())165 sys.stdin = io.BytesIO(data_in)166 sys.stdout = io.StringIO()167 xxd()168 with open(str(datapath / 'test_xxd_bytes.bin.xxd'), 'rt') as stream:169 text_ref = stream.read().replace('\r\n', '\n')170 text_out = sys.stdout.getvalue().replace('\r\n', '\n')171 finally:172 sys.stdin = stdin_backup173 sys.stdout = stdout_backup174 assert text_out == text_ref175def test_xxd_bytes(datapath):176 with open(str(datapath / 'bytes.bin'), 'rb') as stream:177 data_in = memoryview(stream.read())178 text_out = io.StringIO()179 xxd(data_in, text_out)180 with open(str(datapath / 'test_xxd_bytes.bin.xxd'), 'rt') as stream:181 text_ref = stream.read().replace('\r\n', '\n')182 text_out = text_out.getvalue().replace('\r\n', '\n')183 assert text_out == text_ref184def test_xxd_bytes_seek(datapath):185 stdin_backup = sys.stdin186 stdout_backup = sys.stdout187 text_out = None188 text_ref = None189 try:190 with open(str(datapath / 'bytes.bin'), 'rb') as stream:191 data_in = memoryview(stream.read())192 sys.stdin = io.BytesIO(data_in)193 sys.stdout = io.StringIO()194 sys.stdin.seek(96, io.SEEK_CUR)195 xxd(iseek='+-64')196 filename = 'test_xxd_-s_32_bytes.bin.xxd'197 with open(str(datapath / filename), 'rt') as stream:198 text_ref = stream.read().replace('\r\n', '\n')199 text_out = sys.stdout.getvalue().replace('\r\n', '\n')200 finally:201 sys.stdin = stdin_backup202 sys.stdout = stdout_backup203 assert text_out == text_ref204def test_xxd_include_stdin(datapath):205 with open(str(datapath / 'bytes.bin'), 'rb') as stream:206 data_in = memoryview(stream.read())207 text_out = io.StringIO()208 xxd(data_in, text_out, include=True)209 with open(str(datapath / 'bytes-stdin.c'), 'rt') as stream:210 text_ref = stream.read().replace('\r\n', '\n')211 text_out = text_out.getvalue().replace('\r\n', '\n')212 assert text_out == text_ref213def test_xxd_ellipsis(datapath):214 with open(str(datapath / 'test_xxd_bytes.bin.xxd'), 'rt') as stream:215 text_ref = stream.read().replace('\r\n', '\n')216 with open(str(datapath / 'bytes.bin'), 'rb') as stream_in:217 stream_out = xxd(stream_in, Ellipsis)218 text_out = stream_out.getvalue()219 assert text_out == text_ref220def test_xxd_ellipsis_reverse(datapath):221 with open(str(datapath / 'bytes.bin'), 'rb') as stream:222 data_ref = memoryview(stream.read())223 with open(str(datapath / 'bytes.xxd'), 'rt') as stream_in:224 stream_out = xxd(stream_in, Ellipsis, revert=True)225 data_out = stream_out.getvalue()...

Full Screen

Full Screen

xxd_test.py

Source:xxd_test.py Github

copy

Full Screen

...49 # This corrects for this to avoid having this test fail when that is the only problem50 corrected_expected = self._standardize_xxd_output(expected)51 corrected_actual = self._standardize_xxd_output(actual)52 self.assertEquals(corrected_expected, corrected_actual)53 def test_compare_to_xxd(self):54 """55 Runs xxd on some random text, and compares output with our xxd.56 It's conceivable that this isn't portable: xxd may have different57 default options.58 To be honest, this test was written after this was working.59 I tested using a temporary file and a side-by-side diff tool (vimdiff).60 """61 # /dev/random tends to hang on Linux, so we use python instead.62 # It's inefficient, but it's not terrible.63 random_text = "".join(chr(random.getrandbits(8)) for _ in range(LENGTH))64 p = Popen(["xxd"], shell=True, stdin=PIPE, stdout=PIPE, close_fds=True)65 (stdin, stderr) = p.communicate(random_text)66 self.assertFalse(stderr)67 output = StringIO.StringIO()...

Full Screen

Full Screen

urls.py

Source:urls.py Github

copy

Full Screen

1from django.conf.urls import url2import views as mock_pro_views3urlpatterns = [4 url(r'^$',mock_pro_views.index,name="index"),5 url(r'^indexPost/$',mock_pro_views.indexPost,name="d1"),6 url(r'^indexXXD/$',mock_pro_views.indexXXD,name="d1"),7 url(r'^indexPatch/$',mock_pro_views.indexPatch,name="d5"),8 url(r'^indexPut/$', mock_pro_views.indexPut, name="d6"),9 url(r'^indexGet/$',mock_pro_views.indexGet,name="d2"),10 url(r'^indexDelete/$', mock_pro_views.indexDelete, name="d7"),11 url(r'^indexGetBatch/$',mock_pro_views.indexGetBatch,name="d3"),12 url(r'^indexPostBatch/$',mock_pro_views.indexPostBatch,name="d4"),13 #url(r'^(?P<mock_pro_id>\d+)/$',mock_pro_views.vote,name='vote'),14 url(r'^post/(?P<mock_pro_id>\d+)/$',mock_pro_views.post_ready,name='post_ready'),15 url(r'^post_batch/(?P<mock_pro_id>\d+)/$',mock_pro_views.post_batch_ready,name='post_batch_ready'),16#xxd requests post17 #post18 # url(r'^xxd_post/(?P<mock_pro_id>\d+)/$',mock_pro_views.post_ready,name='post_ready'),19 url(r'^post/(?P<mock_pro_id>\d+)/$',mock_pro_views.xxd_request_ready,name='post_ready'),20 url(r'^post/(?P<mock_pro_id>\d+)/(?P<req_type>\POST)/rep/$',mock_pro_views.xxd_request_vessel,name='xxd_post_ok'),#(?P<req_type>\"POST")21 #put22 # url(r'^xxd_post/(?P<mock_pro_id>\d+)/$',mock_pro_views.post_ready,name='post_ready'),23 # url(r'^xxd_post/(?P<mock_pro_id>\d+)/(?P<req_type>\POST)/rep/$',mock_pro_views.xxd_request,name='xxd_post_ok'),24 url(r'^put/(?P<mock_pro_id>\d+)/$', mock_pro_views.post_ready, name='put_ready'),25 url(r'^put/(?P<mock_pro_id>\d+)/(?P<req_type>\PUT)/rep/$', mock_pro_views.xxd_request_vessel,name='xxd_put_ok'),26 # patch27 # url(r'^xxd_post/(?P<mock_pro_id>\d+)/$',mock_pro_views.post_ready,name='post_ready'),28 # url(r'^xxd_post/(?P<mock_pro_id>\d+)/(?P<req_type>\w+)/rep/$',mock_pro_views.xxd_request,name='xxd_post_ok'),#(?P<req_type>\"POST")29 url(r'^patch/(?P<mock_pro_id>\d+)/$',mock_pro_views.post_ready,name='patch_ready'),30 url(r'^patch/(?P<mock_pro_id>\d+)/(?P<req_type>\PATCH)/rep/$',mock_pro_views.xxd_request_vessel,name='xxd_patch_ok'),31 #delete32 url(r'^delete/(?P<mock_pro_id>\d+)/$', mock_pro_views.delete_ready, name='delete_ready'),33 url(r'^delete/(?P<mock_pro_id>\d+)/(?P<req_type>\DELETE)/rep/$', mock_pro_views.xxd_request_vessel,name='xxd_delete_ok'),34 url(r'^post/(?P<mock_pro_id>\d+)/rep/$',mock_pro_views.post_ok,name='post_ok'),35 url(r'^post_batch/(?P<mock_pro_id>\d+)/rep/$',mock_pro_views.post_batch_ok,name='post_batch_ok'),36 url(r'^get/(?P<mock_pro_id>\d+)/$',mock_pro_views.get_ready,name='get_ready'),37 url(r'^get_batch/(?P<mock_pro_id>\d+)/$',mock_pro_views.get_batch_ready,name='get_batch_ready'),38 url(r'^get_batch/(?P<mock_pro_id>\d+)/rep/$',mock_pro_views.get_batch_ok,name='get_batch_ok'),...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful