Skip to content

Commit

Permalink
Merge pull request #21 from madnesspie/sync-context-manager
Browse files Browse the repository at this point in the history
Extends syncify_wrap for work with context methods
  • Loading branch information
madnesspie committed Jun 8, 2020
2 parents bce309a + c4e6b77 commit b3c3206
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion obm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = "0.0.19"
__version__ = "0.0.20"
11 changes: 9 additions & 2 deletions obm/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ def syncified(*args, **kwargs):
return coro
return loop.run_until_complete(coro)

def optional_rename(name):
return (
name.replace("a", "")
if name in ["__aenter__", "__aexit__"]
else name
)

# Save an accessible reference to the original method
syncified.asynchronous = method
setattr(_type, method_name, syncified)
setattr(_type, optional_rename(method_name), syncified)


def syncify(*types):
Expand All @@ -51,7 +58,7 @@ def syncify(*types):
"""
for _type in types:
for name in dir(_type):
if not name.startswith("_") or name == "__call__":
if not name.startswith("_") or name in ["__aexit__", "__aenter__"]:
# TODO: Move to __slots__
if inspect.iscoroutinefunction(getattr(_type, name)):
_syncify_wrap(_type, name)
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pytest]
addopts = -vs -r fEP --tb=short --maxfail=1
addopts = -vs -r fEP --tb=short
markers =
integration: Run integration tests with main test suite.
run-only: Run tests only for specified currency.
Expand Down
14 changes: 11 additions & 3 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def sync_node(request, sync_geth_node, sync_bitcoin_core_node):


@pytest.mark.integration
class TestIntegrationNode:
class TestNodeIntegration:
@staticmethod
def test_fetch_recent_transactions(node):
txs = node.fetch_recent_transactions(limit=5)
Expand All @@ -64,8 +64,8 @@ def test_get_latest_block_number(node):

@staticmethod
def test_create_address(node):
txs = node.create_address()
assert isinstance(txs, str)
addr = node.create_address()
assert isinstance(addr, str)

@staticmethod
def test_send_transaction(node):
Expand All @@ -84,3 +84,11 @@ def test_send_transaction(node):
tx = node.send_transaction(**tx_data[node.name])
assert isinstance(tx, dict)
assert serializers.Transaction().validate(tx) == {}


class TestNode:
@staticmethod
def test_sync_context_methods(node):
with node:
assert node.connector.session is not None
assert node.connector.session is None

0 comments on commit b3c3206

Please sign in to comment.