Problem getting unittest tests for existing project working
Peter Otten
__peter__ at web.de
Mon Jul 3 03:26:19 EDT 2017
Aaron Gray wrote:
> I am trying to get distorm3's unittests working but to no avail.
>
> I am not really a Python programmer so was hoping someone in the know
> maybe able to fix this for me.
Normally it doesn't work that way...
>
> Here's a GitHub issue I have created for the bug :-
>
> https://github.com/gdabah/distorm/issues/118
...though this time it does:
diff --git a/examples/tests/test_distorm3.py
b/examples/tests/test_distorm3.py
index aec1d63..babaacc 100644
--- a/examples/tests/test_distorm3.py
+++ b/examples/tests/test_distorm3.py
@@ -43,11 +43,18 @@ def Assemble(text, mode):
mode = "amd64"
else:
mode = "x86"
- os.system("yasm.exe -m%s 1.asm" % mode)
+ os.system("yasm -m%s 1.asm" % mode)
return open("1", "rb").read()
-class InstBin(unittest.TestCase):
+class NoTest(unittest.TestCase):
+ def __init__(self):
+ unittest.TestCase.__init__(self, "test_dummy")
+ def test_dummy(self):
+ self.fail("dummy")
+
+class InstBin(NoTest):
def __init__(self, bin, mode):
+ NoTest.__init__(self)
bin = bin.decode("hex")
#fbin[mode].write(bin)
self.insts = Decompose(0, bin, mode)
@@ -61,8 +68,9 @@ class InstBin(unittest.TestCase):
self.assertNotEqual(self.inst.rawFlags, 65535)
self.assertEqual(self.insts[instNo].mnemonic, mnemonic)
-class Inst(unittest.TestCase):
+class Inst(NoTest):
def __init__(self, instText, mode, instNo, features):
+ NoTest.__init__(self)
modeSize = [16, 32, 64][mode]
bin = Assemble(instText, modeSize)
#print map(lambda x: hex(ord(x)), bin)
Notes:
(1) This is a hack; the original code was probably written against an older
version of unittest and is abusing the framework to some extent. The dummy
tests I introduced are ugly but should do no harm.
(2) I tried this on linux only and thus changed 'yasm.exe' to 'yasm'
unconditionally.
More information about the Python-list
mailing list