Kaynağa Gözat

remove tests for removed code

Daniel Sheffield 8 ay önce
ebeveyn
işleme
4c2811da17

+ 1 - 0
test/__init__.py

@@ -0,0 +1 @@
+ALL_UNITS = { 'g', 'kg', 'mL', 'L', 'Pieces', 'Bunches', 'Bags' }

+ 0 - 2
test/rest/templates/__init__.py

@@ -1,2 +0,0 @@
-from bottle import TEMPLATE_PATH
-TEMPLATE_PATH.append("app/rest/templates")

+ 0 - 42
test/rest/templates/test_buttongroup-nav.py

@@ -1,42 +0,0 @@
-from bottle import template
-from pytest import mark
-
-@mark.parametrize('expected', [
-    """<div class="vertical-button-group">
-  <div class="pure-button-group vertical-button-group" role="nav" style="padding: 1em 0.25em 0;">
-    <button
-      class="pure-button "
-      type="submit"
-      formaction="trend"
-      style=""
-    > Trend </button>
-    <button
-      class="pure-button pure-button-active"
-      type="submit"
-      formaction="products"
-      style=""
-    > Products </button>
-    <button
-      class="pure-button "
-      type="submit"
-      formaction="categories"
-      style=""
-    > Categories </button>
-    <button
-      class="pure-button "
-      type="submit"
-      formaction="groups"
-      style=""
-    > Groups </button>
-    <button
-      class="pure-button "
-      type="submit"
-      formaction="tags"
-      style=""
-    > Tags </button>
-  </div>
-</div>"""])
-def test_form_nav_render_exact(expected):
-    assert template('buttongroup-nav', role='nav', action='products', targets=[
-        "trend", "products", "categories", "groups", "tags"
-    ]) == expected

+ 0 - 56
test/rest/templates/test_include-exclude.py

@@ -1,56 +0,0 @@
-import pytest
-from pytest import mark, raises
-from bottle import template
-
-@mark.parametrize('expected, params', [
-    ("""<div class="pure-u-1-3 pure-u-lg-1-6">
-  <div class="pure-g">
-    <div class="pure-u-1">
-      <div class="l-box">
-        <h3>Item</h3>
-      </div>
-    </div>
-<div class="pure-u-1">
-
-<select id="item-include" name="item" size="10" multiple="true" style="width: calc(100% - 1em); margin: 0 1em 1em">
-  <option value="Include" disabled="true" >Include</option>
-
-  <option value="val1-to-backend"  >val1</option>
-  <option value="val2" disabled="true" >val2</option>
-</select>
-</div>
-<div class="pure-u-1">
-
-<select id="item-exclude" name="item" size="10" multiple="true" style="width: calc(100% - 1em); margin: 0 1em 1em">
-  <option value="Exclude" disabled="true" >Exclude</option>
-
-  <option value="val1-to-backend"  >val1</option>
-  <option value="val2" disabled="true" >val2</option>
-</select>
-</div>
-  </div>
-</div>""",{
-    "name": "item",
-    "_include": {
-        "options": [{
-            "value": "val1-to-backend",
-            "display": "val1",
-        },
-        {
-            "value": "val2",
-            "disabled": True,
-        },]
-    },
-    "_exclude": {
-        "options": [{
-            "value": "val1-to-backend",
-            "display": "val1",
-        },
-        {
-            "value": "val2",
-            "disabled": True,
-        },]
-    } }),
-])
-def test_include_exclude_render_exact(expected, params):
-    assert template('include-exclude', **params) == expected

+ 0 - 108
test/rest/templates/test_options.py

