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

Partial fix for pytest on Windows #1338

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions tests/context/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import unittest
from tempfile import TemporaryDirectory

from tests import utils
from vsg import __main__, severity

sFileName = "context_classification_test_input.vhd"
Expand All @@ -29,9 +30,9 @@ def tearDown(self):

def test_classification_file(self):
self.maxDiff = None
subprocess.check_output(["bin/vsg", "-f", self._sFileName, "--fix"]).decode("utf-8").split("\n")
subprocess.check_output([*utils.vsg_exec(), "-f", self._sFileName, "--fix"]).decode("utf-8").splitlines()

lActual = pathlib.Path(self._sFileName).read_text().split("\n")
lExpected = pathlib.Path(sFixedFile).read_text().split("\n")
lActual = pathlib.Path(self._sFileName).read_text().splitlines()
lExpected = pathlib.Path(sFixedFile).read_text().splitlines()

self.assertEqual(lExpected, lActual)
54 changes: 27 additions & 27 deletions tests/severity/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,75 +40,75 @@ def tearDown(self):

def test_entity_without_configuration(self):
try:
subprocess.check_output(["bin/vsg", "-f", self._sEntityFileName])
subprocess.check_output([*utils.vsg_exec(), "-f", self._sEntityFileName])
except subprocess.CalledProcessError as e:
lActual = e.output.decode("utf-8").split("\n")
lActual = e.output.decode("utf-8").splitlines()
iExitStatus = e.returncode

lExpected = pathlib.Path(sOutputFileWoConfig).read_text().split("\n")
lExpected = pathlib.Path(sOutputFileWoConfig).read_text().splitlines()

self.assertEqual(iExitStatus, 1)
self.assertEqual(utils.replace_token(utils.replace_total_count(lActual), self._sEntityFileName, sEntityFileName), lExpected)

def test_entity_with_configuration(self):
try:
subprocess.check_output(["bin/vsg", "-f", self._sEntityFileName, "-c", sConfigFile])
subprocess.check_output([*utils.vsg_exec(), "-f", self._sEntityFileName, "-c", sConfigFile])
except subprocess.CalledProcessError as e:
lActual = e.output.decode("utf-8").split("\n")
lActual = e.output.decode("utf-8").splitlines()
iExitStatus = e.returncode

lExpected = pathlib.Path(sOutputFileWithConfig).read_text().split("\n")
lExpected = pathlib.Path(sOutputFileWithConfig).read_text().splitlines()

self.assertEqual(iExitStatus, 1)
self.assertEqual(utils.replace_token(utils.replace_total_count(lActual), self._sEntityFileName, sEntityFileName), lExpected)

def test_entity_with_configuration_and_fixed(self):
lActual = subprocess.check_output(["bin/vsg", "-f", self._sEntityFileName, "-c", sConfigFile, "--fix"]).decode("utf-8").split("\n")
lActual = subprocess.check_output([*utils.vsg_exec(), "-f", self._sEntityFileName, "-c", sConfigFile, "--fix"]).decode("utf-8").splitlines()

lExpected = pathlib.Path(sOutputFileWithConfigFixed).read_text().split("\n")
lExpected = pathlib.Path(sOutputFileWithConfigFixed).read_text().splitlines()

self.assertEqual(utils.replace_token(utils.replace_total_count(lActual), self._sEntityFileName, sEntityFileName), lExpected)

def test_architecture_without_configuration(self):
try:
subprocess.check_output(["bin/vsg", "-f", self._sArchitectureFileName])
subprocess.check_output([*utils.vsg_exec(), "-f", self._sArchitectureFileName])
except subprocess.CalledProcessError as e:
lActual = e.output.decode("utf-8").split("\n")
lActual = e.output.decode("utf-8").splitlines()
iExitStatus = e.returncode

lExpected = pathlib.Path(sArchitectureOutputFileWoConfig).read_text().split("\n")
lExpected = pathlib.Path(sArchitectureOutputFileWoConfig).read_text().splitlines()

self.assertEqual(iExitStatus, 1)
self.assertEqual(utils.replace_token(utils.replace_total_count(lActual), self._sArchitectureFileName, sArchitectureFileName), lExpected)

def test_architecture_with_configuration(self):
try:
subprocess.check_output(["bin/vsg", "-f", self._sArchitectureFileName, "-c", sConfigFile])
subprocess.check_output([*utils.vsg_exec(), "-f", self._sArchitectureFileName, "-c", sConfigFile])
except subprocess.CalledProcessError as e:
lActual = e.output.decode("utf-8").split("\n")
lActual = e.output.decode("utf-8").splitlines()
iExitStatus = e.returncode

