Skip to content

Commit

Permalink
Merge pull request #15 from coderefinery/rkdarst/end-to-end-tests
Browse files Browse the repository at this point in the history
Add end-to-end tests
  • Loading branch information
bast authored Aug 24, 2023
2 parents f4ca474 + e57b633 commit ecb5898
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/end-to-end-python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3

# This should be run from the main word-count directory, *not* the `tests/`
# directory.

import subprocess
import sys

# Run count.py using whatever Python we are using right now. Get the output as
# a string.
output = subprocess.check_output([sys.executable, 'statistics/count.py', 'data/abyss.txt']).decode()

# Split the string and confirm the expected lines are in there.
output = output.split('\n')
assert 'the 4044' in output
assert 'and 2807' in output
print("Success")
27 changes: 27 additions & 0 deletions tests/end-to-end-shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# This should be run from the main word-count directory, *not* the `tests/`
# directory.

# This is an end-to-end test of count.py. It runs the script and
# tests that a few lines are correct.

# Check that `the` appears 4044 times. The 'grep' command returns
# true if somethin is found that matches.
if python3 statistics/count.py data/abyss.txt | grep "the 4044" ; then
echo "Success: 'the' found correct number of times"
else
echo "Fail: 'the' not correct"
exit 1
fi


# Check that `and` appears 2807 times
if python3 statistics/count.py data/abyss.txt | grep "and 2807" ; then
echo "Success: 'and' found correct number of times"
else
echo "Fail: 'and' not correct"
exit 1
fi

echo "Success"

0 comments on commit ecb5898

Please sign in to comment.