@@ -1,108 +0,0 @@
-from pytest import mark, raises
-from bottle import template
-
-@mark.parametrize('expected, params', [
-    ("""<optgroup label="Group">
-  <option value="val-to-backend"  selected="true">val-displayed</option>
-</optgroup>""", {
-    "optgroup": "Group", "options": [
-    {
-        "value": "val-to-backend",
-        "selected": True,
-        "display": "val-displayed",
-    }, ] }),
-    ("""<optgroup label="Group">
-  <option value="val-to-backend" disabled="true" >val-to-backend</option>
-</optgroup>""", { "optgroup": "Group", "options": [
-    {
-        "value": "val-to-backend",
-        "disabled": True,
-    }, ] }),
-    ("""<optgroup label="Group">
-  <option value="val1-to-backend"  >val1</option>
-  <option value="val2-to-backend" disabled="true" >val2-to-backend</option>
-</optgroup>""", { "optgroup": "Group", "options": [
-    {
-        "value": "val1-to-backend",
-        "display": "val1",
-    },
-    {
-        "value": "val2-to-backend",
-        "disabled": True,
-    }, ] }),
-])
-def test_optgroup_render_exact(expected, params):
-    assert template('options', **params) == expected
-
-
-@mark.parametrize('name', [
-    '',
-    None,
-    'Group',
-])
-@mark.parametrize('value', [
-    *[ { "value": v } for v in ("", "val-to-backend", "!val-to-backend", None)],
-    ({}, NameError, "name 'value' is not defined"),
-])
-@mark.parametrize('display', [
-    *[ { "display": v } for v in ("", "val-displayed", None)],
-    {},
-])
-@mark.parametrize('disabled', [
-    *[ { "disabled": v } for v in (True, False, None)],
-    {},
-])
-@mark.parametrize('selected', [
-    *[ { "selected": v } for v in (True, False, None)],
-    {},
-])
-def test_optgroup_render_includes(name, value, selected, disabled, display):
-    options = dict()
-    exp_exceptions = []
-    for part, ex, msg in map(
-        lambda x: x if isinstance(x, tuple) else (x, None, None),
-        (value, selected, disabled, display)):
-        options.update(part)
-        if ex is not None:
-            exp_exceptions.append(ex)
-
-    if not exp_exceptions:
-        assert template('options', optgroup=name, options=[ options, ]) is not None
-        assert template('options', optgroup=name, options=[ options, options ]) is not None
-        return
-
-    with raises(tuple(exp_exceptions)):
-        template('options', optgroup=name, options=[ options, ]) is not None
-    
-    with raises(tuple(exp_exceptions)):
-        template('options', optgroup=name, options=[ options, options ]) is not None
-    
-    return
-
-@mark.parametrize('name', [
-    {},
-    *[ { "optgroup": v } for v in ("", "group", None)],
-])
-@mark.parametrize('options', [
-    ({}, NameError, "name 'options' is not defined"),
-    { "options": [{ "value": "anything" },] },
-    { "options": [{ "value": "opt1" }, { "value": "opt2" }] },
-])
-def test_optgroup_render(name, options):
-    params = dict()
-    exp_exceptions = []
-    for part, ex, msg in map(
-        lambda x: x if isinstance(x, tuple) else (x, None, None),
-        (name, options)):
-        params.update(part)
-        if ex is not None:
-            exp_exceptions.append(ex)
-
-    if not exp_exceptions:
-        assert template('options', **params) is not None
-        return
-
-    with raises(tuple(exp_exceptions)):
-        assert template('options', **params) is not None
-
-    return

+ 0 - 43
test/rest/templates/test_select-one.py

@@ -1,43 +0,0 @@
-import pytest
-from pytest import mark, raises
-from bottle import template
-
-@mark.parametrize('expected, params', [
-    ("""<div class="pure-u-1">
-  <div class="l-box">
-    <h3>Unit</h3>
-  </div>
-</div>
-<div class="pure-u-1">
-
-<select id="unit-select-one" name="unit" size="10"  style="width: calc(100% - 1em); margin: 0 1em 1em">
-
-
-  <option value="Bags"  >Bags</option>
-  <option value="Bunches"  >Bunches</option>
-  <option value="L"  >L</option>
-  <option value="Pieces"  >Pieces</option>
-  <option value="g"  >g</option>
-  <option value="kg"  selected="true">kg</option>
-  <option value="mL"  >mL</option>
-</select>
-</div>""", {
-    "name": "unit", "options": [{
-        "value": "Bags",
-    }, {
-        "value": "Bunches",
-    }, {
-        "value": "L",
-    }, {
-        "value": "Pieces",
-    }, {
-        "value": "g",
-    }, {
-        "value": "kg",
-        "selected": True,
-    }, {
-        "value": "mL",
-    }, ]}, ),
-])
-def test_select_one_render_exact(expected, params):
-    assert template('select-one', **params) == expected

