Skip to content

Commit

Permalink
Adding test and example and update README.md (#3)
Browse files Browse the repository at this point in the history
* test:adding test and example

* docs: update README.md
  • Loading branch information
touero authored Dec 5, 2023
1 parent 47f99db commit 11541e0
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 15 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ if __name__ == '__main__':
easier_docker = EasierDocker(config)
easier_docker.start()
"""
>>> 2023-11-27 14:40:29,264 - INFO - easier-docker ==> Find docker image: [python:3.9] locally...:
>>> 2023-11-27 14:40:29,280 - INFO - easier-docker ==> Image: [python:3.9] is found locally
>>> 2023-11-27 14:40:29,280 - INFO - easier-docker ==> Find docker container: [python_test] locally...:
>>> 2023-11-27 14:40:29,284 - INFO - easier-docker ==> ContainerNotFound: [python_test], it will be created
>>> 2023-11-27 14:40:29,558 - INFO - easier-docker ==> Container name: [python_test] is running
>>> 2023-11-27 14:40:29,558 - INFO - easier-docker ==> Container id: [58509ced60ba] is running
>>> 2023-11-27 14:40:29,559 - INFO - easier-docker ==> Successfully container is running and be created at 2023-11-27T06:40:29.291320745Z
>>> 2023-12-05 21:02:04,327 - INFO - easier-docker ==> Find docker image: [python:3.9] locally...
>>> 2023-12-05 21:02:04,330 - INFO - easier-docker ==> Image: [python:3.9] is found locally
>>> 2023-12-05 21:02:04,330 - INFO - easier-docker ==> Find docker container: [python_test] locally...
>>> 2023-12-05 21:02:04,332 - INFO - easier-docker ==> ContainerNotFound: [python_test], it will be created
>>> 2023-12-05 21:02:04,568 - INFO - easier-docker ==> Container name: [python_test] is running
>>> 2023-12-05 21:02:04,568 - INFO - easier-docker ==> Container id: [50e5ae686a9f] is running
>>> 2023-12-05 21:02:04,568 - INFO - easier-docker ==> Container ip address: []
>>> 2023-12-05 21:02:04,568 - INFO - easier-docker ==> Successfully container is running and be created at 2023-12-05T13:02:04.344804339Z
"""
```
The content of docker_example.py is
Expand Down Expand Up @@ -85,7 +86,7 @@ The content of config.yaml is
image: python:3.9
name: python_test
volumes:
/Users/admin/data/code_project/easier-docker/tests:
/Users/admin/data/code_project/easier-docker/example:
bind: /path/to/container
mode: rw
detach: true
Expand All @@ -97,10 +98,10 @@ command:
```


| |
|--------------------------------------------------------------------------------------------------------|
| ![containers.png](https://github.com/weiensong/easier-docker/blob/master/image/containers.png) |
| ![containers_log.png](https://github.com/weiensong/easier-docker/blob/master/image/containers_log.png) |
| |
|-----------------------------------------------------------------------------------------------------|
| ![container.png](https://github.com/weiensong/easier-docker/blob/master/image/container.png) |
| ![container_log.png](https://github.com/weiensong/easier-docker/blob/master/image/container_log.png)|


## Related
Expand All @@ -120,14 +121,14 @@ Building a Basic Information API for Chinese National Universities in the Handhe


## Contributing
[Open an issue](https://github.com/weiensong/easier_docker/issues) or submit PRs.
[Open an issue](https://github.com/weiensong/easier_docker/issues) or submit PRs.
Standard Python follows the [Python PEP-8](https://peps.python.org/pep-0008/) Code of Conduct.


### Contributors
This project exists thanks to all the people who contribute.

<a href="https://github.com/weiensong/carp/graphs/contributors">
<a href="https://github.com/touero/easier-docker/graphs/contributors">
<img src="https://contrib.rocks/image?repo=weiensong/easier_docker" alt=""/>
</a>

Expand Down
12 changes: 12 additions & 0 deletions example/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# config.yaml
image: python:3.9
name: python_test
volumes:
/Users/weiensong/data/code_project/easier-docker/example:
bind: /path/to/container
mode: rw
detach: true
command:
- sh
- -c
- cd /path/to/container && python docker_example.py
File renamed without changes.
3 changes: 2 additions & 1 deletion tests/example.py → example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from easierdocker import EasierDocker

if __name__ == '__main__':
host_script = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(os.getcwd())
host_script = os.path.join(parent_dir, 'example')
container_script = '/path/to/container'
config = {
'image': 'python:3.9',
Expand Down
Binary file added image/container.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/container_log.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed image/containers.png
Binary file not shown.
Binary file removed image/containers_log.png
Binary file not shown.
43 changes: 43 additions & 0 deletions tests/test_easier_docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import unittest

from easierdocker import EasierDocker


class TestEasierDocker(unittest.TestCase):
def test_init(self):
parent_dir = os.path.dirname(os.getcwd())
host_script = os.path.join(parent_dir, 'example')
container_script = '/path/to/container'
config = {
'image': 'python:3.9',
'name': 'python_test',
'volumes': {
f'{host_script}': {'bind': container_script, 'mode': 'rw'}
},
'detach': True,
'command': ["sh", "-c", f'cd {container_script} &&'
'python docker_example.py'],
}
test_config = {
'image': 'python:3.9',
'name': 'python_test',
'volumes': {
'/Users/weiensong/data/code_project/easier-docker/example': {
'bind': container_script, 'mode': 'rw'
}
},
'detach': True,
'command': ["sh", "-c", f'cd {container_script} &&'
'python docker_example.py'],
}
easier_docker = EasierDocker(config)
self.assertEqual(easier_docker.config, test_config)
self.assertEqual(easier_docker.image_name, 'python:3.9')
self.assertEqual(easier_docker.container_name, 'python_test')

def test_get_image(self):
...

def test_get_container(self):
...

0 comments on commit 11541e0

Please sign in to comment.