Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adbar committed Apr 24, 2024
1 parent 9501a71 commit 5d73e29
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions tests/urlstore_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import tempfile
import uuid

from copy import copy
from datetime import datetime
from time import sleep

Expand Down Expand Up @@ -297,17 +298,22 @@ def test_urlstore():
).total_seconds() < 0.25
assert my_urls.urldict["https://www.example.org"].count == 3

downloadable_urls = my_urls.get_download_urls(time_limit=0)
# does not work on Windows?
if os.name != "nt":
assert (
len(downloadable_urls) == 2
and downloadable_urls[0].startswith("https://www.example.org")
and downloadable_urls[1].startswith("https://test.org")
)
assert my_urls.urldict["https://test.org"].count == 1
downloadable_urls = my_urls.get_download_urls()
# if os.name != "nt":
test_urls = UrlStore()
test_urls.add_urls(
["https://www.example.org/1", "https://test.org/1", "https://test.org/2"]
)
downloadable_urls = test_urls.get_download_urls(time_limit=0)
assert (
len(downloadable_urls) == 2
and downloadable_urls[0].startswith("https://www.example.org")
and downloadable_urls[1].startswith("https://test.org")

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High test

The string
https://test.org
may be at an arbitrary position in the sanitized URL.
and test_urls.urldict["https://test.org"].count == 1
)
downloadable_urls = test_urls.get_download_urls()
assert len(downloadable_urls) == 0

other_store = UrlStore()
downloadable_urls = other_store.get_download_urls()
assert not downloadable_urls and other_store.done is True
Expand All @@ -329,18 +335,18 @@ def test_urlstore():
assert (
len(schedule) == 1
and round(schedule[0][0]) == 1
and schedule[0][1] == "https://www.example.org/3"
and schedule[0][1].startswith("https://www.example.org")

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High test

The string
https://www.example.org
may be at an arbitrary position in the sanitized URL.
)
schedule = my_urls.establish_download_schedule(max_urls=6, time_limit=1)
assert len(schedule) == 6 and round(max(s[0] for s in schedule)) == 4
assert my_urls.urldict["https://www.example.org"].count == 8
assert my_urls.urldict["https://www.example.org"].count == 7
assert (
my_urls.urldict["https://test.org"].count
== 4
== 3
== sum(u.visited is True for u in my_urls.urldict["https://test.org"].tuples)
)
assert my_urls.download_threshold_reached(9) is False
assert my_urls.download_threshold_reached(8) is True
assert my_urls.download_threshold_reached(8) is False
assert my_urls.download_threshold_reached(7) is True


def test_dbdump(capsys):
Expand Down

0 comments on commit 5d73e29

Please sign in to comment.