Commit Graph

6 Commits

Author SHA1 Message Date
Brandon Maier 4b43d5744a
Fix for pytest on Windows (#1338)
* tests: support admin check on Windows

The tests fail on Windows with the following

> ___________ ERROR collecting tests/source_file/test_source_file.py ____________
> tests\source_file\test_source_file.py:24: in <module>
>     class testOSError(unittest.TestCase):
> tests\source_file\test_source_file.py:39: in testOSError
>     @unittest.skipIf("SUDO_UID" in os.environ.keys() or os.geteuid() == 0, "We are root. Root always has permissions so test will fail.")
> E   AttributeError: module 'os' has no attribute 'geteuid'

Catch the AttributeError and attempt to check for admin when on Windows

Signed-off-by: Brandon Maier <brandon.maier@gmail.com>

* tests: support running 'vsg' binary on Windows

A large number of tests fail on Windows with the following error

> ________ test_severity_using_main.test_architecture_with_configuration ________
> [gw0] win32 -- Python 3.8.20 %PREFIX%\python.exe
>
> self = <tests.severity.test_main.test_severity_using_main testMethod=test_architecture_with_configuration>
>
>     def test_architecture_with_configuration(self):
>         try:
> >           subprocess.check_output(["bin/vsg", "-f", self._sArchitectureFileName, "-c", sConfigFile])
>
> tests\severity\test_main.py:86:
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ..\_test_env\lib\subprocess.py:415: in check_output
>     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
> ..\_test_env\lib\subprocess.py:493: in run
>     with Popen(*popenargs, **kwargs) as process:
> ..\_test_env\lib\subprocess.py:858: in __init__
>     self._execute_child(args, executable, preexec_fn, close_fds,
...
> E FileNotFoundError: [WinError 2] The system cannot find the file specified
> ..\_test_env\lib\subprocess.py:1327: FileNotFoundError

Tests that call "bin/vsg" are relying on the Unix shebang (e.g.
"#!/usr/bin/python") to launch `vsg` using the Python interpreter, But
this is not supported on Windows. Instead launch `vsg` with Python
directly.

Signed-off-by: Brandon Maier <brandon.maier@gmail.com>

* tests: normalize line endings for Windows tests

Many of the tests that compare `vsg` stdout fail with a warning as
follows.

> First differing element 0:
> 'ERRO[19 chars]1.vhd(7)port_007 -- Change number of spaces after *in* to 4.\r'
> 'ERRO[19 chars]1.vhd(7)port_007 -- Change number of spaces after *in* to 4.'

The tests use `.split('\n')` to split stdout and stderr by the Linux
line terminator '\n'. But on Windows this causes test failures as the
line terminator is '\r\n'.

Instead use Python `.splitlines()`. which will split on both Linux and
Windows style line terminators. `.splitlines()` also removes empty
trailing lines, so we must modify the expected output accordingly.

Signed-off-by: Brandon Maier <brandon.maier@gmail.com>

* Fixing test error by including encoding when reading vhdl files.

* Fixing second error due to glob function using incorrect divider.

* Fixed file compare not working in quality report test.

* Fixed output error message to be independent of platform.

* Skipping permission tests when running on windows.

* Skipping file permission test when running on Windows.

---------

Signed-off-by: Brandon Maier <brandon.maier@gmail.com>
Co-authored-by: Jeremiah Leary <jeremiah.c.leary@gmail.com>
2025-01-13 20:46:16 -06:00
JHertz5 b7a1023f5b Issue#1314: Updated tests after report format change. 2024-11-13 08:26:26 +00:00
Alon Bar-Lev c22a86025f style: apply black
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
2024-03-24 21:16:35 +02:00
Alon Bar-Lev 5b4bae04aa style: apply isort
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
2024-03-24 21:16:35 +02:00
Alon Bar-Lev b8c49b5946 style: python encoding
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
2024-03-24 21:16:35 +02:00
Alon Bar-Lev 8f9dc637ee tests: move out of vsg
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
2024-03-23 18:48:35 +02:00