mirror of
https://github.com/StevenBlack/hosts.git
synced 2026-07-01 02:36:52 +00:00
Unification of the sorting of the sources.
Before this patch, there was no proper sorting and the sources. As @XhmikosR mentioned in StevenBlack/hosts#1166, without this patch, the output is totally different in Windows. But let's be honest, if it is like that under Windows, chances are that the same behavior happens across different OSes or machines around the globe. Another reason behind this patch is that - desperate the fact that we certainly trust @StevenBlack - the integrity of the generated files could not be guarenteed because of the sorting which may be completely different from an OS to another and a machine to another. For those reasons, this patch introduces a unification of the sorting of all sources. The idea behind this patch is to have @StevenBlack's ad-hoc hosts file always on top (1st) and the rest of the sources sorted alphabetically based on the name of the folder inside the `data` or `extensions` directory. This will ensure that we get the same result everywhere. Concretely speaking, I just added the function (`sort_sources`) which sorts a given list of sources files. And later on, call the new function everywhere it was necessary. Tests of the newly introduced function are also included. Contributors: * @ScriptTiger * @XhmikosR Notes: * This patch fix (completely ?) ScriptTiger/hosts#1 * This patch fix https://github.com/StevenBlack/hosts/issues/1166#issuecomment-590511086
This commit is contained in:
@@ -41,6 +41,7 @@ from updateHostsFile import (
|
||||
query_yes_no,
|
||||
recursive_glob,
|
||||
remove_old_hosts_file,
|
||||
sort_sources,
|
||||
strip_rule,
|
||||
supports_color,
|
||||
update_all_sources,
|
||||
@@ -131,6 +132,80 @@ class TestGetDefaults(Base):
|
||||
# End Project Settings
|
||||
|
||||
|
||||
class TestSortSources(Base):
|
||||
def test_sort_sources_simple(self):
|
||||
given = [
|
||||
"sbc.io",
|
||||
"example.com",
|
||||
"github.com",
|
||||
]
|
||||
|
||||
expected = ["example.com", "github.com", "sbc.io"]
|
||||
|
||||
actual = sort_sources(given)
|
||||
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_live_data(self):
|
||||
given = [
|
||||
"data/KADhosts/update.json",
|
||||
"data/someonewhocares.org/update.json",
|
||||
"data/StevenBlack/update.json",
|
||||
"data/adaway.org/update.json",
|
||||
"data/URLHaus/update.json",
|
||||
"data/UncheckyAds/update.json",
|
||||
"data/add.2o7Net/update.json",
|
||||
"data/mvps.org/update.json",
|
||||
"data/add.Spam/update.json",
|
||||
"data/add.Dead/update.json",
|
||||
"data/malwaredomainlist.com/update.json",
|
||||
"data/Badd-Boyz-Hosts/update.json",
|
||||
"data/hostsVN/update.json",
|
||||
"data/yoyo.org/update.json",
|
||||
"data/add.Risk/update.json",
|
||||
"data/tiuxo/update.json",
|
||||
"extensions/gambling/update.json",
|
||||
"extensions/porn/clefspeare13/update.json",
|
||||
"extensions/porn/sinfonietta-snuff/update.json",
|
||||
"extensions/porn/tiuxo/update.json",
|
||||
"extensions/porn/sinfonietta/update.json",
|
||||
"extensions/fakenews/update.json",
|
||||
"extensions/social/tiuxo/update.json",
|
||||
"extensions/social/sinfonietta/update.json",
|
||||
]
|
||||
|
||||
expected = [
|
||||
"data/StevenBlack/update.json",
|
||||
"data/adaway.org/update.json",
|
||||
"data/add.2o7Net/update.json",
|
||||
"data/add.Dead/update.json",
|
||||
"data/add.Risk/update.json",
|
||||
"data/add.Spam/update.json",
|
||||
"data/Badd-Boyz-Hosts/update.json",
|
||||
"data/hostsVN/update.json",
|
||||
"data/KADhosts/update.json",
|
||||
"data/malwaredomainlist.com/update.json",
|
||||
"data/mvps.org/update.json",
|
||||
"data/someonewhocares.org/update.json",
|
||||
"data/tiuxo/update.json",
|
||||
"data/UncheckyAds/update.json",
|
||||
"data/URLHaus/update.json",
|
||||
"data/yoyo.org/update.json",
|
||||
"extensions/fakenews/update.json",
|
||||
"extensions/gambling/update.json",
|
||||
"extensions/porn/clefspeare13/update.json",
|
||||
"extensions/porn/sinfonietta/update.json",
|
||||
"extensions/porn/sinfonietta-snuff/update.json",
|
||||
"extensions/porn/tiuxo/update.json",
|
||||
"extensions/social/sinfonietta/update.json",
|
||||
"extensions/social/tiuxo/update.json",
|
||||
]
|
||||
|
||||
actual = sort_sources(given)
|
||||
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
|
||||
# Prompt the User
|
||||
class TestPromptForUpdate(BaseStdout, BaseMockDir):
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user