Skip to content

Commit 4b9bd9d

Browse files
author
Szymon Janowski
committed
Fixing tests
1 parent bb0be26 commit 4b9bd9d

File tree

7 files changed

+65
-36
lines changed

7 files changed

+65
-36
lines changed

tests/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import logging
2+
3+
import pytest # pyright: ignore [reportMissingImports]
4+
from loguru import logger
5+
6+
7+
@pytest.fixture()
8+
def caplog(_caplog):
9+
"""Wrapper over caplog fixture to fix loguru logs.
10+
11+
Yields
12+
------
13+
_caplog: Pytest fixture
14+
"""
15+
16+
class PropogateHandler(logging.Handler):
17+
def emit(self, record):
18+
logging.getLogger(record.name).handle(record)
19+
20+
logger.add(PropogateHandler(), format="{message}")
21+
handler_id = logger.add(PropogateHandler(), format="{message}")
22+
yield _caplog
23+
logger.remove(handler_id)

tests/data/advanced.ansi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
 
22
 Info 
3-
┌─────────────────┬──────────────┐
4-
 Item   Value  
5-
├─────────────────┼──────────────┤
3+
┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
4+
 Item   Value  
5+
┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
66
│ program  │ licensecheck │
77
│ version  │ 2024  │
88
│ license  │ MIT LICENSE  │
@@ -11,16 +11,16 @@
1111
 
1212
 List Of 
1313
 Errors 
14-
┌──────────┐
15-
 Package  
16-
├──────────┤
14+
┏━━━━━━━━━━┓
15+
 Package  
16+
┡━━━━━━━━━━┩
1717
│ example1 │
1818
└──────────┘
1919
 
2020
 List Of Packages 
21-
┌────────────┬──────────┬────────────┐
22-
 Compatible  Package   License(s) 
23-
├────────────┼──────────┼────────────┤
21+
┏━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━┓
22+
 Compatible  Package   License(s) 
23+
┡━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━┩
2424
│ ✔  │ example0 │ MIT  │
2525
│ ✖  │ example1 │ GPL3  │
2626
└────────────┴──────────┴────────────┘

tests/data/advanced.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
Info
3-
┌─────────────────┬──────────────┐
4-
Item Value
5-
├─────────────────┼──────────────┤
3+
┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
4+
Item Value
5+
┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
66
│ program │ licensecheck │
77
│ version │ 2024 │
88
│ license │ MIT LICENSE │
@@ -11,16 +11,16 @@
1111

1212
List Of
1313
Errors
14-
┌──────────┐
15-
Package
16-
├──────────┤
14+
┏━━━━━━━━━━┓
15+
Package
16+
┡━━━━━━━━━━┩
1717
│ example1 │
1818
└──────────┘
1919

2020
List Of Packages
21-
┌────────────┬──────────┬────────────┐
22-
Compatible Package License(s)
23-
├────────────┼──────────┼────────────┤
21+
┏━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━┓
22+
Compatible Package License(s)
23+
┡━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━┩
2424
│ ✔ │ example0 │ MIT │
2525
│ ✖ │ example1 │ GPL3 │
2626
└────────────┴──────────┴────────────┘

tests/data/simple.ansi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
 
22
 Info 
3-
┌─────────────────┬──────────────┐
4-
 Item   Value  
5-
├─────────────────┼──────────────┤
3+
┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
4+
 Item   Value  
5+
┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
66
│ program  │ licensecheck │
77
│ version  │ 2024  │
88
│ license  │ MIT LICENSE  │
99
│ project_license │ MIT LICENSE  │
1010
└─────────────────┴──────────────┘
1111
 
1212
 List Of Packages 
13-
┌────────────┬─────────┬────────────┐
14-
 Compatible  Package  License(s) 
15-
├────────────┼─────────┼────────────┤
13+
┏━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━┓
14+
 Compatible  Package  License(s) 
15+
┡━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━┩
1616
│ ✖  │ example │ UNKNOWN  │
1717
└────────────┴─────────┴────────────┘

tests/data/simple.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11

22
Info
3-
┌─────────────────┬──────────────┐
4-
Item Value
5-
├─────────────────┼──────────────┤
3+
┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
4+
Item Value
5+
┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
66
│ program │ licensecheck │
77
│ version │ 2024 │
88
│ license │ MIT LICENSE │
99
│ project_license │ MIT LICENSE │
1010
└─────────────────┴──────────────┘
1111

1212
List Of Packages
13-
┌────────────┬─────────┬────────────┐
14-
Compatible Package License(s)
15-
├────────────┼─────────┼────────────┤
13+
┏━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━┓
14+
Compatible Package License(s)
15+
┡━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━┩
1616
│ ✖ │ example │ UNKNOWN │
1717
└────────────┴─────────┴────────────┘

tests/test_get_deps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def test_doGetReqs_requirements() -> None:
6363
"OPENPYXL",
6464
"PANDAS",
6565
"PYTHON-DATEUTIL",
66+
"PYTHON-CALAMINE",
6667
"PYTZ",
6768
"PYXLSB",
6869
"TZDATA",

tests/test_license_matrix.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pathlib import Path
22

3-
from _pytest.logging import LogCaptureFixture
3+
from _pytest.logging import LogCaptureFixture # pyright: ignore [reportMissingImports]
44
from loguru import logger
55

66
from licensecheck import license_matrix, types
@@ -53,16 +53,21 @@ def test_dualLicenseCompat() -> None:
5353
def test_whitelistedLicenseCompat() -> None:
5454
assert license_matrix.depCompatWMyLice(types.L.MIT, [types.L.MIT], onlyLicenses=[types.L.MIT])
5555
assert license_matrix.depCompatWMyLice(types.L.MPL, [types.L.MIT], onlyLicenses=[types.L.MIT])
56-
assert not license_matrix.depCompatWMyLice(types.L.MIT, [types.L.MIT], onlyLicenses=[types.L.MPL])
57-
assert not license_matrix.depCompatWMyLice(types.L.MPL, [types.L.MIT], onlyLicenses=[types.L.MPL])
56+
assert not license_matrix.depCompatWMyLice(
57+
types.L.MIT, [types.L.MIT], onlyLicenses=[types.L.MPL]
58+
)
59+
assert not license_matrix.depCompatWMyLice(
60+
types.L.MPL, [types.L.MIT], onlyLicenses=[types.L.MPL]
61+
)
5862

5963

6064
def test_warningsForIgnoredLicense(caplog: LogCaptureFixture) -> None:
6165
zope = types.ucstr("ZOPE PUBLIC LICENSE")
6266
license_matrix.licenseLookup(zope, [])
63-
assert (
64-
"'ZOPE PUBLIC LICENSE' License not identified so falling back to NO_LICENSE\n"
65-
in caplog.text
67+
assert any(
68+
record.levelname == "WARNING"
69+
and f"'{zope}' License not identified so falling back to NO_LICENSE" in record.message
70+
for record in caplog.records
6671
)
6772

6873

0 commit comments

Comments
 (0)