Skip to content

Commit

Permalink
debug tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sup2point0 committed May 25, 2024
1 parent ef035ff commit eb31121
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 40 deletions.
29 changes: 16 additions & 13 deletions quarkdown/classes/export_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .. import textualise


@ dataclass(kw_only = True)
@ dataclass(kw_only = True, slots = True)
class ExportFile:
'''A container for all the export info of a file.'''

Expand All @@ -29,6 +29,7 @@ class ExportFile:
source_url: str = None

live: bool = None
is_index: bool = False

title: str = "Assort"
header: str = None
Expand Down Expand Up @@ -81,19 +82,22 @@ def set_flags(self, data: dict):
for style in sup.it.unique(styles)
]

# if no duality set, find default by cascading backwards
duality = (
flags["styles"][style].get("duality", None)
for style in reversed(self.styles)
)
self.duality = data.get("duality", next(
(each for each in duality if each),
flags["styles"]["default"]["duality"]
)).lower()
try:
self.duality = data["duality"]
except KeyError:
# cascade backwards over style defaults
defaults = (
flags["styles"].get(style, {}).get("duality", None)
for style in reversed(self.styles)
)
self.duality = next(
(each for each in defaults if each),
flags["styles"]["default"]["duality"]
).lower()

# indexes listed by relevance so order retained
indexes = data.get("indexes", [])
self.indices = list(sup.it.unique(
self.indexes = list(sup.it.unique(
itertools.chain.from_iterable(
self.export_path_frags if index.lower() == "auto" else index.lower()
for index in indexes
Expand Down Expand Up @@ -121,5 +125,4 @@ def set_flags(self, data: dict):
def export_dict(self) -> dict:
'''Extract a concise `dict` representation of the exported file.'''

attrs = vars(self)
return {each: attrs[each] for each in attrs if each in self.EXPORT_DATA}
return {each: getattr(self, each) for each in self.EXPORT_DATA}
2 changes: 1 addition & 1 deletion suptools
Submodule suptools updated 2 files
+5 −3 source/io.py
+1 −1 weighted-list
34 changes: 17 additions & 17 deletions tests/test-core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,50 @@
Test export metadata handling.
'''

# we really need to find a proper way to do this
import sys
sys.path[0] = "/".join(sys.path[0].split("/")[:-1])
import datetime

import quarkdown as qk


def test_single(file):
file.content = '''
def test_single(source, encode):
file = qk.ExportFile(file = source)
file.content = encode('''
<!-- #QUARK live!
EXPORT: testing/test
STYLE: default
DUALITY: light
INDEX: tests
DATE: 24
-->
'''
''')

result = qk.extract(file)

assert result.live is True
assert result.path == "testing/test"
assert result.style == ["default"]
assert result.export_path == "testing/test.html"
assert result.styles == ["default"]
assert result.duality == "light"
assert result.index == ["tests"]
assert result.date == ["24"]
assert result.indexes == ["tests"]
assert result.date == datetime.date(24, 0, 1)


def test_multi():
file = '''
def test_multi(source, encode):
file = qk.ExportFile(file = source)
file.content = encode('''
<!-- #QUARK live!
EXPORT: testing/tester/test scarlet/herring
STYLE: default special testing
DUALITY: light ignore
INDEX: tests testing
DATE: 24 04 02
-->
'''
''')

result = qk.extract(file)

assert result.live is True
assert result.path == "testing/tester/test"
assert result.style == ["default", "special", "testing"]
assert result.export_path == "testing/tester/test.html"
assert result.styles == ["default", "special", "testing"]
assert result.duality == "light"
assert result.index == ["tests", "testing"]
assert result.date == ["24", "04", "02"]
assert result.indexes == ["tests", "testing"]
assert result.date == datetime.date("24", "04", "02")
5 changes: 4 additions & 1 deletion tests/test-exportfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import quarkdown as qk


def test_export(file):
def test_export(source, encode):
file = qk.ExportFile(file = source)
file.content = encode("test")

result = qk.extract(file)
assert isinstance(result, qk.ExportFile)
15 changes: 7 additions & 8 deletions tests/test-index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
Test index page exporting.
'''

# we really need to find a proper way to do this
import sys
sys.path[0] = "/".join(sys.path[0].split("/")[:-1])
import quarkdown as qk

from quarkdown import quarkify


def test_positive():
result = quarkify.extract('''
def test_positive(source, encode):
file = qk.ExportFile(file = source)
file.content = encode('''
<!-- #QUARK live! index! -->
''')

assert result["is-index"] is True, "index page not detected!"
result = qk.extract(file)

assert result.is_index is True, "index page not detected!"

0 comments on commit eb31121

Please sign in to comment.