Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Python2.7 Test Suite #1684

Merged
merged 5 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/discord/update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 1996-2020 Cyberbotics Ltd.
Expand Down
4 changes: 3 additions & 1 deletion docs/tests/test_hyperlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest
import re
import os
import sys

from books import Books

Expand All @@ -18,7 +19,8 @@ def setUp(self):
for book in books.books:
for md_path in book.md_paths:
# Extract MD content.
with open(md_path, encoding='utf-8') as f:
args = {} if sys.version_info[0] < 3 else {'encoding': 'utf-8'}
with open(md_path, **args) as f:
content = f.read()
# Remove code statements
content = re.sub(r'```.+?(?=```)```', '', content, flags=re.S)
Expand Down
7 changes: 5 additions & 2 deletions docs/tests/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fnmatch
import os
import re
import sys


class TestImages(unittest.TestCase):
Expand All @@ -15,7 +16,8 @@ def test_images_are_valid(self):
books = Books()
for book in books.books:
for md_path in book.md_paths:
with open(md_path, encoding='utf-8') as f:
args = {} if sys.version_info[0] < 3 else {'encoding': 'utf-8'}
with open(md_path, **args) as f:
content = f.read()
for match in re.finditer(r"!\[(.*?)\]\((.*?)\)", content):
# remove parameters
Expand Down Expand Up @@ -50,7 +52,8 @@ def test_all_images_are_used(self):
for image_path in images_paths:
found = False
for md_path in book.md_paths:
with open(md_path, encoding='utf-8') as file:
args = {} if sys.version_info[0] < 3 else {'encoding': 'utf-8'}
with open(md_path, **args) as file:
if (image_path in file.read() or
image_path.replace('.png', '.thumbnail.jpg') in images_paths or
image_path.replace('.png', '.thumbnail.png') in images_paths):
Expand Down
4 changes: 3 additions & 1 deletion docs/tests/test_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import unittest
import re
import sys

from books import Books

Expand All @@ -26,7 +27,8 @@ def setUp(self):
# Extract MD content.
itemBuffer = ''
skipUntil = ''
with open(md_path, encoding='utf-8') as f:
args = {} if sys.version_info[0] < 3 else {'encoding': 'utf-8'}
with open(md_path, **args) as f:
content = f.readlines()
for line in content:
if skipUntil:
Expand Down
7 changes: 5 additions & 2 deletions docs/tests/test_md_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from books import Books

import os
import sys


class TestMDFiles(unittest.TestCase):
Expand All @@ -23,7 +24,8 @@ def test_md_files_exist(self):
os.path.isfile(md_filename),
msg='MD file "%s" is not existing' % (md_filename)
)
with open(md_filename, encoding='utf-8') as f:
args = {} if sys.version_info[0] < 3 else {'encoding': 'utf-8'}
with open(md_filename, **args) as f:
content = f.read()
self.assertGreater(
len(content), 0,
Expand All @@ -45,7 +47,8 @@ def test_md_file_contents_dont_contain_prohibited_keywords(self):
books = Books()
for book in books.books:
for md_path in book.md_paths:
with open(md_path, encoding='utf-8') as f:
args = {} if sys.version_info[0] < 3 else {'encoding': 'utf-8'}
with open(md_path, **args) as f:
content = f.readlines()
for line in content:
# π crashes QtWebEngine on Windows.
Expand Down
7 changes: 5 additions & 2 deletions docs/tests/test_menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import re
import sys


class TestMenus(unittest.TestCase):
Expand All @@ -28,7 +29,8 @@ def test_menu_files_exist(self):
def test_menu_refer_valid_files(self):
"""The menu.md refer valid files."""
for menu in self.menus:
with open(menu, encoding='utf-8') as f:
args = {} if sys.version_info[0] < 3 else {'encoding': 'utf-8'}
with open(menu, **args) as f:
content = f.readlines()
self.assertGreater(len(content), 0, msg='Menu file is empty')
match_counter = 0
Expand Down Expand Up @@ -72,7 +74,8 @@ def test_all_book_files_are_referred_by_the_menu_file(self):
for menu in self.menus:
book_path = os.path.dirname(menu)
# list md files in bookPath
with open(menu, 'r', encoding='utf-8') as menu_file:
args = {} if sys.version_info[0] < 3 else {'encoding': 'utf-8'}
with open(menu, 'r', **args) as menu_file:
menu_content = menu_file.read()
for file_path in os.listdir(book_path):
if (file_path.endswith(".md") and
Expand Down
4 changes: 3 additions & 1 deletion docs/tests/test_paragraphs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test module for the Markdown paragraphs."""

import re
import sys
import unittest

from books import Books
Expand All @@ -21,7 +22,8 @@ def setUp(self):

for md_path in book.md_paths:
# Extract MD content.
with open(md_path, encoding='utf-8') as f:
args = {} if sys.version_info[0] < 3 else {'encoding': 'utf-8'}
with open(md_path, **args) as f:
content = f.read()

# Remove annoying string sequences.
Expand Down
7 changes: 5 additions & 2 deletions docs/tests/test_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import re
import sys


def slugify(txt):
Expand Down Expand Up @@ -35,7 +36,8 @@ def setUp(self):

for md_path in book.md_paths:
anchors = []
with open(md_path, encoding='utf-8') as f:
args = {} if sys.version_info[0] < 3 else {'encoding': 'utf-8'}
with open(md_path, **args) as f:
skipUntil = ''
for line in f:
if skipUntil:
Expand Down Expand Up @@ -99,7 +101,8 @@ def test_references_are_valid(self):
continue

for md_path in book.md_paths:
with open(md_path, encoding='utf-8') as f:
args = {} if sys.version_info[0] < 3 else {'encoding': 'utf-8'}
with open(md_path, **args) as f:
content = f.read()
for m in re.finditer(r"[^!]\[(.*?)\]\(([^\)]+)\)", content):
# remove parameters
Expand Down
4 changes: 3 additions & 1 deletion docs/tests/test_titles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test module for the titles."""

import re
import sys
import unittest

from books import Books
Expand Down Expand Up @@ -52,7 +53,8 @@ def setUp(self):

for md_path in book.md_paths:
# Extract MD content.
with open(md_path, encoding='utf-8') as f:
args = {} if sys.version_info[0] < 3 else {'encoding': 'utf-8'}
with open(md_path, **args) as f:
content = f.read()

# Remove annoying string sequences.
Expand Down
2 changes: 1 addition & 1 deletion src/packaging/copy_msys64_files.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Copyright 1996-2020 Cyberbotics Ltd.
#
Expand Down
9 changes: 4 additions & 5 deletions tests/sources/test_pep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@
'projects/languages/ros/controllers/ros_python/python'
]

if sys.version_info[0] < 3:
# these scripts work only with Python 3
skippedDirectories.append('scripts/preferences_cleaner')
skippedDirectories.append('src/packaging')


class FlakesReporter(Reporter):
"""Flakes reporter."""
Expand Down Expand Up @@ -162,6 +157,10 @@ def setUp(self):
if shouldContinue:
continue
filePath = os.path.join(rootPath, fileName)
if sys.version_info[0] < 3:
with open(filePath) as file:
if file.readline().startswith('#!/usr/bin/env python3'):
continue
self.files.append(filePath)

def test_pep8_conformance(self):
Expand Down