(core) Fix updating attributes inside f-strings when columns are renamed

Summary: Upgrades asttokens and uses the newly released support for astroid trees in `asttokens.ASTText` which is needed to deal with f-strings (as opposed to `asttokens.ASTTokens`).

Test Plan: Added a Python unit test

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D4027
This commit is contained in:
Alex Hall
2023-09-07 12:01:42 +02:00
parent 8644f346af
commit 525613216c
4 changed files with 29 additions and 10 deletions

View File

@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
import logging
import unittest
import six
import testutil
import test_engine
@@ -78,6 +81,20 @@ class TestRenames(test_engine.EngineTestCase):
}]
]})
@unittest.skipUnless(six.PY3, "Python 3 only")
def test_rename_inside_fstring(self):
self.load_sample(self.sample)
self.add_column("People", "CityUpper", formula="f'{$city.upper()}'")
out_actions = self.apply_user_action(["RenameColumn", "People", "city", "ciudad"])
self.assertPartialOutActions(out_actions, { "stored": [
["RenameColumn", "People", "city", "ciudad"],
["ModifyColumn", "People", "CityUpper", {"formula": "f'{$ciudad.upper()}'"}],
["BulkUpdateRecord", "_grist_Tables_column", [24, 25], {
"colId": ["ciudad", "CityUpper"],
"formula": ["$addr.city", "f'{$ciudad.upper()}'"]
}]
]})
def test_rename_reference_attribute(self):
# Slightly harder: renaming `$ref.COLUMN`
self.load_sample(self.sample)