Skip to content

Commit

Permalink
Merge pull request #2800 from HelioGuilherme66/misc_bugs
Browse files Browse the repository at this point in the history
Fix unit tests
  • Loading branch information
HelioGuilherme66 authored Jun 9, 2024
2 parents 7f3938a + 7ae2f55 commit cc977a5
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/robotide/controller/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def load_data(self, path, load_observer=None):
try:
robot_version = APP.robot_version
except AttributeError:
robot_version = '3.1.2' # It is failing at unit tests
robot_version = '7.0.1' # It is failing at unit tests
print(f"DEBUG: project.py Project load_data robot version = {robot_version}")
from ..lib.compat.parsing.language import check_file_language
self.file_language = check_file_language(path)
Expand Down
29 changes: 16 additions & 13 deletions utest/controller/test_occurrences.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


def TestCaseControllerWithSteps(project=None, source='some_suite.robot'):
tcf = TestCaseFile()
tcf = TestCaseFile(language=['English'])
tcf.source = source
tcf.setting_table.suite_setup.name = 'Suite Setup Kw'
tcf.setting_table.test_setup.name = SUITE_TEST_SETUP_KEYWORD
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_finding_from_keyword_teardown(self):
self._assert_usage('Keyword Teardown Keyword', 'Teardown')

def test_finding_from_test_teardown_in_settings(self):
self._assert_usage('Test Teardown in Setting', 'Task Teardown')
self._assert_usage('Test Teardown in Setting', 'Test Teardown')

def test_occurrences_in_suite_documentation_should_not_be_found(self):
self._assert_no_usages('suitedocmatch')
Expand All @@ -237,8 +237,7 @@ def _assert_no_usages(self, keyword):
self.assertEqual(list(self.ts2.execute(FindUsages(keyword))), [])

def assert_occurrences(self, ctrl, kw_name, count):
assert (sum(1 for _ in ctrl.execute(FindOccurrences(kw_name))) ==
count)
assert (sum(1 for _ in ctrl.execute(FindOccurrences(kw_name))) == count)


class FindOccurrencesTest(unittest.TestCase):
Expand Down Expand Up @@ -272,24 +271,28 @@ def test_unknown_variable_occurrences(self):
'${some unknown variable}'))), [])

def test_occurrences_in_test_metadata(self):
# self.test_ctrl.parent.parent._language = ['en']
# print(f"DEBUG: FindOccurrences test_occurrences_in_test_metadata"
# f" file_language={self.test_ctrl.parent.parent.file_language}\n"
# f" source= {self.test_ctrl.parent.parent.source}\n")
assert_occurrence(self.test_ctrl, SETUP_KEYWORD,
TEST1_NAME, 'Setup')
'Some Suite', 'Suite Setup')
assert_occurrence(self.test_ctrl, 'Teardown Kw',
TEST1_NAME, 'Teardown')
'Some Suite', 'Suite Teardown')
assert_occurrence(self.test_ctrl, TEMPLATE_KEYWORD,
TEST1_NAME, 'Template')
'Some Suite', 'Test Template')

def test_occurrences_in_suite_metadata(self):
assert_occurrence(self.test_ctrl, SUITE_SETUP_KEYWORD,
SUITE_NAME, 'Suite Setup')
assert_occurrence(self.test_ctrl, 'Test Setup Kw',
SUITE_NAME, 'Task Setup')
SUITE_NAME, 'Test Setup')
assert_occurrence(self.test_ctrl, 'Test Teardown Kw',
SUITE_NAME, 'Task Teardown')
SUITE_NAME, 'Test Teardown')
assert_occurrence(self.test_ctrl, 'Suite Teardown Kw',
SUITE_NAME, 'Suite Teardown')
assert_occurrence(self.test_ctrl, 'Test Template Kw',
SUITE_NAME, 'Task Template')
SUITE_NAME, 'Test Template')

