Skip to content

Commit

Permalink
add hashFile
Browse files Browse the repository at this point in the history
  • Loading branch information
Orasund committed Mar 31, 2024
1 parent edb5e5f commit be9ca01
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# cli-tools
toy project for learning different languages

This project is meant to have a set of projects that can be implemented in different languages. The projects are practical and use eachother.

## Projects

1. hashFile - hash the content of a file
2 changes: 2 additions & 0 deletions hashFile/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
venv
.pytest_cache
21 changes: 21 additions & 0 deletions hashFile/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Hashfile

## Installation

```
python3 -m venv venv
pip install -r requirements.txt
```

## Run

```
source venv/bin/activate
bash run.sh
```

## Test

```
bash test.sh
```
2 changes: 2 additions & 0 deletions hashFile/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
click
1 change: 1 addition & 0 deletions hashFile/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python src/__init__.py $1
Empty file added hashFile/src/__init__.py
Empty file.
Binary file added hashFile/src/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added hashFile/src/__pycache__/hashFile.cpython-311.pyc
Binary file not shown.
14 changes: 14 additions & 0 deletions hashFile/src/hashFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from io import BufferedReader
import click
import hashlib

@click.command()
@click.argument("filepath")
def hashFile(filepath:click.File):
"""Hash the content of the file"""
f = open(filepath, "rb").read()
hash = hashlib.sha256(f).hexdigest()
click.echo(hash)

if __name__ == '__main__':
hashFile()
1 change: 1 addition & 0 deletions hashFile/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest tests/
Empty file added hashFile/tests/__init__.py
Empty file.
Binary file added hashFile/tests/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions hashFile/tests/test_hashFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from click.testing import CliRunner
from src.hashFile import hashFile

def test():
runner = CliRunner()
result = runner.invoke(hashFile, ['tests/trivial/input'])
assert result.output == open('tests/trivial/output', "r").read() + "\n"
1 change: 1 addition & 0 deletions hashFile/tests/trivial/input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World
1 change: 1 addition & 0 deletions hashFile/tests/trivial/output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e

0 comments on commit be9ca01

Please sign in to comment.