|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""tests for classify.py""" |
| 3 | + |
| 4 | +import os |
| 5 | +import random |
| 6 | +import re |
| 7 | +import string |
| 8 | +from subprocess import getstatusoutput |
| 9 | + |
| 10 | +prg = './classify.py' |
| 11 | + |
| 12 | + |
| 13 | +# -------------------------------------------------- |
| 14 | +def test_exists(): |
| 15 | + """exists""" |
| 16 | + |
| 17 | + assert os.path.isfile(prg) |
| 18 | + |
| 19 | + |
| 20 | +# -------------------------------------------------- |
| 21 | +def test_usage(): |
| 22 | + """usage""" |
| 23 | + |
| 24 | + for flag in ['-h', '--help']: |
| 25 | + rv, out = getstatusoutput(f'{prg} {flag}') |
| 26 | + assert rv == 0 |
| 27 | + assert out.lower().startswith('usage') |
| 28 | + |
| 29 | + |
| 30 | +# -------------------------------------------------- |
| 31 | +def test_upper(): |
| 32 | + """upper""" |
| 33 | + |
| 34 | + word = random.choice('APPLE BANANA CHERRY'.split()) |
| 35 | + rv, out = getstatusoutput(f'{prg} {word}') |
| 36 | + assert rv == 0 |
| 37 | + assert out == f'{word} is uppercase.' |
| 38 | + |
| 39 | + |
| 40 | +# -------------------------------------------------- |
| 41 | +def test_lower(): |
| 42 | + """lower""" |
| 43 | + |
| 44 | + word = random.choice('apple banana cherry'.split()) |
| 45 | + rv, out = getstatusoutput(f'{prg} {word}') |
| 46 | + assert rv == 0 |
| 47 | + assert out == f'{word} is lowercase.' |
| 48 | + |
| 49 | + |
| 50 | +# -------------------------------------------------- |
| 51 | +def test_title(): |
| 52 | + """title""" |
| 53 | + |
| 54 | + word = random.choice('Apple Banana Cherry'.split()) |
| 55 | + rv, out = getstatusoutput(f'{prg} {word}') |
| 56 | + assert rv == 0 |
| 57 | + assert out == f'{word} is title case.' |
| 58 | + |
| 59 | + |
| 60 | +# -------------------------------------------------- |
| 61 | +def test_digit(): |
| 62 | + """digit""" |
| 63 | + |
| 64 | + word = random.choice('1 2 3'.split()) |
| 65 | + rv, out = getstatusoutput(f'{prg} {word}') |
| 66 | + assert rv == 0 |
| 67 | + assert out == f'{word} is a digit.' |
| 68 | + |
| 69 | + |
| 70 | +# -------------------------------------------------- |
| 71 | +def test_space(): |
| 72 | + """space""" |
| 73 | + |
| 74 | + word = random.choice([' ', '\t']) |
| 75 | + rv, out = getstatusoutput(f'{prg} "{word}"') |
| 76 | + assert rv == 0 |
| 77 | + assert out == f'input is space.' |
| 78 | + |
| 79 | + |
| 80 | +# -------------------------------------------------- |
| 81 | +def test_unclassified(): |
| 82 | + """unclassified""" |
| 83 | + |
| 84 | + word = random.choice('1.2 3.04 40.5'.split()) |
| 85 | + rv, out = getstatusoutput(f'{prg} "{word}"') |
| 86 | + assert rv == 0 |
| 87 | + assert out == f'{word} is unclassified.' |
0 commit comments