def test_occurrences_in_user_keywords(self):
assert_occurrence(self.test_ctrl, KEYWORD_IN_USERKEYWORD1,
Expand Down Expand Up @@ -516,7 +519,7 @@ def test_rename_in_test_setup(self):

def test_rename_in_test_template(self):
self._rename(TEMPLATE_KEYWORD, UNUSED_KEYWORD_NAME,
TEST1_NAME, 'Template')
'Some Suite', 'Test Template')
self._expected_messages(testcase_settings_have_changed=True)
self.assertTrue(self.test_ctrl.dirty)

Expand All @@ -528,13 +531,13 @@ def test_rename_in_suite_metadata(self):

def test_rename_in_suite_test_setup(self):
self._rename(SUITE_TEST_SETUP_KEYWORD, UNUSED_KEYWORD_NAME, SUITE_NAME,
'Task Setup')
'Test Setup')
self._expected_messages()
self.assertTrue(self.test_ctrl.dirty)

def test_rename_in_suite_test_template(self):
self._rename(SUITE_TEST_TEMPLATE_KEYWORD, UNUSED_KEYWORD_NAME,
SUITE_NAME, 'Task Template')
SUITE_NAME, 'Test Template')
self._expected_messages()
self.assertTrue(self.test_ctrl.dirty)

Expand Down
4 changes: 4 additions & 0 deletions utest/controller/test_rename_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def test_rename_suite_setup_kw(self):
kw_list = self.suites[0].get_keyword_names()
settings = self.suites[0].setting_table
suite_setup = settings.suite_setup.as_list()
# self.ctrl.language = ['en']
print(f"DEBUG: TestRenameSetupKeywords test_rename_suite_setup_kw"
f" file_language={self.ctrl.file_language}\n"
f" source= {self.suites[0].source}\n")
assert kw_list == ['First KW', 'Second KW', 'Test Setup Keyword', 'Test Teardown Keyword',
'Keyword Teardown Keyword', SUITESETUPKW, 'Test Teardown in Setting']
assert suite_setup == ['Suite Setup', 'Run Keywords', SUITESETUPKW, 'AND', 'First KW']
Expand Down
8 changes: 4 additions & 4 deletions utest/namespace/test_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def test_variable_suggestions_without_varwrapping(self):
self._test_global_variable('space', '${SPACE}')
self._test_global_variable('EMP', '${EMPTY}')

@pytest.mark.skipif(VERSION == '7.0', reason="This test fails with Robot 7.0")
@pytest.mark.skipif(VERSION.startswith('7.0'), reason="This test fails with Robot 7.0")
def test_vars_from_file(self):
sugs = self.ns.get_suggestions_for(
self._get_controller(TESTCASEFILE_WITH_EVERYTHING).keywords[0],
Expand All @@ -274,14 +274,14 @@ def test_vars_from_path_resource_file(self):
'${Path RESOURCE var')
assert len(sugs) > 0

@pytest.mark.skipif(VERSION == '7.0', reason="This test fails with Robot 7.0")
@pytest.mark.skipif(VERSION.startswith('7.0'), reason="This test fails with Robot 7.0")
def test_variable_file_arguments_are_resolved(self):
sugs = self.ns.get_suggestions_for(
self._get_controller(TESTCASEFILE_WITH_EVERYTHING).keywords[0],
'${dyn ')
assert len(sugs) > 0

@pytest.mark.skipif(VERSION == '7.0', reason="This test fails with Robot 7.0")
@pytest.mark.skipif(VERSION.startswith('7.0'), reason="This test fails with Robot 7.0")
def test_variable_file_variables_are_available_in_resource_imports(self):
sugs = self.ns.get_suggestions_for(self._get_controller(
TESTCASEFILE_WITH_RESOURCES_WITH_VARIABLES_FROM_VARIABLE_FILE
Expand Down Expand Up @@ -328,7 +328,7 @@ def test_suggestions_for_datafile(self):
sugs = self.ns.get_suggestions_for(self.tcf_ctrl, '${libna')
assert len(sugs) == 1

@pytest.mark.skipif(VERSION == '7.0', reason="This test fails with Robot 7.0")
@pytest.mark.skipif(VERSION.startswith('7.0'), reason="This test fails with Robot 7.0")
def test_variable_sources(self):
everything_tcf = self._get_controller(TESTCASEFILE_WITH_EVERYTHING)
self._check_source(everything_tcf, '${arg}', 'everything.robot')
Expand Down
5 changes: 2 additions & 3 deletions utest/resources/datafilereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def _makepath(*elements):
SIMPLE_TEST_SUITE_RESOURCE_NAME = 'Testdata Resource'
SIMPLE_TEST_SUITE_RESOURCE_FILE = 'testdata_resource.robot'
SIMPLE_TEST_SUITE_INNER_RESOURCE_DIR = 'Resources Folder'
SIMPLE_TEST_SUITE_PATH = \
_makepath('simple_testsuite_with_different_namespaces')
SIMPLE_TEST_SUITE_PATH = _makepath('simple_testsuite_with_different_namespaces')

FOR_LOOP_PATH = _makepath('forloop')

Expand Down Expand Up @@ -97,7 +96,7 @@ def _makepath(*elements):

def construct_project(datapath, temp_dir_for_excludes=None, file_language=None):
print("DEBUG: construct_project with argpath: %s\n" % datapath)
settings = FakeSettings({'excludes': temp_dir_for_excludes, 'txt number of spaces': 2})
settings = FakeSettings({'excludes': temp_dir_for_excludes, 'txt number of spaces': 2, 'doc language': ''})
print("DEBUG: construct_project FakeSettings: %s\n" % list(settings.iteritems()))
library_manager = LibraryManager(':memory:')
library_manager.create_database()
Expand Down
2 changes: 1 addition & 1 deletion utest/resources/fake.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
auto imports = []
pythonpath = []
global_settings = []
doc language = 'en'
doc language = ''
excludes = None
txt number of spaces = 2
[General]
Expand Down
2 changes: 1 addition & 1 deletion utest/resources/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, settings=None):
self.set('pythonpath', [])
self.set('auto imports', [])
self.set('global_settings', [])
self.set('doc language', 'en')
self.set('doc language', '')
if settings:
for key, val in settings.items():
self.set(key, val)
Expand Down
2 changes: 2 additions & 0 deletions utest/resources/robotdata/complex_tests/TestSuite.robot
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Language: English

*** Settings ***
Suite Setup Run Keywords Suite Setup Keyword AND First KW
Test Teardown Run Keywords Test Teardown in Setting AND Second KW
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Language: English

*** Settings ***
Resource testdata_resource.robot
Resource ..${/}resources${/}resu.robot
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Language: English

*** Settings ***
Documentation suitedocmatch
Resource testdata_resource.robot
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Language: English

*** Test Cases ***
My Second Test
My Keyword
Expand All @@ -10,4 +12,4 @@ embedded ${args} keyword
No Operation

2nd embedded ${args} keyword
No Operation
No Operation
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Language: English

*** Settings ***
Resource resources${/}inner_resource.robot

Expand Down
4 changes: 2 additions & 2 deletions utest/ui/test_namedialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_execute(self):
def test_get_title(self):
test_ctrl = file_controller().create_test('A test')
dlg = TestCaseNameDialog(test_ctrl, item=test_ctrl.data)
assert dlg.GetTitle() == TestCaseNameDialog._title
assert dlg.GetTitle() == 'New Test Case'

def test_validators(self):
test_ctrl = file_controller().create_test('A test')
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_execute(self):
def test_get_title(self):
kw_ctrl = file_controller().create_keyword('Keyword it is', '${a1} | ${a2}')
dlg = UserKeywordNameDialog(kw_ctrl, item=kw_ctrl.data)
assert dlg.GetTitle() == UserKeywordNameDialog._title
assert dlg.GetTitle() == 'New User Keyword'

def test_validators(self):
kw_ctrl = file_controller().create_keyword('Keyword it is', '${a1} | ${a2}')
Expand Down

0 comments on commit cc977a5

Please sign in to comment.