+ 0 - 80
test/rest/templates/test_select.py

@@ -1,80 +0,0 @@
-import pytest
-from pytest import mark, raises
-from bottle import template
-
-@mark.parametrize('expected, params', [
-    ("""<div class="pure-u-1">
-<label for="select-id">Choose: </label>
-<select id="select-id" name="select-name" size="10" multiple="true" style="width: calc(100% - 1em); margin: 0 1em 1em">
-  <option value="hint" disabled="true" >hint</option>
-<optgroup label="Group">
-  <option value="val1-to-backend"  >val1</option>
-  <option value="val2" disabled="true" >val2</option>
-</optgroup>
-</select>
-</div>""", {
-    "id": "select-id", "label": "Choose: ", "name": "select-name",
-    "hint": "hint", "multiple": True, "children": [{"optgroup": "Group", "options": [
-    {
-        "value": "val1-to-backend",
-        "display": "val1",
-    },
-    {
-        "value": "val2",
-        "disabled": True,
-    }, ]}, ]}),
-    ("""<div class="pure-u-1">
-
-<select id="select-unit-id" name="unit" size="10"  style="width: calc(100% - 1em); margin: 0 1em 1em">
-
-
-  <option value="val1"  >val1</option>
-  <option value="val2"  selected="true">val2</option>
-</select>
-</div>""",{
-    "id": "select-unit-id", "name": "unit", "children": [{ "options": [
-    {
-        "value": "val1",
-    },
-    {
-        "value": "val2",
-        "selected": True,
-    }, ]}, ]}),
-    ("""<div class="pure-u-1">
-<label for="select-id">Choose: </label>
-<select id="select-id" name="select-name" size="10" multiple="true" style="width: calc(100% - 1em); margin: 0 1em 1em">
-  <option value="hint" disabled="true" >hint</option>
-<optgroup label="Group">
-  <option value="val1-to-backend"  >val1</option>
-  <option value="val2" disabled="true" >val2</option>
-</optgroup>
-
-  <option value="val1"  >val1</option>
-  <option value="val2"  selected="true">val2</option>
-</select>
-</div>""",{
-    "id": "select-id", "label": "Choose: ", "name": "select-name",
-    "hint": "hint", "multiple": True, "children": [
-        {"optgroup": "Group", "options": [
-            {
-                "value": "val1-to-backend",
-                "display": "val1",
-            },
-            {
-                "value": "val2",
-                "disabled": True,
-            }
-        ]},
-        { "options": [
-            {
-                "value": "val1",
-            },
-            {
-                "value": "val2",
-                "selected": True,
-            },
-        ]},
-    ]})
-])
-def test_select_render_exact(expected, params):
-    assert template('select', **params) == expected

+ 0 - 73
test/rest/test_Cache.py

