Best Python code snippet using refurb_python
test_syscalls.py
Source:test_syscalls.py
1from builtins import object2from posix_omni_parser import Trace3from posix_omni_parser import parsing_classes4import os5def get_test_data_path(filename):6 dir_path = os.path.dirname(os.path.realpath(__file__))7 return os.path.join(dir_path, filename)8class TestOpen(object):9 def test_open(self):10 strace_path = get_test_data_path("openclose.strace")11 syscall_definitions = get_test_data_path("syscall_definitions.pickle")12 t = Trace.Trace(strace_path, syscall_definitions)13 open_call = t.syscalls[0]14 assert open_call.name == "open"15 assert open_call.args[0].value == "test.txt"16 assert open_call.args[1].value == ["O_RDONLY"]17 assert open_call.args[2].value == ["0"]18 assert open_call.ret == (3, None)19 bad_open_call = t.syscalls[1]20 assert bad_open_call.ret == (-1, "ENOENT")21 def test_close(self):22 strace_path = get_test_data_path("openclose.strace")23 syscall_definitions = get_test_data_path("syscall_definitions.pickle")24 t = Trace.Trace(strace_path, syscall_definitions)25 close_call = t.syscalls[3]26 assert close_call.name == "close"27 assert close_call.args[0].value == 328 assert close_call.ret == (0, None)29 def openat(self):30 strace_path = get_test_data_path("openclose.strace")31 syscall_definitions = get_test_data_path("syscall_definitions.pickle")32 t = Trace.Trace(strace_path, syscall_definitions)33 openat_call = t.syscalls[4]34 assert openat_call.args[0].value == "AT_FDCWD"35 assert openat_call.args[1].value == "/etc/ld.so.cache"36 assert openat_call.ret == (7, None)37class TestFstat(object):38 def test_fstat(self):39 strace_path = get_test_data_path("fstat.strace")40 syscall_definitions = get_test_data_path("syscall_definitions.pickle")41 t = Trace.Trace(strace_path, syscall_definitions)42 fstat_call = t.syscalls[0]43 assert fstat_call.name == "fstat"44 assert fstat_call.args[0].value == 345 assert fstat_call.args[1].value[0] == "st_dev=makedev(0, 4)"46 assert fstat_call.args[1].value[5] == "st_gid=0"47 def test_stat(self):48 strace_path = get_test_data_path("fstat.strace")49 syscall_definitions = get_test_data_path("syscall_definitions.pickle")50 t = Trace.Trace(strace_path, syscall_definitions)51 stat_call = t.syscalls[1]52 assert stat_call.args[0].value == "/proc/19"53 assert stat_call.args[1].value[0] == "st_dev=makedev(0, 0x16)"54 assert stat_call.args[1].value[5] == "st_gid=0"55 assert stat_call.ret == (0, None)56 def test_lstat(self):57 strace_path = get_test_data_path("fstat.strace")58 syscall_definitions = get_test_data_path("syscall_definitions.pickle")59 t = Trace.Trace(strace_path, syscall_definitions)60 lstat_call = t.syscalls[2]61 assert lstat_call.args[0].value == "/proc/self/task"62 assert lstat_call.args[1].value[0] == "st_dev=makedev(0, 0x16)"63 assert lstat_call.args[1].value[5] == "st_gid=0"64 assert lstat_call.ret == (0, None)65 def test_statfs(self):66 strace_path = get_test_data_path("fstat.strace")67 syscall_definitions = get_test_data_path("syscall_definitions.pickle")68 t = Trace.Trace(strace_path, syscall_definitions)69 statfs_call = t.syscalls[3]70 assert statfs_call.args[0].value == "/sys/fs/selinux"71 assert statfs_call.args[1].value == "0x7ffffab26f40"72 assert statfs_call.ret == (-1, "ENOENT")73class TestSocket(object):74 def test_socket(self):75 strace_path = get_test_data_path("socket.strace")76 syscall_definitions = get_test_data_path("syscall_definitions.pickle")77 t = Trace.Trace(strace_path, syscall_definitions)78 socket_call = t.syscalls[0]79 assert socket_call.name == "socket"80 assert socket_call.args[0].value == ["PF_INET"]81 assert socket_call.args[1].value == ["SOCK_STREAM"]82 assert socket_call.args[2].value == ["IPPROTO_IP"]83 assert socket_call.ret == (3, None)84 # mark a socket as accepting connections85 def test_listen(self):86 strace_path = get_test_data_path("socket.strace")87 syscall_definitions = get_test_data_path("syscall_definitions.pickle")88 t = Trace.Trace(strace_path, syscall_definitions)89 listen_call = t.syscalls[11]90 assert listen_call.args[0].value == 791 assert listen_call.args[1].value == 592 assert listen_call.ret == (0, None)93class TestConnect(object):94 def test_connect(self):95 strace_path = get_test_data_path("socket.strace")96 syscall_definitions = get_test_data_path("syscall_definitions.pickle")97 t = Trace.Trace(strace_path, syscall_definitions)98 connect_call = t.syscalls[6]99 assert connect_call.args[0].value == 4100 assert connect_call.args[1].value[0].value == "AF_LOCAL"101 assert connect_call.args[1].value[1].value == "/var/run/nscd/socket"102 assert connect_call.args[2].value == 110103 assert connect_call.ret == (-1, "ENOENT")104class TestRead(object):105 def test_read(self):106 strace_path = get_test_data_path("readwrite.strace")107 syscall_definitions = get_test_data_path("syscall_definitions.pickle")108 t = Trace.Trace(strace_path, syscall_definitions)109 read_call = t.syscalls[0]110 assert read_call.args[0].value == 7111 assert read_call.args[1].value == '"hello world"'112 assert read_call.args[2].value == "1024"113 assert read_call.ret == (11, None)114 bad_read_call = t.syscalls[1]115 assert bad_read_call.args[0].value == 40116 assert bad_read_call.args[1].value == "0x7ffcf0e72860"117 assert bad_read_call.args[2].value == "10"118 assert bad_read_call.ret == (-1, "EBADF")119 def test_write(self):120 strace_path = get_test_data_path("readwrite.strace")121 syscall_definitions = get_test_data_path("syscall_definitions.pickle")122 t = Trace.Trace(strace_path, syscall_definitions)123 write_call = t.syscalls[2]124 assert write_call.args[0].value == 0125 assert write_call.args[1].value == '"Hello"'126 assert write_call.args[2].value == "5"127 assert write_call.ret == (5, None)128 bad_write_call = t.syscalls[3]129 assert bad_write_call.args[0].value == 40130 assert bad_write_call.args[1].value == '"Bad m"'131 assert bad_write_call.args[2].value == "5"132 assert bad_write_call.ret == (-1, "EBADF")133class TestExecve(object):134 def test_execve(self):135 strace_path = get_test_data_path("execve.strace")136 syscall_definitions = get_test_data_path("syscall_definitions.pickle")137 t = Trace.Trace(strace_path, syscall_definitions)138 execve_call = t.syscalls[0]139 assert execve_call.args[0].value == "/bin/ps"140 assert execve_call.args[1].value == '["ps"]'141 assert execve_call.args[2].value == "NULL"142 assert execve_call.ret == (0, None)143 def test_get_pid(self):144 strace_path = get_test_data_path("execve.strace")145 syscall_definitions = get_test_data_path("syscall_definitions.pickle")146 t = Trace.Trace(strace_path, syscall_definitions)147 getpid_call = t.syscalls[1]148 assert getpid_call.ret == (21698, None)149 def test_get_euid(self):150 strace_path = get_test_data_path("execve.strace")151 syscall_definitions = get_test_data_path("syscall_definitions.pickle")152 t = Trace.Trace(strace_path, syscall_definitions)153 geteuid_call = t.syscalls[2]154 assert geteuid_call.ret == (0, None)155class TestLseek(object):156 def test_lseek(self):157 strace_path = get_test_data_path("execve.strace")158 syscall_definitions = get_test_data_path("syscall_definitions.pickle")159 t = Trace.Trace(strace_path, syscall_definitions)160 lseek_call = t.syscalls[3]161 assert lseek_call.args[0].value == 3162 assert lseek_call.args[1].value == "0"163 assert lseek_call.args[2].value == ["SEEK_SET"]164 assert lseek_call.ret == (0, None)165class TestClone(object):166 def test_clone(self):167 strace_path = get_test_data_path("clone.strace")168 syscall_definitions = get_test_data_path("syscall_definitions.pickle")169 t = Trace.Trace(strace_path, syscall_definitions)170 clone_call = t.syscalls[0]171 assert clone_call.args[0].value == ["child_stack=NULL"]172 assert (173 clone_call.args[1].value174 == "flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD"175 )176 assert clone_call.args[2].value == ["child_tidptr=0x7fdb04c07810"]177 assert clone_call.ret == (21677, None)178class TestLink(object):179 def test_link(self):180 strace_path = get_test_data_path("link.strace")181 syscall_definitions = get_test_data_path("syscall_definitions.pickle")182 t = Trace.Trace(strace_path, syscall_definitions)183 link_call = t.syscalls[0]184 assert link_call.args[0].value == "al/ma/newfile.txt"185 assert link_call.args[1].value == "al/sic/newest1.txt"186 assert link_call.ret == (0, None)187 bad_link_call = t.syscalls[1]188 assert bad_link_call.args[0].value == "al/ma/newfile.txt"189 assert bad_link_call.args[1].value == "al/sic/"190 assert bad_link_call.ret == (-1, "EEXIST")191 def test_unlink(self):192 strace_path = get_test_data_path("link.strace")193 syscall_definitions = get_test_data_path("syscall_definitions.pickle")194 t = Trace.Trace(strace_path, syscall_definitions)195 unlink_call = t.syscalls[2]196 assert unlink_call.args[0].value == "al/sic/newest1.txt"197 assert unlink_call.ret == (0, None)198 bad_unlink_call = t.syscalls[3]199 assert bad_unlink_call.args[0].value == "al/sic/newest2.txt"200 assert bad_unlink_call.ret == (-1, "ENOENT")201class TestDir(object):202 def test_mkdir(self):203 strace_path = get_test_data_path("directory.strace")204 syscall_definitions = get_test_data_path("syscall_definitions.pickle")205 t = Trace.Trace(strace_path, syscall_definitions)206 mkdir_call = t.syscalls[0]207 assert mkdir_call.args[0].value == "al/ma/new-dir1"208 assert mkdir_call.args[1].value == ["0700"]209 assert mkdir_call.ret == (0, None)210 bad_mkdir_call = t.syscalls[1]211 assert bad_mkdir_call.args[0].value == "al/ma/new-dir1"212 assert bad_mkdir_call.args[1].value == ["0700"]213 assert bad_mkdir_call.ret == (-1, "EEXIST")214 def test_rmdir(self):215 strace_path = get_test_data_path("directory.strace")216 syscall_definitions = get_test_data_path("syscall_definitions.pickle")217 t = Trace.Trace(strace_path, syscall_definitions)218 rmdir_call = t.syscalls[2]219 assert rmdir_call.args[0].value == "al/ma/new-dir1"220 assert rmdir_call.ret == (0, None)221 bad_rmdir_call = t.syscalls[3]222 assert bad_rmdir_call.args[0].value == "al/ma/new-dir1"223 assert bad_rmdir_call.ret == (-1, "ENOENT")224 def test_chdir(self):225 strace_path = get_test_data_path("directory.strace")226 syscall_definitions = get_test_data_path("syscall_definitions.pickle")227 t = Trace.Trace(strace_path, syscall_definitions)228 chdir_call = t.syscalls[4]229 assert (230 chdir_call.args[0].value231 == "/home/almazhan/Desktop/res_tandon/posix-omni-parser/testbins"232 )233 assert chdir_call.ret == (0, None)234 bad_chdir_call = t.syscalls[5]235 assert (236 bad_chdir_call.args[0].value237 == "/home/almazhan/Desktop/res_tandon/posix-omni-parser/testbins1"238 )239 assert bad_chdir_call.ret == (-1, "ENOENT")240 def test_getcwd(self):241 strace_path = get_test_data_path("directory.strace")242 syscall_definitions = get_test_data_path("syscall_definitions.pickle")243 t = Trace.Trace(strace_path, syscall_definitions)244 getcwd_call = t.syscalls[6]245 assert (246 getcwd_call.args[0].value247 == '"/home/almazhan/Desktop/res_tandon/posix-omni-parser/testbins"'248 )249 assert getcwd_call.args[1].value == "4096"250 assert getcwd_call.ret == (61, None)251 # get directory entries label252 def test_getdents64(self): # Note: empty function253 strace_path = get_test_data_path("directory.strace")254 syscall_definitions = get_test_data_path("syscall_definitions.pickle")255 t = Trace.Trace(strace_path, syscall_definitions)256 getdents64_call = t.syscalls[7]257 assert getdents64_call.args[0].value == 7258 assert getdents64_call.args[1].value == "[]"259 assert getdents64_call.args[2].value == 32768260 assert getdents64_call.ret == (0, None)261class TestMount(object):262 def test_mount(self):263 strace_path = get_test_data_path("mount.strace")264 syscall_definitions = get_test_data_path("syscall_definitions.pickle")265 t = Trace.Trace(strace_path, syscall_definitions)266 mount_call = t.syscalls[0]267 assert mount_call.args[0].value == '"none"'268 assert mount_call.args[1].value == '"/var/tmp"'269 assert mount_call.args[2].value == '"tmpfs"'270 assert mount_call.args[3].value == "0"271 assert mount_call.args[4].value == '"mode=0700,uid=65534"'272 assert mount_call.ret == (0, None)273 bad_mount_call = t.syscalls[1]274 assert bad_mount_call.args[0].value == '"al/ma/newest"'275 assert bad_mount_call.args[1].value == '"al/mnt"'276 assert bad_mount_call.args[2].value == "NULL"277 assert bad_mount_call.args[4].value == "NULL"278 assert bad_mount_call.ret == (-1, "EINVAL")279 def test_unmount(self):280 strace_path = get_test_data_path("mount.strace")281 syscall_definitions = get_test_data_path("syscall_definitions.pickle")282 t = Trace.Trace(strace_path, syscall_definitions)283 unmount_call = t.syscalls[2]284 assert unmount_call.args[0].value == '"/var/tmp"'285 assert unmount_call.args[1].value == ["0"]286 assert unmount_call.ret == (0, None)287 bad_unmount_call = t.syscalls[3]288 assert bad_unmount_call.args[0].value == '"al/mnt/"'289 assert bad_unmount_call.args[1].value == ["0"]290 assert bad_unmount_call.ret == (-1, "EINVAL")291class TestChmod(object):292 def test_chmod(self):293 strace_path = get_test_data_path("execve.strace")294 syscall_definitions = get_test_data_path("syscall_definitions.pickle")295 t = Trace.Trace(strace_path, syscall_definitions)296 chmod_call = t.syscalls[4]297 assert chmod_call.args[0].value == "al/ma/newfile.txt"298 assert chmod_call.args[1].value == ["0644"]299 assert chmod_call.ret == (0, None)300 bad_chmod_call = t.syscalls[5]301 assert bad_chmod_call.args[0].value == "al/ma/newfile7.txt"302 assert bad_chmod_call.args[1].value == ["0644"]303 assert bad_chmod_call.ret == (-1, "ENOENT")304 def test_access(self):305 strace_path = get_test_data_path("execve.strace")306 syscall_definitions = get_test_data_path("syscall_definitions.pickle")307 t = Trace.Trace(strace_path, syscall_definitions)308 bad_access_call = t.syscalls[6]309 assert bad_access_call.args[0].value == "/etc/ld.so.preload"310 assert bad_access_call.args[1].value == ["R_OK"]311 assert bad_access_call.ret == (-1, "ENOENT")312class TestSignals(object):313 def test_sigaction(self): # Note-incorrect parsing314 strace_path = get_test_data_path("signals.strace")315 syscall_definitions = get_test_data_path("syscall_definitions.pickle")316 t = Trace.Trace(strace_path, syscall_definitions)317 sigaction_call = t.syscalls[0]318 assert sigaction_call.args[0].value == "SIGCHLD"319 assert sigaction_call.args[1].value == "{sa_handler=0x55907f1f81c9"320 assert sigaction_call.args[2].value == "sa_mask=[CHLD]"321 assert sigaction_call.args[3].value == "sa_flags=SA_RESTORER|SA_RESTART"322 assert sigaction_call.args[4].value == "sa_restorer=0x7ff1ed57f210}"323 assert sigaction_call.args[4].value == "sa_restorer=0x7ff1ed57f210}"324 assert sigaction_call.args[8].value == "8"325 assert sigaction_call.ret == (0, None)326 def test_sigprocmask(self):327 strace_path = get_test_data_path("signals.strace")328 syscall_definitions = get_test_data_path("syscall_definitions.pickle")329 t = Trace.Trace(strace_path, syscall_definitions)330 sigprocmask_call = t.syscalls[1]331 assert sigprocmask_call.args[0].value == ["SIG_UNBLOCK"]332 assert sigprocmask_call.args[1].value == "[RTMIN RT_1]"333 assert sigprocmask_call.args[2].value == "NULL"334 assert sigprocmask_call.args[3].value == "8"335 assert sigprocmask_call.ret == (0, None)336 def test_sigreturn(self):337 strace_path = get_test_data_path("signals.strace")338 syscall_definitions = get_test_data_path("syscall_definitions.pickle")339 t = Trace.Trace(strace_path, syscall_definitions)340 sigreturn_call = t.syscalls[2]341 assert sigreturn_call.args[0].value == "{mask=[]}"342 assert sigreturn_call.ret == (26827, None)343class TestMemory(object):344 def test_mprotect(self):345 strace_path = get_test_data_path("memory.strace")346 syscall_definitions = get_test_data_path("syscall_definitions.pickle")347 t = Trace.Trace(strace_path, syscall_definitions)348 mprotect_call = t.syscalls[0]349 assert mprotect_call.args[0].value == "0x7f3366ab3000"350 assert mprotect_call.args[1].value == "12288"351 assert mprotect_call.args[2].value == ["PROT_READ"]352 assert mprotect_call.ret == (0, None)353 # create new mapping in the va space354 def test_mmap(self):355 strace_path = get_test_data_path("memory.strace")356 syscall_definitions = get_test_data_path("syscall_definitions.pickle")357 t = Trace.Trace(strace_path, syscall_definitions)358 mmap_call = t.syscalls[1]359 assert mmap_call.args[0].value == "NULL"360 assert mmap_call.args[1].value == "2036952"361 assert mmap_call.args[2].value == ["PROT_READ"]362 assert mmap_call.args[4].value == 7363 assert mmap_call.args[5].value == "0"364 assert mmap_call.ret == ("0x7fc88349b000", None)365 # delete mappings for specified address range366 def test_munmap(self):367 strace_path = get_test_data_path("memory.strace")368 syscall_definitions = get_test_data_path("syscall_definitions.pickle")369 t = Trace.Trace(strace_path, syscall_definitions)370 munmap_call = t.syscalls[2]371 assert munmap_call.args[0].value == "0x7fcf9d4b0000"372 assert munmap_call.args[1].value == "75070"373 assert munmap_call.ret == (0, None)374 # set resource limits375 def test_prlimit64(self): # Note-incorrect parsing376 strace_path = get_test_data_path("memory.strace")377 syscall_definitions = get_test_data_path("syscall_definitions.pickle")378 t = Trace.Trace(strace_path, syscall_definitions)379 prlimit64_call = t.syscalls[3]380 assert prlimit64_call.args[0].value == 0381 assert prlimit64_call.args[1].value == ["RLIMIT_STACK"]382 assert prlimit64_call.args[2].value == "NULL"383 assert prlimit64_call.args[3].value == "{rlim_cur=8192*1024"384 assert prlimit64_call.ret == (0, None)385class TestSetup(object):386 # set segment size387 def test_brk(self):388 strace_path = get_test_data_path("misc.strace")389 syscall_definitions = get_test_data_path("syscall_definitions.pickle")390 t = Trace.Trace(strace_path, syscall_definitions)391 brk_call = t.syscalls[0]392 assert brk_call.args[0].value == "NULL"393 assert brk_call.ret == ("0x56221d7d1000", None)394 # set pointer to thread ID395 def test_tid_addr(self):396 strace_path = get_test_data_path("misc.strace")397 syscall_definitions = get_test_data_path("syscall_definitions.pickle")398 t = Trace.Trace(strace_path, syscall_definitions)399 set_tid_addr_call = t.syscalls[1]400 assert set_tid_addr_call.args[0].value == "7f75b62c36d0"401 assert set_tid_addr_call.ret == (29898, None)402 # set list of robust futexes403 def test_robust_list(self):404 strace_path = get_test_data_path("misc.strace")405 syscall_definitions = get_test_data_path("syscall_definitions.pickle")406 t = Trace.Trace(strace_path, syscall_definitions)407 set_robust_list_call = t.syscalls[2]408 assert set_robust_list_call.args[0].value == "0x7f75b62c36e0"409 assert set_robust_list_call.args[1].value == "24"410 assert set_robust_list_call.ret == (0, None)411 # set architecture specific thread state412 def test_arch_prctl(self):413 strace_path = get_test_data_path("misc.strace")414 syscall_definitions = get_test_data_path("syscall_definitions.pickle")415 t = Trace.Trace(strace_path, syscall_definitions)416 arch_prctl_call = t.syscalls[3]417 assert arch_prctl_call.args[0].value == ["ARCH_SET_FS"]418 assert arch_prctl_call.args[1].value == "0x7f75b62c3400"419 assert arch_prctl_call.ret == (0, None)420 bad_arch_prctl_call = t.syscalls[4]421 assert bad_arch_prctl_call.args[0].value == ["0x3001 /* ARCH_??? */"]422 assert bad_arch_prctl_call.args[1].value == "0x7ffcf11e3030"423 assert bad_arch_prctl_call.ret == (-1, "EINVAL")424class TestMisc(object):425 # control device426 def test_ioctl(self): # Note-incorrect parsing427 strace_path = get_test_data_path("misc.strace")428 syscall_definitions = get_test_data_path("syscall_definitions.pickle")429 t = Trace.Trace(strace_path, syscall_definitions)430 ioctl_call = t.syscalls[5]431 assert ioctl_call.args[0].value == 1432 assert ioctl_call.args[1].value == "TIOCGWINSZ"433 assert ioctl_call.args[2].value == "{ws_row=16"434 assert ioctl_call.args[3].value == "ws_col=109"435 assert ioctl_call.args[4].value == "ws_xpixel=0"436 assert ioctl_call.ret == (0, None)437 # read from a file descriptor at an offset438 def test_pread64(self):439 strace_path = get_test_data_path("misc.strace")440 syscall_definitions = get_test_data_path("syscall_definitions.pickle")441 t = Trace.Trace(strace_path, syscall_definitions)442 prlimit64_call = t.syscalls[6]443 assert prlimit64_call.args[0].value == 3444 assert prlimit64_call.args[2].value == "784"445 assert prlimit64_call.args[3].value == "64"446 assert prlimit64_call.ret == (784, None)447class TestWrite(object):448 def test_write(self):449 strace_path = get_test_data_path("write.strace")450 syscall_definitions = get_test_data_path("syscall_definitions.pickle")451 t = Trace.Trace(strace_path, syscall_definitions)452 write_call = t.syscalls[0]453 assert write_call.name == "write"454 assert write_call.args[0].value == 1455 assert (456 write_call.args[1].value457 == '"crashsimlang get-pip.py local posix-omni-parser test\\n"'458 )459 assert write_call.args[2].value == "57"460 assert write_call.ret == (57, None)461class TestWait:462 def test_wait(self):463 strace_path = get_test_data_path("unfinished.strace")464 syscall_definitions = get_test_data_path("syscall_definitions.pickle")465 t = Trace.Trace(strace_path, syscall_definitions)466 wait_call = t.syscalls[0]467 # import pdb; pdb.set_trace()468 assert wait_call.name == "wait4"469 assert wait_call.args[0].value == 8216470 assert wait_call.args[1].expected_value.type == "int"471 assert wait_call.args[1].expected_value.name == "wstatus"472 assert wait_call.args[1].given_value == None473 assert wait_call.args[2].expected_value.type == "int"474 assert wait_call.args[2].expected_value.name == "options"475 assert wait_call.args[3].expected_value.pointer == True476 assert wait_call.ret == None477 478# 14037 recv(6, 0xb7199058, 4096, 0) = -1 EAGAIN479# 20645 recvfrom(7, 0x7ffd1481ba50, 256, 0, NULL, NULL) = -1 ENOTCONN (Transport endpoint is not connected)480class TestRecv:481 def test_recv(self):482 strace_path = get_test_data_path("recv.strace")483 syscall_definitions = get_test_data_path("syscall_definitions.pickle")484 t = Trace.Trace(strace_path, syscall_definitions)485 recv_call = t.syscalls[0]486 #20645 recv(6, 0xb7199058, 4096, 0) = -1 EAGAIN487 assert recv_call.args[0].value == 6488 assert recv_call.args[1].value == "0xb7199058"489 assert recv_call.args[2].value == "4096"490 assert recv_call.args[3].value == ['0']491 assert recv_call.ret == (-1, "EAGAIN")492 def test_recvfrom(self):493 strace_path = get_test_data_path("recv.strace")494 syscall_definitions = get_test_data_path("syscall_definitions.pickle")495 t = Trace.Trace(strace_path, syscall_definitions)496 recvfrom_call = t.syscalls[1]497 #20645 recvfrom(7, 0x7ffd1481ba50, 256, 0, NULL, NULL) = -1 ENOTCONN (Transport endpoint is not connected)498 assert recvfrom_call.args[0].value == 7499 assert recvfrom_call.args[1].value == "0x7ffd1481ba50"500 assert recvfrom_call.args[2].value == "256"501 assert recvfrom_call.args[3].value == []502 assert recvfrom_call.args[4].value == 'NULL'...
test_parser.py
Source:test_parser.py
...16 copy_tree(test_data_path, self.test_data_path)17 self.maxDiff = None18 def tearDown(self):19 shutil.rmtree(self.test_data_path)20 def get_test_data_path(self, fs_path: str):21 return os.path.join(self.test_data_path, fs_path)22 def test_simple_load_yaml(self):23 fs_path = self.get_test_data_path('test_config_01.yml')24 p = conff.Parser()25 data = p.load(fs_path=fs_path)26 data = data if data else {}27 self.assertDictEqual(data, {'test_1': 'test_1', 'test_2': ''})28 def test_ext_up_load_yaml(self):29 fs_path = self.get_test_data_path('test_config_04.yml')30 p = conff.Parser()31 data = p.load(fs_path=fs_path)32 data = data if data else {}33 self.assertDictEqual(data, {34 "test_13": {"test_13_1": 1, "test_13_2": 2, "test_13_3": 3, "test_13_5": {"test_13_5_1": 1},35 "test_13_6": {"test_13_6_1": 1}},36 "test_14": {"test_13_1": 11, "test_13_2": 2, "test_13_3": 3, "test_13_5": 5,37 "test_13_6": {"test_13_6_1": 1, "test_13_6_2": {"test_13_6_2_1": 1, "test_13_6_2_2": 2}},38 "test_13_4": 4}})39 def test_load_json(self):40 fs_path = self.get_test_data_path('test_config_01.json')41 p = conff.Parser()42 data = p.load(fs_path=fs_path)43 data = data if data else {}44 self.assertDictEqual(data, {'test_1': 1, 'test_2': 2})45 def test_complex_load_yml(self):46 p = conff.Parser()47 fs_path = self.get_test_data_path('test_config_02.yml')48 p.generate_crypto_key()49 data = p.load(fs_path=fs_path)50 data = data if data else {}51 # test simple types52 self.assertEqual(data.get('test_1'), 'test_1')53 self.assertEqual(data.get('test_2'), 2)54 self.assertListEqual(data.get('test_3'), ['test_3', 3])55 self.assertDictEqual(data.get('test_4'), {'test_4_1': 'test_4_1'})56 self.assertDictEqual(data.get('test_5'), {'test_5_1': 'test_5_1', 'test_5_2': {'test_5_2_1': 'test_5_2_1'}})57 # test expression58 self.assertEqual(data.get('test_6'), 'test_6')59 # test extends60 self.assertListEqual(data.get('test_7', {}).get('test_7_1'), [1, 2])61 self.assertListEqual(data.get('test_7', {}).get('test_7_2'), [1, 2])62 self.assertDictEqual(data.get('test_7', {}).get('test_7_3'), {'data2_1': 1, 'data2_2': 2, 'data2_3': 3})63 # test complex extends64 self.assertDictEqual(data.get('test_8'), {'data2_1': 1, 'data2_2': '2a', 'data2_3': 3, 'data2_4': 4})65 # test complex expressions66 self.assertListEqual(data.get('test_9', {}).get('test_9_1'), [True, False, True, False])67 self.assertListEqual(data.get('test_9', {}).get('test_9_2'), [1, 'RO'])68 self.assertEqual(data.get('test_9', {}).get('test_9_3'), '1 2 3')69 self.assertEqual(data.get('test_9', {}).get('test_9_4'), 'ro/ro')70 # test error expressions71 self.assertEqual(data.get('test_10'), 'F.no_exist()')72 # test encryption73 self.assertEqual(data.get('test_11'), 'test_11')74 # test importing75 self.assertDictEqual(data.get('test_12'), {'test_1': 'test_1', 'test_2': ''})76 # test update77 data_test_13 = {'test_13_1': 1, 'test_13_2': 2, 'test_13_3': 3, 'test_13_5': {'test_13_5_1': 1},78 'test_13_6': {'test_13_6_1': 1}}79 self.assertDictEqual(data.get('test_13'), data_test_13)80 # test extend + update81 data_test_14 = {'test_13_1': 11, 'test_13_2': 2, 'test_13_3': 3, 'test_13_5': 5,82 'test_13_6': {'test_13_6_1': 1, 'test_13_6_2': {'test_13_6_2_1': 1, 'test_13_6_2_2': 2}},83 'test_13_4': 4}84 self.assertDictEqual(data.get('test_14'), data_test_14)85 # test foreach with linspace86 data_test_15 = {'test0': {'value': 0, 'length': 3},87 'test1': {'value': 3, 'length': 3},88 'test2': {'value': 6, 'length': 3}}89 self.assertDictEqual(data.get('test_15'), data_test_15)90 # test foreach with arange. Should get same result as above91 data_test_16 = data_test_1592 self.assertDictEqual(data.get('test_16'), data_test_16)93 # test foreach with arange. Testing behavior of arange94 data_test_17 = {'test0': {'value': 0, 'length': 2},95 'test1': {'value': 4, 'length': 2}}96 self.assertDictEqual(data.get('test_17'), data_test_17)97 data_test_18 = {'test_18_1': 3}98 self.assertDictEqual(data.get('test_18'), data_test_18)99 def test_error_load_yaml(self):100 p = conff.Parser()101 fs_path = self.get_test_data_path('test_config_03.yml')102 with self.assertRaises(TypeError) as context:103 data = p.load(fs_path=fs_path)104 def test_error_foreach(self):105 p = conff.Parser()106 fs_path = self.get_test_data_path('malformed_foreach_01.yml')107 with self.assertRaises(ValueError):108 p.load(fs_path=fs_path)109 fs_path = self.get_test_data_path('malformed_foreach_02.yml')110 with self.assertRaises(ValueError):111 p.load(fs_path=fs_path)112 def test_parse(self):113 p = conff.Parser()114 data = p.parse('{"a": "a", "b": "1/0"}')115 self.assertDictEqual(data, {'a': 'a', 'b': '1/0'})116 data = p.parse(utils.odict([('a', 'a'), ('b', '1 + 2')]))117 self.assertDictEqual(data, {'a': 'a', 'b': 3})118 def test_parse_with_fns(self):119 def fn_add(a, b):120 return a + b121 fns = {'add': fn_add, 'test': {'add': fn_add}}122 p = conff.Parser(fns=fns)123 data = p.parse('{"a": "a", "b": "1/0", "c": F.add(1, 2), "d": F.test.add(2, 2)}')124 self.assertDictEqual(data, {'a': 'a', 'b': '1/0', 'c': 3, 'd': 4})125 def test_parse_dict_with_names(self):126 names = {'c': 1, 'd': 2}127 p = conff.Parser(names=names)128 data = p.parse(utils.odict([('a', 'a'), ('b', 'c + d')]))129 self.assertDictEqual(data, {'a': 'a', 'b': 3})130 def test_missing_operators(self):131 names = {'c': 1, 'd': 2}132 p = conff.Parser(names=names, params={'simpleeval': {'operators': {'not': 'an_operator'}}})133 with self.assertRaises(KeyError) as context:134 p.parse(utils.odict([('a', 'a'), ('b', 'c + d')]))135 self.assertTrue("<class '_ast.Add'>" in str(context.exception))136 def test_generate_crypto(self):137 p = conff.Parser()138 del p.params['etype']139 key = p.generate_crypto_key()140 self.assertTrue(key is None)141 self.assertTrue(p.params['ekey'] is None)142 p.params['etype'] = 'nonsense'143 key = p.generate_crypto_key()144 self.assertTrue(key is None)145 self.assertTrue(p.params['ekey'] is None)146 def test_encryption(self):147 # generate key, save it somewhere safe148 names = {'R': {'_': {'etype': 'fernet'}}}149 ekey = 'FOb7DBRftamqsyRFIaP01q57ZLZZV6MVB2xg1Cg_E7g='150 names = {'R': {'_': {'etype': 'fernet', 'ekey': ekey}}}151 original_value = 'ACCESSSECRETPLAIN1234'152 encrypted_value = conff.encrypt(names)(original_value)153 # decrypt data154 value = conff.decrypt(names)(encrypted_value)155 self.assertEqual(original_value, value, 'Value mismatch')156 def test_sample(self):157 # nose2 conff.test.ConffTestCase.test_sample158 fs_path = self.get_test_data_path('sample_config_01.yml')159 with open(fs_path) as stream:160 r1 = yaml.safe_load(stream)161 fs_path = self.get_test_data_path('sample_config_02.yml')162 ekey = 'FOb7DBRftamqsyRFIaP01q57ZLZZV6MVB2xg1Cg_E7g='163 errors = []164 r2 = conff.load(fs_path=fs_path, params={'ekey': ekey}, errors=errors)165 fs_path = self.get_test_data_path('sample_config_03.yml')166 r3 = conff.load(fs_path=fs_path, params={'ekey': ekey})167 self.assertDictEqual(r1['job'], r2['job'], 'Mismatch value')168 self.assertDictEqual(r2['job'], r3['job'], 'Mismatch value')169 def test_object(self):170 # nose2 conff.test.ConffTestCase.test_object171 # TODO: add test when trying to combine config as object with conff172 # test update173 class Test(object):174 test = None175 data = Test()176 conff.update(data, {'test': 'test'})177 self.assertEqual('test', data.test, 'Value mismatch')178 def test_warning(self):179 p = conff.Parser()180 with self.assertWarns(Warning):181 data = p.parse({'a': 'a', 'b': '1 + 2'})182 self.assertDictEqual(data, {'a': 'a', 'b': 3})183 def test_update_recursive(self):184 fns = {'F': conff.update({'a': 1}, {'b': {'c': 2}})}185 self.assertDictEqual(fns, {'F': {'a': 1, 'b': {'c': 2}}})186 def test_parse_old(self):187 data = conff.parse('{"a": "a", "b": "1/0"}')188 self.assertDictEqual(data, {'a': 'a', 'b': '1/0'})189 data = conff.parse(utils.odict([('a', 'a'), ('b', '1 + 2')]))190 self.assertDictEqual(data, {'a': 'a', 'b': 3})191 def test_encryption_old(self):192 # generate key, save it somewhere safe193 names = {'R': {'_': {'etype': 'fernet'}}}194 etype = conff.generate_key(names)()195 ekey = 'FOb7DBRftamqsyRFIaP01q57ZLZZV6MVB2xg1Cg_E7g='196 names = {'R': {'_': {'etype': 'fernet', 'ekey': ekey}}}197 original_value = 'ACCESSSECRETPLAIN1234'198 encrypted_value = conff.encrypt(names)(original_value)199 # decrypt data200 value = conff.decrypt(names)(encrypted_value)201 self.assertEqual(original_value, value, 'Value mismatch')202 def test_fn_template(self):203 p = conff.Parser(names={'test': 1})204 fs_path = self.get_test_data_path('test_config_05.yml')205 data = p.load(fs_path)206 data = data if data else {}207 # test: simple value208 self.assertEqual(data.get('test_1'), 1)209 # test: template as string, it is seamless names from input (test) and template (test_1)210 self.assertEqual(data.get('test_2'), '2')211 # test: template as file (borrowing F.inc capabilities), if test_tpl_01.tpl is {{1 + 2}}212 self.assertEqual(data.get('test_3'), '3')213 # test: this where attaching more complex object214 data_test_4 = {215 "test_4_0": [3, 4], "test_4_1": 1, "test_4_2": 2, "test_4_3": 3, "test_4_4": 4, "test_4_5": 5,216 "test_4_6": 6217 }218 self.assertDictEqual(data.get('test_4'), data_test_4)
test_ace.py
Source:test_ace.py
...4import json5from os.path import dirname, join, exists, sep as pathsep6import os7import shutil8def get_test_data_path():9 """Returns the path to test datasets, terminated with separator (/ vs \)"""10 # TODO: do not rely on __file__11 return join(dirname(__file__), 'data') + pathsep12class TestACE(unittest.TestCase):13 def setUp(self):14 self.db = database.Database(adapter='sqlite', db_name='sqlite:///ace_test_database.tmp')15 self.manager = sources.SourceManager(self.db)16 def tearDown(self):17 os.remove('ace_test_database.tmp')18 # Just run some very basic tests for now, one per Source.19 # Make sure that the right number of tables, activations,20 # etc. are returned.21 def testFrontiersSource(self):22 filename = join(get_test_data_path(), 'frontiers.html')23 html = open(filename).read()24 source = self.manager.identify_source(html)25 article = source.parse_article(html)26 tables = article.tables27 self.assertEqual(len(tables), 3)28 t = tables[2]29 self.assertEqual(t.number, '5')30 self.assertIsNotNone(t.caption)31 self.assertEqual(t.n_activations, 13)32 def testScienceDirectSource(self):33 filename = join(get_test_data_path(), 'neuroimage.html')34 html = open(filename).read()35 source = self.manager.identify_source(html)36 article = source.parse_article(html)37 tables = article.tables38 self.assertEqual(len(tables), 3)39 t = tables[2]40 self.assertEqual(t.number, '4')41 self.assertIsNotNone(t.caption)42 self.assertEqual(t.n_activations, 30)43 def testPlosSource(self):44 filename = join(get_test_data_path(), 'plosone.html')45 html = open(filename).read()46 source = self.manager.identify_source(html)47 article = source.parse_article(html)48 tables = article.tables49 self.assertEqual(len(tables), 1)50 t = tables[0]51 self.assertEqual(t.number, '1')52 self.assertIsNotNone(t.caption)53 for a in t.activations:54 print [a.x, a.y, a.z]55 # Note: only 12 regions, but there are data for 2 experiments,56 # so it's appropriate to treat as 24 activations.57 self.assertEqual(t.n_activations, 24)58 def testDatabaseProcessingStream(self):59 self.db.add_articles(get_test_data_path() + '*.html')60 self.assertEqual(len(self.db.articles), 6)61 export.export_database(self.db, 'exported_db.txt')62 self.assertTrue(exists('exported_db.txt'))63 os.remove('exported_db.txt')64 def testJournalScraping(self):65 scrape_path = join(get_test_data_path(), 'scrape_test')66 os.mkdir(scrape_path)67 # Test with PLoS ONE because it's OA68 scraper = scrape.Scraper(scrape_path)69 scraper.retrieve_journal_articles('PLoS ONE', delay=5.0, mode='direct', 70 search='fmri', limit=2)71 # For now just check to make sure we have expected number of files in the directory72 plos_dir = join(scrape_path, 'html/PLoS ONE/')73 n_files = len([name for name in os.listdir(plos_dir) if os.path.isfile(plos_dir + name)])74 self.assertEqual(n_files, 2)75 shutil.rmtree(scrape_path)76suite = unittest.TestLoader().loadTestsFromTestCase(TestACE)77if __name__ == '__main__':...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!