lExpected = pathlib.Path(sArchitectureOutputFileWithConfig).read_text().split("\n")
lExpected = pathlib.Path(sArchitectureOutputFileWithConfig).read_text().splitlines()

self.assertEqual(iExitStatus, 1)
self.assertEqual(utils.replace_token(utils.replace_total_count(lActual), self._sArchitectureFileName, sArchitectureFileName), lExpected)

def test_architecture_with_configuration_and_fixed(self):
lActual = subprocess.check_output(["bin/vsg", "-f", self._sArchitectureFileName, "-c", sConfigFile, "--fix"]).decode("utf-8").split("\n")
lActual = subprocess.check_output([*utils.vsg_exec(), "-f", self._sArchitectureFileName, "-c", sConfigFile, "--fix"]).decode("utf-8").splitlines()

lExpected = pathlib.Path(sArchitectureOutputFileWithConfigFixed).read_text().split("\n")
lExpected = pathlib.Path(sArchitectureOutputFileWithConfigFixed).read_text().splitlines()

self.assertEqual(utils.replace_token(utils.replace_total_count(lActual), self._sArchitectureFileName, sArchitectureFileName), lExpected)

def test_both_with_configuration(self):
try:
subprocess.check_output(["bin/vsg", "-f", self._sEntityFileName, self._sArchitectureFileName, "-c", sConfigFile])
subprocess.check_output([*utils.vsg_exec(), "-f", self._sEntityFileName, self._sArchitectureFileName, "-c", sConfigFile])
except subprocess.CalledProcessError as e:
lActual = e.output.decode("utf-8").split("\n")
lActual = e.output.decode("utf-8").splitlines()
iExitStatus = e.returncode

lExpected1 = pathlib.Path(sOutputFileWithConfig).read_text().rstrip("\n").split("\n")
lExpected2 = pathlib.Path(sArchitectureOutputFileWithConfig).read_text().split("\n")
lExpected1 = pathlib.Path(sOutputFileWithConfig).read_text().splitlines()
lExpected2 = pathlib.Path(sArchitectureOutputFileWithConfig).read_text().splitlines()