@@ -1,73 +0,0 @@
-#
-# Copyright (c) Daniel Sheffield 2023
-#
-# All rights reserved
-#
-# THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
-from pytest import fixture
-from time import time
-from app.rest.PageCache import PageCache
-from app.rest.CachedLoadingPage import (
-    CachedLoadingPage,
-    STALE,
-)
-
-@fixture
-def cache():
-    return PageCache(0)
-
-def test_add(cache: PageCache):
-    val = 'test-cached-value'
-    key = 'test-key'
-    assert cache.add(key, CachedLoadingPage(val, lambda _: None, incremental=False)).value == val
-
-def test_get(cache: PageCache):
-    val = 'test-cached-value'
-    key = 'test-key'
-
-    assert cache.get(key) is None
-
-    assert cache.add(key, CachedLoadingPage(val, lambda q: q.put('next-val'), incremental=False)).value == val
-    assert cache.get(key).value == 'next-val'
-
-def test_remove(cache: PageCache):
-    val = 'test-cached-value'
-    key = 'test-key'
-
-    assert cache.get(key) is None
-    assert cache.add(key, CachedLoadingPage(val, lambda q: q.put('next-val'), incremental=False)).value == val
-    cache.remove(key)
-    assert cache.get(key) is None
-
-def test_enforce_limit(cache: PageCache):
-    val = 'test-cached-value'
-    key = 'test-key'
-    assert cache.add(key, CachedLoadingPage(val, lambda _: None, incremental=False)).value == val
-    # adding more exceeds limit
-    assert cache.add('other', CachedLoadingPage(val, lambda _: None, incremental=False)).value == val
-    assert cache.get(key) is None
-    assert cache.get('other').value == val
-
-def test_clean_stale(cache: PageCache):
-    val = 'test-cached-value'
-    key = 'test-key'
-    page = CachedLoadingPage(val, lambda _: None, incremental=False)
-    page._created = time() - STALE
-    # add stale page
-    assert cache.add(key, page).value == val
-    assert cache.get(key) is None
-
-    page = CachedLoadingPage(val, lambda _: None, incremental=False)
-    assert cache.add(key, page).value == val
-    # make page stale
-    page._created = time() - STALE
-    assert cache.get(key) is None
-
-    page = CachedLoadingPage(val, lambda _: None, incremental=False)
-    assert cache.add(key, page).value == val
-    # make page stale
-    page._created = time() - STALE
-    # stale page is rotated out on addition
-    assert cache.add('other', CachedLoadingPage(val, lambda _: None, incremental=False)).value == val
-    assert cache.get(key) is None
-    assert cache.get('other').value == val

+ 0 - 66
test/rest/test_CachedLoadingPage.py

@@ -1,66 +0,0 @@
-#
-# Copyright (c) Daniel Sheffield 2023
-#
-# All rights reserved
-#
-# THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
-from queue import Queue
-from typing import Any, Generator
-from pytest import mark, fixture
-from time import sleep, time
-from app.rest.CachedLoadingPage import (
-    CachedLoadingPage,
-    STALE,
-)
-
-
-@fixture
-def cache():
-    return CachedLoadingPage("start", lambda _: None, incremental=False)
-
-
-def test_get_age(cache: CachedLoadingPage):
-    sleep(0.1)
-    assert cache.age > 0.1
-
-def test_get_queue(cache: CachedLoadingPage):
-    assert type(cache.queue) == Queue
-    cache.queue.put("next", timeout=0.1)
-    assert cache.update() == "next"
-
-def test_get_loaded(cache: CachedLoadingPage):
-    assert cache.loaded is False
-    cache.queue.put("not None", timeout=0.1)
-    assert cache.update() == "not None"
-    assert cache.loaded is False
-    cache.queue.put(None, timeout=0.1)
-    assert cache.update() == "not None"
-    assert cache.loaded is True
-
-def test_update(cache: CachedLoadingPage):
-    cache.queue.put("not None", timeout=0.1)
-    assert cache.update() == "not None"
-    cache.queue.put("next value", timeout=0.1)
-    assert cache.update() == "next value"
-    assert cache.update() == "next value"
-    cache.queue.put("another value", timeout=0.1)
-    cache.queue.put("final value", timeout=0.1)
-    assert cache.update() == "another value"
-    assert cache.update() == "final value"
-    cache.queue.put(None, timeout=0.1)
-    assert cache.update() == "final value"
-    assert cache.loaded is True
-    assert cache.update() == "final value"
-
-def test_stale(cache: CachedLoadingPage):
-    cache._created = time() - STALE
-    assert cache.stale
-
-def test_lock(cache: CachedLoadingPage):
-    cache.queue.put("not None", timeout=0.1)
-    assert cache.update() == "not None"
-    assert cache._lock.acquire()
-    cache.queue.put("next value", timeout=0.1)
-    assert cache.update() == "not None"
-    cache._lock.release()
-    assert cache.update() == "next value"

