Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

6 May, 2024: The networking issue during the past two days has been identified and appears to be fixed. Will keep monitoring.


devel / comp.lang.python / Can you mock a C function using ctypes?

SubjectAuthor
o Can you mock a C function using ctypes?Grant Edwards

1
Can you mock a C function using ctypes?

<mailman.442.1663270903.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19522&group=comp.lang.python#19522

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: grant.b....@gmail.com (Grant Edwards)
Newsgroups: comp.lang.python
Subject: Can you mock a C function using ctypes?
Date: Thu, 15 Sep 2022 12:41:40 -0700 (PDT)
Lines: 21
Message-ID: <mailman.442.1663270903.20444.python-list@python.org>
References: <63237ff4.c80a0220.23ec1.ce9c@mx.google.com>
X-Trace: news.uni-berlin.de ZorWxl36gyjdQPD3HqKTGgp9zFKHyS5Icco7xLB66SzA==
Return-Path: <grant.b.edwards@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=JFvr4ZYX;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.029
X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'library.': 0.05;
'received:209.85.219': 0.09; 'from:addr:grant.b.edwards': 0.16;
'from:name:grant edwards': 0.16; 'question,': 0.16; 'python':
0.16; 'grant': 0.17; 'calls': 0.19; 'figure': 0.19; 'to:addr
:python-list': 0.20; "i've": 0.22; 'code': 0.23; 'subject:using':
0.23; 'library': 0.26; 'suspect': 0.26; 'bit': 0.27; 'function':
0.27; 'done': 0.28; 'example,': 0.28; 'asked': 0.29; 'header:User-
Agent:1': 0.30; 'question': 0.32; 'subject:Can': 0.32; 'but':
0.32; 'received:google.com': 0.34; 'from:addr:gmail.com': 0.35;
'functions': 0.36; 'using': 0.37; 'received:209.85': 0.37;
'received:209': 0.39; 'quite': 0.39; "couldn't": 0.40; 'provide':
0.60; 'years': 0.65; 'unit': 0.81; 'subject:you': 0.84; 'was.':
0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:user-agent:subject:from:date:message-id:from:to:cc:subject:date;
bh=tK1Wdd/IxO7uT7WnYpoKO5+7e9H0naWxmao3ZbjvWsI=;
b=JFvr4ZYXF2ewfpuePXqcGYuzMJgkR7OpRQ/KwXC2gY2lxRgI0+hRRQW2O67gXCdDH4
+ORObFZzPOkTThOsHVV1kmOkW5VsIMsCJBh8TiYggcx97oi0Kfr2U/7wi7C3/zrZMSNq
EBkrJ6ddRE4dHkVO8BtmWbR3fBJRKwdM5nPkfaqqmjqV6JqVwf+R4UPJ62SddujacjXe
XFf4KtH52LI3uVfEfeh/ZGJIBAmnBTRySN3vHzUkkox/nUMOhgbdqMLAp0bwx5Tv9jm/
kasKC0H0uCfF35vO2gQaHtMWojQEi7A602H+Mc0MJMZ8gpzy0R4lJEuFp5sQConOQGua
cLpA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=to:user-agent:subject:from:date:message-id:x-gm-message-state:from
:to:cc:subject:date;
bh=tK1Wdd/IxO7uT7WnYpoKO5+7e9H0naWxmao3ZbjvWsI=;
b=VR9dHueUY9YenFos/xX3/5dErLonJtK8+PGH7szpbb+CDaAdQVZJ2+CEzdWhSA2Atp
ZekPGsvLeyVKX5oVeP5KizOkKLLm7R+L5sCOHFPsH9NLnig3s4pl2VvbheZUjhlVlHsq
eECOIFbj3UjvEjoXVVPF5/4OrBx5Sx7IcN/6aUKCJN7WwzYH0YJChltEdTUuFQ6exSgd
EYR3lz7MHhDBSaZ8xu9v4gIkrp4PVwE/BP6M626bf7pL1D5xCKiPcMs7TNf55GLiC4LN
/DJ5I2RK1TbmE7D9GZzgua/2AqEz1ntU20TVAHUSmsW3yNS3nzjQ7tidYLAKLacYwDY8
OCiA==
X-Gm-Message-State: ACrzQf0syYAiUtuiy3itxP5grJzOmQq3/O8a7OJ7FX+vdMC704XdLPh1
XlMMjYYCHb5C0Lf+Kn5UaGXbcomyvTs=
X-Google-Smtp-Source: AMsMyM4+d5coi9YLFuCD8dNIjmx9wQKrch8qI/dc6MwqcABFtVTvdtpEavAr2t94FAjtgGnI45s70g==
X-Received: by 2002:ad4:5cec:0:b0:4ac:96fc:24e3 with SMTP id
iv12-20020ad45cec000000b004ac96fc24e3mr1538225qvb.95.1663270901259;
Thu, 15 Sep 2022 12:41:41 -0700 (PDT)
User-Agent: slrn/1.0.3 (Linux)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <63237ff4.c80a0220.23ec1.ce9c@mx.google.com>
 by: Grant Edwards - Thu, 15 Sep 2022 19:41 UTC

I've done unit testing of C functions using ctypes, and that works
nicely until you need to provide a stub/mock function to be called by
the C code under test.

Can that be done using ctypes?

For example, I open a library that contains functon foo() where foo()
calls external function bar() which is not contained in the library.
Then, I provide a Python bar() function that gets called by foo() when
foo() is called?

I suspect the anser is "no".

I did a bit of googling, and found this question asked on Stack
Overflow a few years ago, but the answer made no sense. It appeared to
be ansering a different question, but I couldn't quite figure out what
that question was.

--
Grant

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor