Skip to content

Commit

Permalink
Fixed SonarCloud issue and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fra87 committed Jul 6, 2022
1 parent b3cdd80 commit 28affdd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions xlsxwriter/test/core/test_returncodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class TestReturnCodes(unittest.TestCase):
"""

_string_conversion_expected_result = "No error"
_testing_image_path = 'xlsxwriter/test/comparison/images/logo.png'
_testing_vba_bin_path = 'xlsxwriter/test/comparison/xlsx_files/vbaProject02.bin'

def setUp(self):
self.fh = StringIO()
self.workbook = Workbook()
Expand Down Expand Up @@ -135,32 +139,29 @@ def test_returncode_to_string_implicit(self):
Implicit conversion (using StrEnum underlying str representation)
"""
retcode = ReturnCode.XW_NO_ERROR
exp = "No error"
got = retcode

self.assertEqual(got, exp)
self.assertEqual(got, self._string_conversion_expected_result)

def test_returncode_to_string_format(self):
"""Test converting a return code to string.
Using str.format() conversion
"""
retcode = ReturnCode.XW_NO_ERROR
exp = "No error"
got = "{0}".format(retcode)

self.assertEqual(got, exp)
self.assertEqual(got, self._string_conversion_expected_result)

def test_returncode_to_string_fstring(self):
"""Test converting a return code to string.
Using f-string conversion
"""
retcode = ReturnCode.XW_NO_ERROR
exp = "No error"
got = f'{retcode}'

self.assertEqual(got, exp)
self.assertEqual(got, self._string_conversion_expected_result)

###########################################################################
#
Expand All @@ -173,7 +174,7 @@ def test_workbook_add_vba_project_no_error(self):
"""

def func():
return self.workbook.add_vba_project('xlsxwriter/test/comparison/xlsx_files/vbaProject02.bin')
return self.workbook.add_vba_project(self._testing_vba_bin_path)
self._test_no_error(func)

def test_workbook_add_vba_project_vba_file_not_found(self):
Expand Down Expand Up @@ -483,7 +484,7 @@ def test_worksheet_write_url_max_number_urls(self):
max_urls_per_worksheet = 65530

exp = ReturnCode.XW_NO_ERROR
for i in range(max_urls_per_worksheet):
for _ in range(max_urls_per_worksheet):
got = self.worksheet.write_url(0, 0, '')
self.assertEqual(got, exp)

Expand Down Expand Up @@ -581,7 +582,7 @@ def test_worksheet_insert_image_no_error(self):
"""

def func():
return self.worksheet.insert_image(0, 0, 'xlsxwriter/test/comparison/images/logo.png')
return self.worksheet.insert_image(0, 0, self._testing_image_path)
self._test_no_error(func)

def test_worksheet_insert_image_out_of_range(self):
Expand All @@ -593,7 +594,7 @@ def test_worksheet_insert_image_out_of_range(self):
warnings.simplefilter('ignore', category=UserWarning)

def func(r, c):
return self.worksheet.insert_image(r, c, 'xlsxwriter/test/comparison/images/logo.png')
return self.worksheet.insert_image(r, c, self._testing_image_path)
self._test_cell_out_of_range(func)

def test_worksheet_insert_image_file_not_found(self):
Expand Down Expand Up @@ -700,7 +701,7 @@ def test_worksheet_set_background_no_error(self):
"""

def func():
return self.worksheet.set_background('xlsxwriter/test/comparison/images/logo.png')
return self.worksheet.set_background(self._testing_image_path)
self._test_no_error(func)

def test_worksheet_set_background_file_not_found(self):
Expand Down Expand Up @@ -962,7 +963,8 @@ def test_worksheet_add_table_not_supported_constant_memory(self):
# Here we must use an actual file because the worksheet file handle is
# not cleaned up correctly when using the StringIO

filepath = tempfile.mktemp()
(fd, filepath) = tempfile.mkstemp()
os.close(fd)

with Workbook(filepath, dict(constant_memory=True)) as tempworkbook:
tempworksheet = tempworkbook.add_worksheet()
Expand Down
2 changes: 1 addition & 1 deletion xlsxwriter/worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1990,7 +1990,7 @@ def merge_range(self, first_row, first_col, last_row, last_col,
# the others should be blank. All cells should have the same format.

# Excel doesn't allow a single cell to be merged
if first_row == last_row and first_col == last_col:
if (first_row, first_col) == (last_row, last_col):
warn("Can't merge single cell")
return

Expand Down

0 comments on commit 28affdd

Please sign in to comment.