+ 0 - 126
test/rest/test_form.py

@@ -1,126 +0,0 @@
-#
-# Copyright (c) Daniel Sheffield 2023
-#
-# All rights reserved
-#
-# THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
-from typing import Dict, Iterable, Tuple
-from pandas import DataFrame
-from pytest import fixture, mark
-from app.rest.form import get_option_groups
-
-@fixture
-def data():
-    return DataFrame({
-        'type': ['dog', 'cat', 'horse', 'sheep', 'cow'],
-        'category': ['pet', 'pet', 'utility', 'farm', 'farm'],
-        'group': ['small', 'small', 'large', 'medium', 'large',],
-        'tags': [['a'], ['a','b'], [], [], []],
-        '$/unit': ['1', '2', '3', '4', '5'],
-    })
-
-@mark.parametrize('filter_data, _type, key, parent_grouping, expected', [
-    ({
-        'type': [{'dog'}, {'cat'}]
-    }, 'include', 'type', 'category', [
-        {
-            "optgroup": 'pet', "options": [{
-                "selected": True,
-                "value": "dog",
-                "display": "dog",
-            }]
-        }, {
-            "optgroup": None, "options":[{
-                "selected": False,
-                "value": "cat",
-                "display": "cat",
-            }]
-        }
-    ]), ({
-        'type': [{'dog'}, {'cat'}]
-    }, 'exclude', 'type', 'category', [
-        {
-            "optgroup": 'pet', "options": [{
-                "selected": False,
-                "value": "!dog",
-                "display": "dog",
-            }],
-        }, {
-            "optgroup": None, "options":[{
-                "selected": True,
-                "value": "!cat",
-                "display": "cat",
-            }],
-        }
-    ]), ({
-        'group': [{'small'}, {'large'}]
-    }, 'include', 'group', None, [
-        {
-            "optgroup": None, "options": [ {
-                "selected": False,
-                "value": "large",
-                "display": "large",
-            },{
-                "selected": True,
-                "value": "small",
-                "display": "small",
-            }],
-        }
-    ]), ({
-        'group': [{'small'}, {'large'}]
-    }, 'exclude', 'group', None, [
-        {
-            "optgroup": None, "options": [{
-                "selected": True,
-                "value": "!large",
-                "display": "large",
-            },{
-                "selected": False,
-                "value": "!small",
-                "display": "small",
-            }],
-        }
-    ]),  ({
-        'tag': [{'a'}, {'b'}]
-    }, 'include', 'tag', None, [
-        {
-            "optgroup": None, "options": [ {
-                "selected": True,
-                "value": "a",
-                "display": "a",
-            },{
-                "selected": False,
-                "value": "b",
-                "display": "b",
-            }],
-        }
-    ]), ({
-        'tag': [{'a'}, {'b'}]
-    }, 'exclude', 'tag', None, [
-        {
-            "optgroup": None, "options": [{
-                "selected": False,
-                "value": "!a",
-                "display": "a",
-            },{
-                "selected": True,
-                "value": "!b",
-                "display": "b",
-            }],
-        }
-    ]),
-])
-def test_get_option_groups(
-    data: DataFrame,  _type: str,
-    filter_data: Dict[str, Tuple[set, set]],
-    key: str, parent_grouping: str,
-    expected: Iterable
-):
-
-    _filter = data['type'].apply(lambda _: False)
-    for k, (inc, exc) in filter_data.items():
-        for i in inc:
-            _filter |= (data['tags'].apply(lambda x: i in x) if k == 'tag' else data[k] == i)
-        for i in exc:
-            _filter &= ~(data['tags'].apply(lambda x: i in x) if k == 'tag' else data[k] == i)
-    assert list(get_option_groups(data[_filter], filter_data, key, parent_grouping, _type)) == expected

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 308
test/rest/test_hash_util.py


+ 0 - 76
test/rest/test_route_decorators.py