self.assertEqual(iExitStatus, 1)
self.assertEqual(
Expand All @@ -122,13 +122,13 @@ def test_both_with_configuration(self):

def test_both_with_configuration_and_fixed(self):
lActual = (
subprocess.check_output(["bin/vsg", "-f", self._sEntityFileName, self._sArchitectureFileName, "-c", sConfigFile, "--fix"])
subprocess.check_output([*utils.vsg_exec(), "-f", self._sEntityFileName, self._sArchitectureFileName, "-c", sConfigFile, "--fix"])
.decode("utf-8")
.split("\n")
.splitlines()
)

lExpected1 = pathlib.Path(sOutputFileWithConfigFixed).read_text().rstrip("\n").split("\n")
lExpected2 = pathlib.Path(sArchitectureOutputFileWithConfigFixed).read_text().split("\n")
lExpected1 = pathlib.Path(sOutputFileWithConfigFixed).read_text().splitlines()
lExpected2 = pathlib.Path(sArchitectureOutputFileWithConfigFixed).read_text().splitlines()

self.assertEqual(
utils.replace_token(
Expand All @@ -141,12 +141,12 @@ def test_both_with_configuration_and_fixed(self):

def test_junit_output(self):
try:
subprocess.check_output(["bin/vsg", "-f", self._sEntityFileName, "-c", sConfigFile, "-j", self._sJUnitFileName])
subprocess.check_output([*utils.vsg_exec(), "-f", self._sEntityFileName, "-c", sConfigFile, "-j", self._sJUnitFileName])
except subprocess.CalledProcessError as e:
iExitStatus = e.returncode

lActual = pathlib.Path(self._sJUnitFileName).read_text().split("\n")
lExpected = pathlib.Path(sJUnitFile).read_text().split("\n")
lActual = pathlib.Path(self._sJUnitFileName).read_text().splitlines()
lExpected = pathlib.Path(sJUnitFile).read_text().splitlines()

self.assertEqual(iExitStatus, 1)

Expand Down
16 changes: 8 additions & 8 deletions tests/source_file/test_source_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,37 @@ def tearDown(self):

def test_file_not_found(self):
try:
subprocess.check_output(["bin/vsg", "-f", "no_file.vhd"], stderr=subprocess.STDOUT)
subprocess.check_output([*utils.vsg_exec(), "-f", "no_file.vhd"], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
exit_status: int = e.returncode

self.assertEqual(exit_status, 1)

@unittest.skipIf("SUDO_UID" in os.environ.keys() or os.geteuid() == 0, "We are root. Root always has permissions so test will fail.")
@unittest.skipIf(utils.is_user_admin(), "We are root. Root always has permissions so test will fail.")
def test_file_no_permission(self):
sNoPermissionTempFile = os.path.join(self._tmpdir.name, sNoPermissionFile)

pathlib.Path(sNoPermissionTempFile).touch(mode=0o222, exist_ok=True)

try:
subprocess.check_output(["bin/vsg", "-f", sNoPermissionTempFile])
subprocess.check_output([*utils.vsg_exec(), "-f", sNoPermissionTempFile])
except subprocess.CalledProcessError as e:
lActual = str(e.output.decode("utf-8")).split("\n")
lActual = str(e.output.decode("utf-8")).splitlines()
iExitStatus = e.returncode

lExpected = pathlib.Path(sOutputNoPermission).read_text().split("\n")
lExpected = pathlib.Path(sOutputNoPermission).read_text().splitlines()

self.assertEqual(iExitStatus, 1)
self.assertEqual(utils.replace_token(utils.replace_total_count(lActual), sNoPermissionTempFile, sNoPermissionFile), lExpected)

def test_file_empty(self):
try:
subprocess.check_output(["bin/vsg", "-f", "tests/source_file/" + sEmptyFile])
subprocess.check_output([*utils.vsg_exec(), "-f", "tests/source_file/" + sEmptyFile])
except subprocess.CalledProcessError as e:
lActual = str(e.output.decode("utf-8")).split("\n")
lActual = str(e.output.decode("utf-8")).splitlines()
iExitStatus = e.returncode

lExpected = pathlib.Path(sOutputEmptyFile).read_text().split("\n")
lExpected = pathlib.Path(sOutputEmptyFile).read_text().splitlines()

self.assertEqual(iExitStatus, 1)
self.assertEqual(utils.replace_total_count(lActual), lExpected)
18 changes: 18 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
import ctypes
import os
import pprint
import re
import sys

import yaml

Expand Down Expand Up @@ -128,3 +130,19 @@ def replace_total_count_summary(lOutput):

def replace_token(lOutput, src, dst):
return [line.replace(src, dst) for line in lOutput]


def is_user_admin():
if "SUDO_UID" in os.environ.keys():
return True

try:
return os.getuid() == 0
except AttributeError:
pass

return ctypes.windll.shell32.IsUserAnAdmin() == 1


def vsg_exec():
return [sys.executable, "bin/vsg"]
4 changes: 2 additions & 2 deletions tests/vsg/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def test_globbing_filenames_in_configuration(self):
except SystemExit:
pass

lActual = temp_stdout.getvalue().strip().split("\n")
lActual = temp_stdout.getvalue().strip().splitlines()

if lActual[0] == lExpected[1]:
lExpected = [lExpected[1], lExpected[0]]
Expand Down Expand Up @@ -422,7 +422,7 @@ def test_globbing_filenames_in_yaml_configuration(self):
except SystemExit:
pass

lActual = temp_stdout.getvalue().strip().split("\n")
lActual = temp_stdout.getvalue().strip().splitlines()

if lActual[0] == lExpected[1]:
lExpected = [lExpected[1], lExpected[0]]
Expand Down
7 changes: 4 additions & 3 deletions tests/vsg/test_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import subprocess
import unittest

from tests import utils


class command_line_args:
"""This is used as an input into the version command."""
Expand Down Expand Up @@ -68,13 +70,12 @@ class testVsg(unittest.TestCase):
def test_rc_command_line_argument_w_invalid_rule(self):
lExpected = []
lExpected.append("ERROR: rule unknown_rule_001 was not found.")
lExpected.append("")
iExitStatus = -1

try:
subprocess.check_output(["bin/vsg", "-rc", "unknown_rule_001"])
subprocess.check_output([*utils.vsg_exec(), "-rc", "unknown_rule_001"])
except subprocess.CalledProcessError as e:
lActual = str(e.output.decode("utf-8")).split("\n")
lActual = str(e.output.decode("utf-8")).splitlines()
iExitStatus = e.returncode

self.assertEqual(iExitStatus, 1)
Expand Down
Loading