Skip to content

Commit

Permalink
python regexp fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailbayram committed Dec 25, 2023
1 parent ebd2f4a commit bad2545
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
16 changes: 16 additions & 0 deletions internal/browser/pyproject/baskets/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,19 @@ def complete_basket(self, basket):
basket.save()

return basket

def _create_quotation_items(self, quotation: Quotation | Order, basket_items: list[BasketItem]) -> None:
QuotationItem.objects.bulk_create(
[
QuotationItem(
quotation=quotation,
product_remote_id=bi.product_remote_id,
quantity=bi.quantity,
division=bi.division,
price=bi.price,
data=bi.data,
currency=bi.currency,
)
for bi in basket_items
]
)
2 changes: 1 addition & 1 deletion internal/browser/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (b *PythonBrowser) findFunctions(fileContent string) map[string]string {
functions := make(map[string]string)

lines := strings.Split(fileContent, "\n")
functionRegex := regexp.MustCompile(`^\s*def\s+(\w+)\s*\((.*?)\):`)
functionRegex := regexp.MustCompile(`def\s+([a-zA-Z_]\w*)\s*\(([^)]*)\)\s*(?:->\s*([a-zA-Z_]\w*|\w*))?:`)

var currentFunctionName string
var currentFunctionContent string
Expand Down
21 changes: 11 additions & 10 deletions internal/browser/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,19 @@ func TestPythonBrowser_ParseFile(t *testing.T) {
assert.Equal(t, "/cars/exceptions.py", node.ImportRaw[7])
assert.Equal(t, "/cars", node.ImportRaw[8])

assert.Equal(t, 143, node.LineCount)
assert.Equal(t, 159, node.LineCount)

assert.Equal(t, 8, len(node.Functions))
assert.Equal(t, 9, len(node.Functions))
funcs := map[string]int{
"get_or_create_basket": 16,
"apply_discounts": 15,
"_check_basket_items": 17,
"add_basket_item": 22,
"clean_discounts": 7,
"clean_basket": 7,
"delete_basket_item": 7,
"complete_basket": 19,
"get_or_create_basket": 16,
"apply_discounts": 15,
"_check_basket_items": 17,
"add_basket_item": 22,
"clean_discounts": 7,
"clean_basket": 7,
"delete_basket_item": 7,
"complete_basket": 19,
"_create_quotation_items": 14,
}
for _, f := range node.Functions {
assert.Equal(t, funcs[f.Name], f.LineCount, f.Name)
Expand Down

0 comments on commit bad2545

Please sign in to comment.