зеркало из https://github.com/microsoft/dpu-utils.git
Start unit testing (#6)
Add unit tests for identifier splitting along with instructions on how to run tests.
This commit is contained in:
Родитель
3f2ce098a6
Коммит
63030ddf54
|
@ -269,4 +269,9 @@ ModelManifest.xml
|
|||
/dist/
|
||||
|
||||
# Python egg metadata, regenerated from source files by setuptools.
|
||||
/*.egg-info
|
||||
/*.egg-info
|
||||
.eggs/
|
||||
|
||||
# Files generated by Coverage.py.
|
||||
.coverage
|
||||
htmlcov/
|
||||
|
|
18
README.md
18
README.md
|
@ -28,6 +28,24 @@ Code-related Utilities
|
|||
* `dpu_utils.codeutils.split_identifier_into_parts` split identifiers into subtokens on CamelCase and snake_case.
|
||||
* `dpu_utils.codeutils.{Lattice, CSharpLattice}` represent lattices and some useful operations in Python.
|
||||
|
||||
## Tests
|
||||
|
||||
### Run the unit tests
|
||||
|
||||
```bash
|
||||
python setup.py test
|
||||
```
|
||||
|
||||
### Generate code coverage reports
|
||||
|
||||
```bash
|
||||
# pip install coverage
|
||||
coverage run --source dpu_utils/ setup.py test && \
|
||||
coverage html
|
||||
```
|
||||
|
||||
The resulting HTML file will be in `htmlcov/index.html`.
|
||||
|
||||
# Contributing
|
||||
|
||||
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
||||
|
|
1
setup.py
1
setup.py
|
@ -11,4 +11,5 @@ setuptools.setup(
|
|||
install_requires=[
|
||||
'azure-storage', 'numpy'
|
||||
],
|
||||
test_suite="tests",
|
||||
zip_safe=False)
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import unittest
|
||||
import dpu_utils.codeutils.identifiersplitting as split
|
||||
|
||||
class TestSplitCamelCase(unittest.TestCase):
|
||||
def run_test(self, identifier, expected):
|
||||
actual = split.split_camelcase(identifier)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_empty_string_returns_empty_list(self):
|
||||
self.run_test("", [])
|
||||
|
||||
def test_single_word_is_not_split(self):
|
||||
self.run_test("variable", ["variable"])
|
||||
|
||||
def test_two_words_are_split(self):
|
||||
self.run_test("camelCase", ["camel", "Case"])
|
||||
|
||||
def test_three_words_are_split(self):
|
||||
self.run_test("camelCaseIdentifier", ["camel", "Case", "Identifier"])
|
||||
|
||||
def test_upper_camelcase_is_split(self):
|
||||
self.run_test("CamelCase", ["Camel", "Case"])
|
||||
|
||||
def test_abbreviations_are_split_correctly(self):
|
||||
self.run_test("HTMLParser", ["HTML", "Parser"])
|
||||
|
||||
def test_digits_are_split(self):
|
||||
self.run_test("var12var3", ["var", "12", "var", "3"])
|
||||
|
||||
def test_special_characters_are_split(self):
|
||||
self.run_test("@var-$var", ["@", "var", "-$", "var"])
|
Загрузка…
Ссылка в новой задаче