Skip to content

Commit

Permalink
fam
Browse files Browse the repository at this point in the history
  • Loading branch information
latentvector committed Jun 14, 2024
1 parent f314247 commit e940167
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 23 deletions.
4 changes: 3 additions & 1 deletion commune/module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -6366,7 +6366,9 @@ def fn_generator(*args, fn, module, **kwargs):
'my_stake_from',
'my_stake_to',
'stake_many',
'transfer_many', 'send' ],
'transfer_many',
'module_info', 'minfo',
'send' ],
'namespace': [
'add_remote',
'networks',
Expand Down
7 changes: 0 additions & 7 deletions commune/subspace/subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,6 @@ def subnet_params(self,

for f in c.as_completed(future2name, timeout=timeout):
result = f.result()
c.print(result)
subnet_params[future2name.pop(f)] = result
for k in value_features:
subnet_params[k] = self.format_amount(subnet_params[k], fmt=fmt)
Expand Down Expand Up @@ -1072,14 +1071,8 @@ def global_params(self,
subnet_params[k] = self.format_amount(subnet_params[k], fmt=fmt)
return subnet_params



subnet = subnet_params





def subnet2params( self, block: Optional[int] = None ) -> Optional[float]:
netuids = self.netuids()
subnet2params = {}
Expand Down
24 changes: 12 additions & 12 deletions commune/subspace/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@

class Test(c.Module):

def __init__(self, network='test', **kwargs):
self.subspace = c.module('subspace')(network=network, **kwargs)

def test_global_params(self):
global_params = c.global_params(fmt='dict')
global_params = self.subspace.global_params(fmt='dict')
assert isinstance(global_params, dict)

def test_subnet_params(self, netuid=0):
subnet_params = c.subnet_params(netuid=0)
subnet_params = self.subspace.subnet_params(netuid=0)
assert isinstance(subnet_params, dict)
subnet_params_all = c.subnet_params(netuid='all')
subnet_params_all = self.subspace.subnet_params(netuid='all')
for netuid in subnet_params_all:
assert isinstance(subnet_params_all[netuid], dict)
assert isinstance(netuid, int)
subnet_names = c.subnet_names()
subnet_names = self.subspace.subnet_names()
assert isinstance(subnet_names, list) and len(subnet_names) > 0
subnet2netuid = c.subnet2netuid()
subnet2netuid = self.subspace.subnet2netuid()
assert isinstance(subnet2netuid, dict) and len(subnet2netuid) > 0
namespace = self.namespace(netuid=netuid)
namespace = self.subspace.namespace(netuid=netuid)
assert isinstance(namespace, dict)

return {'msg': 'subnet_params test passed', 'success': True}



def test_module_params(self, keys=['dividends', 'incentive'], netuid=0):
self = c.module('subspace')()
key = self.keys(update=1, netuid=netuid)[0]
module_info = self.get_module(key, netuid=netuid)
key = self.subspace.keys(update=1, netuid=netuid)[0]
module_info = self.subspace.get_module(key, netuid=netuid)
assert isinstance(module_info, dict)
for k in keys:
assert k in module_info, f'{k} not in {module_info}'
Expand All @@ -44,7 +44,7 @@ def test_substrate(self):


def test_global_storage(self):
global_params = self.global_params(fmt='j')
global_params = self.subspace.global_params(fmt='j')
assert isinstance(global_params, dict)
return global_params

Expand Down
8 changes: 5 additions & 3 deletions commune/tree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def tree(cls,
include_root = False,
verbose = True,
cache = True,
save = True,
**kwargs
) -> List[str]:
tree = {}
Expand All @@ -86,7 +87,7 @@ def tree(cls,
cache_path = path.split('/')[-1]
# the tree is cached in memory to avoid repeated reads from storage
# if the tree is in the cache and the max_age is not None, we want to check the age of the cache
use_tree_cache = bool(cache and cache_path in cls.tree_cache and not update)
use_tree_cache = bool(cache and cache_path in cls.tree_cache) and not update
if use_tree_cache:
tree_data = cls.tree_cache[cache_path]
assert all([k in tree_data for k in ['data', 'timestamp']]), 'Invalid tree cache'
Expand All @@ -104,9 +105,9 @@ def tree(cls,
# if the tree is not in the storage cache, we want to build it and store it
mode = 'build'
tree = cls.build_tree(path)
if cache:
cls.tree_cache[cache_path] = {'data': tree, 'timestamp': timestamp}
cls.tree_cache[cache_path] = {'data': tree, 'timestamp': timestamp}
cls.put(cache_path, tree)

assert mode != None, 'Invalid mode'
if search != None:
tree = {k:v for k,v in tree.items() if search in k}
Expand All @@ -118,6 +119,7 @@ def tree(cls,
c.print(f'Tree path={path} latency={latency}, n={len(tree)} mode={mode}', color='cyan')
return tree


@classmethod
def local_tree(cls, **kwargs):
return cls.build_tree(c.pwd(), **kwargs)
Expand Down
24 changes: 24 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Testing on Commune

Requirements
- pytest

Install pytest

```
pip install pytest
```

Here is the testing suite. Look at the modules that are being tested in the core repo, each has their own testing sweet or even a module that is suffixed with test.

For instance

```
c server.test/test is the same as c server/test
```

To test it

```
pytest test
```
2 changes: 2 additions & 0 deletions commune/tests/test_commune.py → test/test_commune.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

import pytest
import commune as c


def test_key():
c.module('key').test()
def test_ticket():
Expand Down

0 comments on commit e940167

Please sign in to comment.