Skip to content

Commit

Permalink
Fix tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Jul 6, 2022
1 parent c3b71b2 commit a12af82
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions python/test/test_github_action.py
Expand Up @@ -96,8 +96,8 @@ def test_error(self):
gha.error('the message', file='the file', line=1, column=2)

# log exception
with gh_action_command_test(self, '::error::RuntimeError: failure\n'
'::error file=the file,line=1,col=2::the message') as gha:
with gh_action_command_test(self, f'::error::RuntimeError: failure{os.linesep}'
f'::error file=the file,line=1,col=2::the message') as gha:
try:
raise RuntimeError('failure')
except RuntimeError as e:
Expand All @@ -107,7 +107,7 @@ def test_error(self):
gha.error('the message', file='the file', line=1, column=2, exception=error)

self.assertEqual(
[(call[0], re.sub(r'File ".*/', 'File "', re.sub(r'line \d+', 'line X', call.args[0])))
[(call[0], re.sub(r'File ".*[/\\]', 'File "', re.sub(r'line \d+', 'line X', call.args[0])))
for call in m.method_calls],
[
('error', 'RuntimeError: failure'),
Expand All @@ -119,15 +119,15 @@ def test_error(self):
)

# log exceptions related via cause
with gh_action_command_test(self, '::error::RuntimeError: failed except caused by ValueError: invalid value\n'
'::error::ValueError: invalid value\n'
'::error file=the file,line=1,col=2::the message') as gha:
with gh_action_command_test(self, f'::error::RuntimeError: failed except caused by ValueError: invalid value{os.linesep}'
f'::error::ValueError: invalid value{os.linesep}'
f'::error file=the file,line=1,col=2::the message') as gha:
error = self.get_error_with_cause()
with mock.patch('publish.github_action.logger') as m:
gha.error('the message', file='the file', line=1, column=2, exception=error)

self.assertEqual(
[(call[0], re.sub(r'File ".*/', 'File "', re.sub(r'line \d+', 'line X', call.args[0])))
[(call[0], re.sub(r'File ".*[/\\]', 'File "', re.sub(r'line \d+', 'line X', call.args[0])))
for call in m.method_calls],
[
('error', 'RuntimeError: failed except caused by ValueError: invalid value'),
Expand All @@ -141,15 +141,15 @@ def test_error(self):
)

# log exceptions related via context
with gh_action_command_test(self, '::error::RuntimeError: failed except while handling ValueError: invalid value\n'
'::error::ValueError: invalid value\n'
'::error file=the file,line=1,col=2::the message') as gha:
with gh_action_command_test(self, f'::error::RuntimeError: failed except while handling ValueError: invalid value{os.linesep}'
f'::error::ValueError: invalid value{os.linesep}'
f'::error file=the file,line=1,col=2::the message') as gha:
error = self.get_error_with_context()
with mock.patch('publish.github_action.logger') as m:
gha.error('the message', file='the file', line=1, column=2, exception=error)

self.assertEqual(
[(call[0], re.sub(r'File ".*/', 'File "', re.sub(r'line \d+', 'line X', call.args[0])))
[(call[0], re.sub(r'File ".*[/\\]', 'File "', re.sub(r'line \d+', 'line X', call.args[0])))
for call in m.method_calls],
[
('error', 'RuntimeError: failed except while handling ValueError: invalid value'),
Expand Down Expand Up @@ -207,7 +207,7 @@ def test_add_job_summary(self):
def test__command_with_multi_line_value(self):
with io.StringIO() as string:
GithubAction._command(string, 'command', 'multi\nline\nvalue')
self.assertEqual('::command::multi\n', string.getvalue())
self.assertEqual('::command::multi' + os.linesep, string.getvalue())

def test__append_to_file_errors(self):
# env variable does not exist
Expand Down

0 comments on commit a12af82

Please sign in to comment.