Skip to content

Commit

Permalink
refactor component (#5)
Browse files Browse the repository at this point in the history
* test: fix wrong name for test_get_children

* refactor: change .get() for direct get value by dict key

* refactor: fix trailing commas

* ci: ignore some flake8 cheking for easy easy code reading

This change is intended to make it easier for those who are completely beginners in programming to understand the code

* docs: fix README.md regardnig doctest errors

Co-authored-by: Sergey Karpuk <[email protected]>
  • Loading branch information
AABur and zhabinka authored Jan 25, 2022
1 parent 992df58 commit f6560bd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pip install hexlet-immutable-fs-trees
## Usage example

```python

>>> import hexlet.fs as fs
>>> fs.is_file(fs.mkfile('config'))
True
Expand Down
14 changes: 7 additions & 7 deletions src/hexlet/fs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def mkfile(name, meta={}):
return {
'name': name,
'meta': meta,
'type': 'file'
'type': 'file',
}


Expand All @@ -21,33 +21,33 @@ def mkdir(name, children=[], meta={}):
'name': name,
'children': children,
'meta': meta,
'type': 'directory'
'type': 'directory',
}


def is_directory(node):
"""Check is node a directory."""
return node.get('type') == 'directory'
return node['type'] == 'directory'


def is_file(node):
"""Check is node a file."""
return node.get('type') == 'file'
return node['type'] == 'file'


def get_children(directory):
"""Return children of node."""
return directory.get('children')
return directory.get('children', [])


def get_meta(node):
"""Return meta of node."""
return node.get('meta')
return node['meta']


def get_name(node):
"""Return name of node."""
return node.get('name')
return node['name']


def flatten(tree):
Expand Down
9 changes: 5 additions & 4 deletions test/test_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ def test_build():
'children': [],
'meta': {},
'name': 'etc',
'type': 'directory'
'type': 'directory',
},
{
'children': [],
'meta': {},
'name': 'usr',
'type': 'directory'},
'type': 'directory',
},
{
'meta': {},
'name': 'robots.txt',
'type': 'file'
'type': 'file',
},
],
'meta': {},
Expand All @@ -56,7 +57,7 @@ def test_get_meta2():
assert fs.get_meta(file).get('owner') == 'root'


def test_get_meta3():
def test_get_children():
file = fs.mkfile('robots.txt')
dir = fs.mkdir('/')
tree = fs.mkdir('/', [
Expand Down

0 comments on commit f6560bd

Please sign in to comment.