Skip to content

Commit 3b23e5b

Browse files
authored
Sets max characters to 7000 (#7)
* Test to check files over the max characters * Added logging for file length
1 parent 8e7d8ab commit 3b23e5b

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

.github/workflows/test.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ jobs:
5555
matrix:
5656
python-version: [3.6, 3.7, 3.8]
5757
os: [ubuntu-latest]
58-
5958
steps:
6059
- uses: actions/checkout@v2
6160
- name: Set up Python ${{ matrix.python-version }}
@@ -70,3 +69,26 @@ jobs:
7069
run: |
7170
python3 -m ${{ env.name }} --help
7271
python3 -m ${{ env.name }} "${{secrets.GRAMMARBOT_APIKEY}}" samples/example.txt
72+
api-length-check:
73+
name: 'Checks the max chars in the CLI thousands:'
74+
runs-on: ubuntu-latest
75+
strategy:
76+
max-parallel: 3
77+
fail-fast: false
78+
matrix:
79+
text-length-thousands: [2, 5, 7, 8, 9, 10]
80+
steps:
81+
- uses: actions/checkout@v2
82+
- name: Set up Python
83+
uses: actions/setup-python@v2
84+
with:
85+
python-version: 3.9
86+
- name: Install dependencies
87+
run: |
88+
python3 -m pip install --upgrade pip
89+
python3 -m pip install -r requirements.txt
90+
- name: Run the cli with large files
91+
run: |
92+
python3 -c 'print(open("./samples/long_1000c.txt", "r").read()*${{ matrix.text-length-thousands }})' > test.txt
93+
wc -c test.txt
94+
python3 -m ${{ env.name }} --log INFO "${{secrets.GRAMMARBOT_APIKEY}}" test.txt

hemoglobin/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
from getpass import getpass
33
from json import dumps as json_dumps
4+
import logging
45

56
from .hemoglobin import Hemoglobin, Config
67
from .grammarbot import Language as Languages
@@ -30,6 +31,7 @@ def create_args():
3031
type=Languages,
3132
default=Languages.EN_US,
3233
)
34+
parser.add_argument("--log", dest="log_level", help="Log level.", default="warning")
3335

3436
parser.add_argument("path", help="Where to find these files to parse.", nargs="+")
3537
return parser
@@ -61,6 +63,7 @@ def render_json(hemoglobin):
6163

6264
if __name__ == "__main__":
6365
args = create_args().parse_args()
66+
logging.basicConfig(level=args.log_level.upper())
6467
hemoglobin = Hemoglobin.from_config(Config.from_args(args))
6568
if args.use_json_output:
6669
render_json(hemoglobin)

hemoglobin/files.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import warnings
2+
import logging
23

34

45
class HemoglobinFile(object):
@@ -50,6 +51,11 @@ def matches(self):
5051
return self.response.matches
5152

5253
def get_grammarbot_response(self):
54+
logging.info(
55+
"Length of file {file_name} is {file_length}".format(
56+
file_name=self.f.name, file_length=len(self.text),
57+
)
58+
)
5359
if len(self.text) > self.hemoglobin.grammarbot.MAX_CHARS:
5460
warnings.warn(
5561
"File '{file_path}' is {file_length} characters log, and over {max_chars} characters the GrammarBot API allows. The contents of the file will be broken up to be processed.".format(

hemoglobin/grammarbot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def to_dict(self):
4141

4242
class HemoglobinGrammarBot(GrammarBotClient):
4343
API_RESPONSE = HemoglobinGrammarBotApiResponse
44-
MAX_CHARS = 10000
44+
MAX_CHARS = 7000
4545

4646
def __init__(
4747
self,

samples/long_1000c.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nisl dui, tincidunt vel faucibus vitae, tincidunt ut lorem. Curabitur consequat semper justo, non cursus tortor consequat eget. Praesent tortor lorem, interdum eu elementum feugiat, mollis sit amet lacus. Quisque eget lacus sit amet massa posuere luctus non vitae nibh. Nulla a metus et nisl volutpat viverra eget quis neque. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Suspendisse ut lacus vulputate, eleifend leo in, vulputate ante. Nulla eget magna et e scelerisque malesuada ac at mauris. Sed quis felis ut diam vulputate semper ut ut enim. In posuere lacinia orci, tempus rhoncus ipsum dapibus in. Nulla facilisi. Vestibulum rutrum nisl odio, a dapibus est elementum vel. Fusce non ante sit amet felis dignissim convallis et sit amet nunc. Vestibulum porta justo vitae dignissim cursus. Praesent rhoncus id nisl ac aliquet. Etiam felis, molestie a purus in, vestibulum pellentesque diam.

0 commit comments

Comments
 (0)