Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
z80dev committed Dec 6, 2023
1 parent 7a674b9 commit ae44ee9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ pytest = "^7.4.3"
[tool.poetry.scripts]
vyper-lsp = 'vyper_lsp.main:main'

[tool.coverage.run]
source = ["vyper_lsp"]
omit = ["vyper_lsp/analyzer/SourceAnalyzer.py",
"vyper_lsp/__init__.py",
"vyper_lsp/__main__.py",
]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
21 changes: 21 additions & 0 deletions tests/test_debouncer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import time
from vyper_lsp.debounce import Debouncer # Import Debouncer from your module


def test_debounce():
result = []

def test_function(arg):
result.append(arg)

debouncer = Debouncer(wait=0.5)
debounced_func = debouncer.debounce(test_function)

debounced_func("first call")
time.sleep(0.2) # Sleep for less than the debounce period
debounced_func("second call")
time.sleep(
0.6
) # Sleep for more than the debounce period to allow the function to execute

assert result == ["second call"]
16 changes: 16 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,19 @@ def test_get_expression_at_cursor():
assert utils.get_expression_at_cursor(text, 0) == "foo_bar"
assert utils.get_expression_at_cursor(text, 4) == "foo_bar"
assert utils.get_expression_at_cursor(text, 21) == "self.baz (1,2,3)"


def test_get_internal_fn_name_at_cursor():
text = "self.foo = 123"
assert utils.get_internal_fn_name_at_cursor(text, 0) is None
assert utils.get_internal_fn_name_at_cursor(text, 1) is None
assert utils.get_internal_fn_name_at_cursor(text, 5) is None
assert utils.get_internal_fn_name_at_cursor(text, 12) is None

text = "foo_bar = self.baz (1,2,3)"
assert utils.get_internal_fn_name_at_cursor(text, 0) is None
assert utils.get_internal_fn_name_at_cursor(text, 4) is None
assert utils.get_internal_fn_name_at_cursor(text, 21) == "baz"

text = "self.foo(self.bar())"
assert utils.get_internal_fn_name_at_cursor(text, 0) == "foo"
6 changes: 3 additions & 3 deletions vyper_lsp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ def get_expression_at_cursor(sentence: str, cursor_index: int) -> str:
def get_internal_fn_name_at_cursor(sentence: str, cursor_index: int) -> str:
# TODO: dont assume the fn call is at the end of the line
# REVIEW: make cases like self.foo(self.bar()) work
word = sentence.split("(")[0].split(" ")[-1].strip().split("self.")[-1]

return word
expression = get_expression_at_cursor(sentence, cursor_index)
if is_internal_fn(expression):
return expression.split(".")[1].split("(")[0].strip()


def extract_enum_name(line: str):
Expand Down

0 comments on commit ae44ee9

Please sign in to comment.