@@ -1,76 +0,0 @@
-#
-# Copyright (c) Daniel Sheffield 2023
-#
-# All rights reserved
-#
-# THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
-from bottle import FormsDict
-from pytest import fixture, mark, raises
-from app.rest import PARAMS
-from app.rest.route_decorators import (
-    cache,
-    cursor,
-    normalize_query,
-)
-
-def incr(_dict, key):
-    _dict[key] = _dict[key] + 1
-
-@fixture
-def counter():
-    return dict()
-
-@fixture
-def tracker():
-    return dict()
-
-@fixture
-def method(counter, tracker):
-    counter['method'] = 0
-    tracker['method'] = []
-    return lambda *args, **kwargs: incr(counter, 'method') or \
-        tracker['method'].push({'args': args, 'kwargs': kwargs})
-
-@mark.parametrize('form_data, expected', [
-    ([
-        ('product', 'kiwi'),
-        ('product', 'apple'),
-        ('organic', ''),
-    ], ('category=&group=&organic=0.5&product=apple%7Ckiwi&tag=&unit=', None)),
-    ([
-        ('product', 'kiwi'),
-        ('category', '!baking'),
-        ('organic', '1'),
-    ], ('category=%21baking&group=&organic=1&product=kiwi&tag=&unit=', None)),
-])
-def test_normalise_query(form_data, expected):
-    form = FormsDict()
-    for k,v in form_data:
-        form.append(k, v)
-    
-    assert normalize_query(form, allow=PARAMS) == expected
-
-
-# need to mock bottle request.params
-def test_cache(counter, tracker, method):
-    decorated = cache(query_cache=None, page_cache=None)
-    assert callable(decorated)
-    #decorated()
-    #assert counter['method'] == 1
-    #assert tracker['method'][0]['args'] == []
-    #assert tracker['method'][0]['kwargs'] == {'allow': None}
-    with raises(Exception) as ex:
-        cursor(method)
-    assert ex.value.args[0] == "decorator argument required"
-
-
-def test_cursor(counter, tracker, method):
-    decorated = cursor(cache=None)
-    assert callable(decorated)
-    #decorated()
-    #assert counter['method'] == 1
-    #assert tracker['method'][0]['args'] == []
-    #assert tracker['method'][0]['kwargs'] == {'allow': None}
-    with raises(Exception) as ex:
-        cursor(method)
-    assert ex.value.args[0] == "decorator argument required"

+ 1 - 1
test/test_parse_recipe.py

@@ -7,7 +7,7 @@
 from pytest import fixture
 from app.parse_recipe import parse_recipe
 from app.data.QueryManager import QueryManager
-from app.rest import ALL_UNITS
+from . import ALL_UNITS
 
 @fixture
 def blank_recipe():

+ 3 - 3
test/test_widgets.py

@@ -8,7 +8,7 @@ from typing import Dict, List, Tuple
 from pytest import fixture, mark
 from app.parse_recipe import parse_recipe
 from app.data.QueryManager import QueryManager
-from app.rest import ALL_UNITS
+from . import ALL_UNITS
 
 from app.widgets import (
     SuggestionPopup,
@@ -46,7 +46,7 @@ def test_suggestion_popup_choice(suggestion_popup: SuggestionPopup, tracker: Dic
     assert len(tracker.keys()) == 0
     suggestion_popup.keypress((0,0), 'enter')
     assert tracker['identifier'] == options[pos]
-    
+
 def test_suggestion_popup_banish(suggestion_popup: SuggestionPopup, tracker: Dict[str, str], options: List[str], signals):
     suggestion_popup.keypress((0,0), 'esc')
     assert len(tracker.keys()) == 0
@@ -82,4 +82,4 @@ def test_no_tab_checkbox(notabcheckbox: NoTabCheckBox):
     notabcheckbox.keypress((0,0), 'tab')
     assert notabcheckbox.get_state() == state
     notabcheckbox.keypress((0,0), 'enter')
-    assert notabcheckbox.get_state() != state
+    assert notabcheckbox.get_state() != state

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor