-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
160 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# IPython Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# dotenv | ||
.env | ||
|
||
# virtualenv | ||
venv/ | ||
ENV/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
|
||
# Rope project settings | ||
.ropeproject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,73 @@ | ||
**Author**: `Pahaz Blinov`_ | ||
|
||
**Repo**: https://github.com/pahaz/py3line/ | ||
**Repo**: https://github.com/pahaz/bashtest/ | ||
|
||
Pyline is a UNIX command-line tool for line-based processing | ||
in Python with regex and output transform features | ||
similar to grep, sed, and awk. | ||
BashTest is a UNIX command-line tool for bash/shell utils unit testing. | ||
|
||
This project inspired by: `piep`_, `pysed`_, `pyline`_, `pyp`_ and | ||
`Jacob+Mark recipe <https://code.activestate.com/recipes/437932-pyline-a-grep-like-sed-like-command-line-tool/>`_ | ||
This is a simplest way to write a simple bash tests. | ||
|
||
**requirements**: Python3 | ||
|
||
**WHY I MAKE IT?** | ||
|
||
I sometimes have to use `sed` / `awk`. | ||
Not often, and so I always forget the necessary options and `sed` / `awk` DSL. | ||
But I now python, I like it, and I want use it for data processing. | ||
Default `python -c` is hard to write the kind of one-liner that works well. | ||
|
||
Why not a `pyline`? | ||
* Don`t support python3 | ||
* Have many options (I want as much simple as possible solution) | ||
* Bad performance | ||
* Don`t support command chaining | ||
|
||
Why not a `pysed`? | ||
* | ||
**requirements**: Python2 or Python3 | ||
|
||
Installation | ||
============ | ||
|
||
`py3line`_ is on PyPI, so simply run: | ||
`bashtest`_ is on PyPI, so simply run: | ||
|
||
:: | ||
|
||
pip install py3line | ||
pip install bashtest | ||
|
||
or :: | ||
|
||
easy_install py3line | ||
easy_install bashtest | ||
|
||
to have it installed in your environment. | ||
|
||
For installing from source, clone the | ||
`repo <https://github.com/pahaz/py3line>`_ and run:: | ||
`repo <https://github.com/pahaz/bashtest>`_ and run:: | ||
|
||
python setup.py install | ||
|
||
Usage scenarios | ||
=============== | ||
If you don`t have `pip` you can `install it <https://pip.pypa.io/en/stable/installing/#installation>`_ | ||
|
||
Typical use case | ||
================ | ||
|
||
You write a text processed util or script and you want to test it. | ||
|
||
For example, we want test `ls` util. | ||
|
||
All of we need is create `test_ls.bashtest` file:: | ||
|
||
$ ls ./testsuit/list-directory | ||
file1 | ||
file2.txt | ||
file3.py | ||
file4.sh | ||
|
||
and then run tests :: | ||
|
||
... | ||
$ python -m bashtest test_ls.bashtest | ||
1 items passed all tests: | ||
1 tests in test_ls.bashtest | ||
1 tests in 1 items. | ||
1 passed and 0 failed. | ||
Test passed. | ||
|
||
Examples | ||
-------- | ||
Test README examples | ||
==================== | ||
|
||
Example 1: create spreadsheet | ||
============================= | ||
You have a some open source project like this. And of course, as in any good | ||
open source project, you have examples. You can automatically check this | ||
examples. Just add `python -m bashtest README.rst` in your CI tests. | ||
|
||
.. code-block:: bash | ||
More examples | ||
============= | ||
|
||
$ echo -e "Here are\nsome\nwords for you." | ./py3line.py "x.split()" -a "len(x)" | ||
2 | ||
1 | ||
3 | ||
You can finde some examples in this project. Please check `test_*.bashtest` | ||
files | ||
|
||
DOCS | ||
---- | ||
|
||
.. _Pahaz Blinov: https://github.com/pahaz/ | ||
.. _py3line: https://pypi.python.org/pypi/py3line/ | ||
.. _pyp: https://pypi.python.org/pypi/pyp/ | ||
.. _piep: https://github.com/timbertson/piep/tree/master/piep/ | ||
.. _pysed: https://github.com/dslackw/pysed/blob/master/pysed/main.py | ||
.. _pyline: https://github.com/westurner/pyline/blob/master/pyline/pyline.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
$ ls ./testsuit/list-directory | ||
file1 | ||
file2.txt | ||
file3.py | ||
file4.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
$ ls -lah ./testsuit/list-directory | awk {'print $1"\t"$2"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9'} | ||
total 32 | ||
drwxr-xr-x 6 204B Jul 20 07:45 . | ||
drwxr-xr-x 4 136B Jul 23 12:29 .. | ||
-rw-r--r-- 1 12B Jul 20 07:44 file1 | ||
-rw-r--r-- 1 257B Jul 20 07:45 file2.txt | ||
-rw-r--r-- 1 24B Jul 20 07:43 file3.py | ||
-rw-r--r-- 1 28B Jul 20 07:43 file4.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
$ cat ./testsuit/nginx.log | cut -f3 -d ' ' | sort | uniq -c | sort -g -r | ||
5 92.248.130.149 | ||
3 50.112.95.211 | ||
3 109.173.101.89 | ||
2 54.251.34.67 | ||
2 54.248.250.232 | ||
2 184.73.237.85 | ||
1 54.247.188.179 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
$ cat ./testsuit/list-directory/file1 | ||
line1 | ||
line2 | ||
|
||
$ cat ./testsuit/list-directory/file1 | wc -l | ||
2 | ||
|
This file was deleted.
Oops, something went wrong.