Skip to content

Commit

Permalink
python/word-count: 3rd iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Jun 26, 2023
1 parent 150b07f commit 2d68d4b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 51 deletions.
Binary file modified python/wordcount/.coverage
Binary file not shown.
27 changes: 14 additions & 13 deletions python/wordcount/.coverage.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?>
<coverage version="7.2.3" timestamp="1687762024091" lines-valid="15" lines-covered="15" line-rate="1" branches-valid="6" branches-covered="6" branch-rate="1" complexity="0">
<coverage version="7.2.3" timestamp="1687762285141" lines-valid="16" lines-covered="16" line-rate="1" branches-valid="6" branches-covered="6" branch-rate="1" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.2.3 -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
Expand All @@ -13,19 +13,20 @@
<lines>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="8" hits="1"/>
<line number="14" hits="1"/>
<line number="17" hits="1"/>
<line number="20" hits="1"/>
<line number="23" hits="1"/>
<line number="25" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="6" hits="1"/>
<line number="9" hits="1"/>
<line number="15" hits="1"/>
<line number="18" hits="1"/>
<line number="21" hits="1"/>
<line number="24" hits="1"/>
<line number="26" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="28" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="29" hits="1"/>
<line number="32" hits="1"/>
<line number="35" hits="1"/>
<line number="38" hits="1"/>
<line number="40" hits="1"/>
<line number="27" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="29" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="30" hits="1"/>
<line number="33" hits="1"/>
<line number="36" hits="1"/>
<line number="39" hits="1"/>
<line number="41" hits="1"/>
</lines>
</class>
</classes>
Expand Down
68 changes: 34 additions & 34 deletions python/wordcount/run-tests-python.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ Running automated test file(s):

Running: pylint --ignore-patterns (__init__|.*_test).py .

real 0m0.417s
user 0m0.344s
sys 0m0.074s
real 0m0.412s
user 0m0.348s
sys 0m0.066s

===============================================================================

Running: ruff check --ignore E501 ./__init__.py ./word_count.py ./word_count_test.py

real 0m0.064s
user 0m0.032s
sys 0m0.034s
user 0m0.030s
sys 0m0.036s

===============================================================================

Running: pyright --stats .
Found 3 source files
pyright 1.1.315
0 errors, 0 warnings, 0 informations
Completed in 0.715sec
Completed in 0.687sec

Analysis stats
Total files parsed and bound: 35
Expand All @@ -33,15 +33,15 @@ Timing stats
Find Source Files: 0sec
Read Source Files: 0.01sec
Tokenize: 0.05sec
Parse: 0.08sec
Resolve Imports: 0.05sec
Parse: 0.06sec
Resolve Imports: 0.04sec
Bind: 0.08sec
Check: 0.11sec
Detect Cycles: 0sec

real 0m1.627s
user 0m1.580s
sys 0m0.150s
real 0m1.309s
user 0m1.460s
sys 0m0.145s

===============================================================================

Expand All @@ -51,7 +51,7 @@ Running: bandit --verbose --recursive .
[main] INFO cli include tests: None
[main] INFO cli exclude tests: None
[main] INFO running on Python 3.11.3
Run started:2023-06-26 06:47:01.992774
Run started:2023-06-26 06:51:23.040683
Files in scope (3):
./__init__.py (score: {SEVERITY: 0, CONFIDENCE: 0})
./word_count.py (score: {SEVERITY: 0, CONFIDENCE: 0})
Expand All @@ -78,7 +78,7 @@ Test results:
No issues identified.

Code scanned:
Total lines of code: 122
Total lines of code: 123
Total lines skipped (#nosec): 0
Total potential issues skipped due to specifically being disabled (e.g., #nosec BXXX): 0

Expand All @@ -95,17 +95,17 @@ Run metrics:
High: 0
Files skipped (0):

real 0m0.235s
real 0m0.234s
user 0m0.184s
sys 0m0.052s
sys 0m0.051s

===============================================================================

Running: refurb .

real 0m1.320s
user 0m1.249s
sys 0m0.072s
real 0m1.312s
user 0m1.233s
sys 0m0.080s

===============================================================================

Expand Down Expand Up @@ -143,40 +143,40 @@ word_count_test.py::WordCountTest::test_with_quotations PASSED [100%]
---------- coverage: platform linux, python 3.11.3-final-0 -----------
Name Stmts Miss Branch BrPart Cover Missing
-----------------------------------------------------------
word_count.py 15 0 6 0 100%
word_count.py 16 0 6 0 100%
-----------------------------------------------------------
TOTAL 15 0 6 0 100%
TOTAL 16 0 6 0 100%
Coverage XML written to file .coverage.xml


============================== 17 passed in 0.05s ==============================

real 0m0.936s
user 0m0.829s
sys 0m0.108s
real 0m0.945s
user 0m0.832s
sys 0m0.113s

===============================================================================

Running: coverage report --show-missing
Name Stmts Miss Branch BrPart Cover Missing
-----------------------------------------------------------
word_count.py 15 0 6 0 100%
word_count.py 16 0 6 0 100%
-----------------------------------------------------------
TOTAL 15 0 6 0 100%
TOTAL 16 0 6 0 100%

real 0m0.145s
user 0m0.094s
sys 0m0.051s
real 0m0.147s
user 0m0.103s
sys 0m0.045s

===============================================================================

coverage annotate
The annotate command will be removed in a future version.
Get in touch if you still use it: ned@nedbatchelder.com

real 0m0.130s
user 0m0.096s
sys 0m0.034s
real 0m0.127s
user 0m0.080s
sys 0m0.047s

tail -n 10000 ./*,cover | grep -E -C 3 '^> def |^! '

Expand All @@ -187,9 +187,9 @@ tail -n 10000 ./*,cover | grep -E -C 3 '^> def |^! '

Running: misspell ./__init__.py ./word_count.py ./word_count_test.py

real 0m0.024s
user 0m0.023s
sys 0m0.011s
real 0m0.020s
user 0m0.026s
sys 0m0.005s

===============================================================================

5 changes: 3 additions & 2 deletions python/wordcount/word_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import re
from collections import defaultdict
from typing import Dict


Expand All @@ -11,7 +12,7 @@ def count_words(sentence: str) -> Dict[str, int]:
:param sentence: str - string we're going to count
:return: Dict[str, int] - current round and the two that follow.
"""
counts: Dict[str, int] = {}
counts: Dict[str, int] = defaultdict(int)

# remove surrounding quotes
sentence = sentence.strip("'")
Expand All @@ -35,6 +36,6 @@ def count_words(sentence: str) -> Dict[str, int]:
word = word.strip("'")

# increment the word count in the dictionary
counts[word] = 1 + counts.setdefault(word, 0)
counts[word] += 1

return counts
5 changes: 3 additions & 2 deletions python/wordcount/word_count.py,cover
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


> import re
> from collections import defaultdict
> from typing import Dict


Expand All @@ -11,7 +12,7 @@
> :param sentence: str - string we're going to count
> :return: Dict[str, int] - current round and the two that follow.
> """
> counts: Dict[str, int] = {}
> counts: Dict[str, int] = defaultdict(int)

# remove surrounding quotes
> sentence = sentence.strip("'")
Expand All @@ -35,6 +36,6 @@
> word = word.strip("'")

# increment the word count in the dictionary
> counts[word] = 1 + counts.setdefault(word, 0)
> counts[word] += 1

> return counts

0 comments on commit 2d68d4b

Please sign in to comment.