Skip to content

Commit 338c006

Browse files
author
Lee Miller
committed
Inherit TestProofofworkBase from partial.TestPartialRun
1 parent 822950e commit 338c006

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/tests/partial.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import sys
5+
import time
56
import unittest
67

78
from pybitmessage import pathmagic
@@ -39,3 +40,5 @@ def tearDownClass(cls):
3940
# deactivate pathmagic
4041
os.chdir(cls.dirs[0])
4142
sys.path.remove(cls.dirs[1])
43+
time.sleep(5)
44+
cls.state.shutdown = 0

src/tests/test_proofofwork.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@
1414
networkDefaultProofOfWorkNonceTrialsPerByte,
1515
networkDefaultPayloadLengthExtraBytes)
1616

17+
from .partial import TestPartialRun
1718
from .samples import sample_pow_target, sample_pow_initial_hash
1819

1920
default_ttl = 7200
2021

2122

22-
class TestProofofworkBase(unittest.TestCase):
23+
class TestProofofworkBase(TestPartialRun):
2324
"""Basic test case for proofofwork"""
2425

2526
@classmethod
2627
def setUpClass(cls):
2728
proofofwork.init()
29+
super(TestProofofworkBase, cls).setUpClass()
30+
31+
def setUp(self):
32+
self.state.shutdown = 0
2833

2934
@staticmethod
3035
def _make_sample_payload(TTL=default_ttl):
@@ -43,14 +48,6 @@ def test_calculate(self):
4348
class TestProofofwork(TestProofofworkBase):
4449
"""The main test case for proofofwork"""
4550

46-
@classmethod
47-
def tearDownClass(cls):
48-
import state
49-
state.shutdown = 0
50-
51-
def setUp(self):
52-
self.tearDownClass()
53-
5451
def _make_sample_data(self):
5552
payload = self._make_sample_payload()
5653
return payload, proofofwork.getTarget(
@@ -70,10 +67,8 @@ def test_calculate(self):
7067
pack('>Q', nonce) + payload, 2000, 2000,
7168
int(time.time()) + TTL - 3600))
7269

73-
import state
74-
7570
with self.assertRaises(StopIteration):
76-
state.shutdown = 1
71+
self.state.shutdown = 1
7772
proofofwork.calculate(payload, TTL)
7873

7974
def test_CPoW(self):

0 commit comments

Comments
 (0)