Skip to content

Commit 3880618

Browse files
committed
Fix tests and update project
Fix tests that were broken as a result of 1a314e3 ("Simplify by simply linking to /all/"). Upgrade project to use uv for dependencies, linting, and formatting. Signed-off-by: Dan Rue <danrue@gmail.com>
1 parent 1a314e3 commit 3880618

9 files changed

Lines changed: 496 additions & 77 deletions

File tree

.flake8

Lines changed: 0 additions & 2 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
__pycache__
22
*.swp
3+
.venv/

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
all: black flake8 test
1+
all: format lint test
22

3-
black:
4-
black *.py
3+
format:
4+
uv run ruff format *.py
55

6-
flake8:
7-
flake8
6+
lint:
7+
uv run ruff check *.py
88

99
test:
10-
pytest
10+
uv run pytest

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Lorifier
22

3-
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
3+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
44

55
Lorifier is a mutt display filter that is used to add
66
[lore](https://www.kernel.org/lore.html) links to compatible emails, when
@@ -32,8 +32,8 @@ Message-ID from the displayed email, so that it will not be displayed.
3232

3333
## Requirements
3434

35-
lorifier.py requires python 3, and has been tested with 3.7.
35+
lorifier.py requires python 3.
3636

3737
## Testing
3838

39-
Run 'make test' or 'pytest'. Requires pytest.
39+
Run 'make' or 'uv run pytest'.

lorifier.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020

2121
import email
2222
import email.policy
23-
import os
2423
import sys
25-
import time
2624

2725
from email.utils import mktime_tz, parsedate_tz, formatdate
2826

29-
LORE_MASK = 'https://lore.kernel.org/all/%s'
27+
LORE_MASK = "https://lore.kernel.org/all/%s"
3028

3129

3230
class muttemail:
@@ -37,7 +35,7 @@ def as_string(self):
3735
return self.message.as_string(policy=email.policy.EmailPolicy(utf8=True))
3836

3937
def create_xdate_header(self):
40-
""" Add an X-Date header, which is Date converted to localtime. """
38+
"""Add an X-Date header, which is Date converted to localtime."""
4139
date = self.message.get("Date", None)
4240
if not date:
4341
return
@@ -47,11 +45,11 @@ def create_xdate_header(self):
4745
self.message.add_header("X-Date", formatdate(epoch_time, localtime=True))
4846

4947
def remove_header(self, header):
50-
""" Remove the named header """
48+
"""Remove the named header"""
5149
for i in reversed(range(len(self.message._headers))):
5250
header_name = self.message._headers[i][0].lower()
5351
if header_name == header.lower():
54-
del (self.message._headers[i])
52+
del self.message._headers[i]
5553

5654
def create_xuri_header(self):
5755
"""

pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[project]
2+
name = "lorifier"
3+
version = "0.1.0"
4+
description = "Mutt display filter that adds lore.kernel.org links to emails"
5+
readme = "README.md"
6+
license = "BSD-2-Clause"
7+
requires-python = ">=3.7"
8+
dependencies = []
9+
10+
[dependency-groups]
11+
dev = [
12+
"ruff",
13+
"pytest",
14+
"pytest-mock",
15+
]
16+
17+
[tool.ruff]
18+
line-length = 120
19+
20+
[tool.ruff.lint]
21+
select = ["E", "F", "W"]

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

test_lorifier.py

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import lorifier
2-
import os
31
import subprocess
4-
import time
5-
import urllib
62

73

84
def test_sample_1():
9-
""" Just a typical example email """
5+
"""Just a typical example email"""
106
out = subprocess.run(
117
"cat samples/1.email | ./lorifier.py",
128
shell=True,
@@ -16,14 +12,14 @@ def test_sample_1():
1612
assert len(out.stderr) == 0
1713
lines = [
1814
"\nX-Date: ",
19-
"\nX-URI: https://lore.kernel.org/lkml/20181201095551.GN8952@piout.net\n",
15+
"\nX-URI: https://lore.kernel.org/all/20181201095551.GN8952@piout.net\n",
2016
]
2117
for line in lines:
2218
assert line in out.stdout.decode("utf-8")
2319

2420

2521
def test_sample_2():
26-
""" A typical example, with emoji in body """
22+
"""A typical example, with emoji in body"""
2723
out = subprocess.run(
2824
"cat samples/2.email | ./lorifier.py",
2925
shell=True,
@@ -33,7 +29,7 @@ def test_sample_2():
3329
assert len(out.stderr) == 0
3430
lines = [
3531
"\nX-Date: ",
36-
"\nX-URI: https://lore.kernel.org/lkml/20181201095551.GN8952@piout.net\n",
32+
"\nX-URI: https://lore.kernel.org/all/20181201095551.GN8952@piout.net\n",
3733
"\nHello,\n",
3834
"\nHere is some emoji! 🍌🍌🚀🚀\n",
3935
]
@@ -42,7 +38,7 @@ def test_sample_2():
4238

4339

4440
def test_sample_3():
45-
""" UTF-8 headers """
41+
"""UTF-8 headers"""
4642
out = subprocess.run(
4743
"cat samples/3.email | ./lorifier.py",
4844
shell=True,
@@ -52,56 +48,9 @@ def test_sample_3():
5248
assert len(out.stderr) == 0
5349
lines = [
5450
"\nX-Date: ",
55-
"\nX-URI: https://lore.kernel.org/lkml/CADYN=9LEVUgz_ou6kWrXZGBpUZ5Ti7BB+0Uxp1NtP18BJDVHCg@mail.gmail.com\n",
51+
"\nX-URI: https://lore.kernel.org/all/CADYN=9LEVUgz_ou6kWrXZGBpUZ5Ti7BB+0Uxp1NtP18BJDVHCg@mail.gmail.com\n",
5652
"\nCc: =?UTF-8?B?RGFuaWVsIETDrWF6?= <daniel.diaz@linaro.org>,\n",
5753
'\n "open list:KERNEL SELFTEST FRAMEWORK" \n',
5854
]
5955
for line in lines:
6056
assert line in out.stdout.decode("utf-8")
61-
62-
63-
def test_get_lorifier_list_fresh(mocker):
64-
with open("samples/lists.txt") as f:
65-
lists = f.read()
66-
with open(".in", "w") as f:
67-
f.write(lists)
68-
mocker.patch("urllib.request.urlretrieve")
69-
lore_lists = lorifier.muttemail._get_lorifier_list(
70-
cache_file=os.path.abspath(".in")
71-
)
72-
urllib.request.urlretrieve.assert_not_called()
73-
assert len(lore_lists) == 29
74-
for line in lists.splitlines():
75-
(key, value) = line.split(": ")
76-
assert lore_lists[key] == value
77-
os.remove(".in")
78-
79-
80-
def test_get_lorifier_list_old(mocker):
81-
with open("samples/lists.txt") as f:
82-
lists = f.read()
83-
with open(".in", "w") as f:
84-
f.write(lists)
85-
os.utime(".in", (time.time(), time.time() - 604800))
86-
87-
mocker.patch("urllib.request.urlretrieve")
88-
lorifier.muttemail._get_lorifier_list(
89-
url="https://lore.kernel.org/lists.txt",
90-
cache_file=os.path.abspath(".in"),
91-
cache_ttl=86400,
92-
)
93-
urllib.request.urlretrieve.assert_called_once_with(
94-
"https://lore.kernel.org/lists.txt", os.path.abspath(".in")
95-
)
96-
97-
os.remove(".in")
98-
99-
100-
def test_get_lorifier_list_first_run(mocker):
101-
mocker.patch("urllib.request.urlretrieve")
102-
lorifier.muttemail._get_lorifier_list(
103-
url="https://lore.kernel.org/lists.txt", cache_file=os.path.abspath(".in")
104-
)
105-
urllib.request.urlretrieve.assert_called_once_with(
106-
"https://lore.kernel.org/lists.txt", os.path.abspath(".in")
107-
)

0 commit comments

Comments
 (0)