diff --git a/pyproject.toml b/pyproject.toml index c35dce1a..dfda62b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,10 +23,8 @@ dependencies = [ 'websockets', 'addict>=2.4.0', 'jinja2>=3.1.2', - 'demjson3>=3.0.5', 'hjson>=3.1.0', - 'PyYAML>=6.0', - 'httpx>=0.23.0', + 'httpx>=0.23.0', 'aiofiles', 'twine', 'wheel' diff --git a/tests/test_benchmark_decode.py b/tests/test_benchmark_decode.py deleted file mode 100644 index 5fa012fc..00000000 --- a/tests/test_benchmark_decode.py +++ /dev/null @@ -1,80 +0,0 @@ -""" -Created on 2022-09-05 - -@author: hr -""" -from timeit import timeit - -import yaml -import hjson -import demjson3 as demjson - -from tests.basetest import Basetest - - -class TestBenchmarkDecode(Basetest): - """ - Benchmarks decoding performance - """ - - # example options string see - # https://www.highcharts.com/docs/getting-started/how-to-set-options - options_string: str = """{ - chart: { - renderTo: 'container', - type: 'bar' - }, - title: { - text: 'Fruit Consumption' - }, - xAxis: { - categories: ['Apples', 'Bananas', 'Oranges'] - }, - yAxis: { - title: { - text: 'Fruit eaten' - } - }, - series: [{ - name: 'Jane', - data: [1, 0, 4] - }, { - name: 'John', - data: [5, 7, 3] - }] - }""" - - def test_decode_time_demjson(self): - """ - test demjson - """ - elapsed = timeit( - lambda: demjson.decode(self.options_string.encode("ascii", "ignore")), - number=1000, - ) - print(f"Time: {elapsed:.2f}s") - self.assertGreater(elapsed, 0.0) - - def test_decode_time_yaml(self): - """ - test yaml - """ - - elapsed = timeit( - lambda: yaml.full_load(self.options_string.encode("ascii", "ignore")), - number=1000, - ) - print(f"Time: {elapsed:.2f}s") - self.assertGreater(elapsed, 0.0) - - def test_decode_time_hjson(self): - """ - test hjson - """ - - elapsed = timeit( - lambda: hjson.loads(self.options_string.encode("ascii", "ignore")), - number=1000, - ) - print(f"Time: {elapsed:.2f}s") - self.assertGreater(elapsed, 0.0) diff --git a/tests/test_demjson.py b/tests/test_demjson.py deleted file mode 100644 index 40e8f9e3..00000000 --- a/tests/test_demjson.py +++ /dev/null @@ -1,79 +0,0 @@ -""" -Created on 2022-08-20 - -@author: wf -""" -import demjson3 - -from tests.basetest import Basetest -import demjson3 as demjson -from addict import Dict - - -class TestDemJson(Basetest): - """ - Tests demjson - """ - - def testDemjson(self): - """ - test demjson - """ - # example options string see - # https://www.highcharts.com/docs/getting-started/how-to-set-options - options_string = """{ - chart: { - renderTo: 'container', - type: 'bar' - }, - title: { - text: 'Fruit Consumption' - }, - xAxis: { - categories: ['Apples', 'Bananas', 'Oranges'] - }, - yAxis: { - title: { - text: 'Fruit eaten' - } - }, - series: [{ - name: 'Jane', - data: [1, 0, 4] - }, { - name: 'John', - data: [5, 7, 3] - }] -}""" - options = Dict(demjson.decode(options_string.encode("ascii", "ignore"))) - debug = self.debug - # debug=True - if debug: - print(options) - self.assertTrue("chart" in options) - pass - - def test_decode_no_separating_spaces(self): - """ - test JavaScript object decoding - """ - # example options string see - # https://www.highcharts.com/docs/getting-started/how-to-set-options - options_string = """{ - title:{ - text:'Fruit Consumption' - }, - xAxis: { - categories: ['Apples', 'Bananas', 'Oranges'] - }, - series:[] -}""" - options = Dict(demjson3.decode(options_string.encode("ascii", "ignore"))) - debug = self.debug - # debug=True - if debug: - print(options) - self.assertTrue("series" in options) - self.assertTrue("title" in options) - self.assertTrue("text" in options["title"]) - pass diff --git a/tests/test_jsobject.py b/tests/test_jsobject.py index bec6b462..a228d887 100644 --- a/tests/test_jsobject.py +++ b/tests/test_jsobject.py @@ -3,48 +3,55 @@ @author: hr """ +import os +import unittest +from timeit import timeit + import hjson from tests.basetest import Basetest from addict import Dict +SLOW_TESTS = bool(os.environ.get('JP_SLOW_TESTS', False)) + class TestJavaScriptObject(Basetest): """ - Tests JavaScript object conversion via PyYaml + Tests JavaScript object conversion via hjson """ + # example options string see + # https://www.highcharts.com/docs/getting-started/how-to-set-options + options_string: str = """{ + chart: { + renderTo: 'container', + type: 'bar' + }, + title: { + text: 'Fruit Consumption' + }, + xAxis: { + categories: ['Apples', 'Bananas', 'Oranges'] + }, + yAxis: { + title: { + text: 'Fruit eaten' + } + }, + series: [{ + name: 'Jane', + data: [1, 0, 4] + }, { + name: 'John', + data: [5, 7, 3] + }] + }""" + def test_decode(self): """ test JavaScript object decoding """ - # example options string see - # https://www.highcharts.com/docs/getting-started/how-to-set-options - options_string = """{ - chart: { - renderTo: 'container', - type: 'bar' - }, - title: { - text: 'Fruit Consumption' - }, - xAxis: { - categories: ['Apples', 'Bananas', 'Oranges'] - }, - yAxis: { - title: { - text: 'Fruit eaten' - } - }, - series: [{ - name: 'Jane', - data: [1, 0, 4] - }, { - name: 'John', - data: [5, 7, 3] - }] -}""" - options = Dict(hjson.loads(options_string.encode("ascii", "ignore"))) + options = Dict(hjson.loads(self.options_string.encode("ascii", "ignore"))) debug = self.debug # debug=True if debug: @@ -104,3 +111,14 @@ def test_decode_dirty_js2(self): options = hjson.loads(dirty_js) self.assertTrue("key2" in options) self.assertTrue("key" in options) + + @unittest.skipIf(not SLOW_TESTS, "JP_SLOW_TESTS") + def test_decode_time(self): + """ + test decoding time + """ + no_runs = 1000 + elapsed = timeit(lambda: hjson.loads(self.options_string.encode("ascii", "ignore")), + number=no_runs) + print(f'Time elapsed for {no_runs} runs: {elapsed:.2f}s') + self.assertGreater(elapsed, 0.0)