def test_legendWidth(self): """Test SVG export: legend width variations""" if os.path.isdir('mass'): shutil.rmtree('mass') index = 0 os.mkdir('mass') os.mkdir('mass/output') for legendWidth in [3, 6]: for legendHeight in [1, 2]: for legendX in [2, 4]: for legendY in [2, 4]: c = SVGConfig(legendDocked=False, legendWidth=legendWidth, legendHeight=legendHeight, legendX=legendX, legendY=legendY) l1.layer.description = f"undocked legend, {legendWidth}x{legendHeight} at {legendX}x{legendY}" t = ToSvg(domain=l1.layer.domain, source=source, resource=resource, config=c) t.to_svg(l1, filepath=f"mass/output/{index}.svg") e = ToExcel(domain=l1.layer.domain, source=source, resource=resource) e.to_xlsx(l1, filepath=f"mass/output/{index}.xlsx") assert os.path.exists(f"mass/output/{index}.xlsx") assert os.path.exists(f"mass/output/{index}.svg") index += 1 shutil.rmtree('mass')
def test_aggregate(): """Test aggregate layer exports (agg configurations are present in each layer)""" if os.path.isdir("agg_tests"): shutil.rmtree("agg_tests") os.mkdir("agg_tests") listing = [ testing_data.agg_layer_1, testing_data.agg_layer_2, testing_data.agg_layer_3, testing_data.agg_layer_5, testing_data.agg_layer_6, testing_data.agg_layer_7 ] for lay in listing: test_layer = Layer() test_layer.from_str(lay) exporter = ToExcel(domain=test_layer.layer.domain, source='taxii', resource=None) exporter.to_xlsx( layerInit=test_layer, filepath=f"agg_tests/layer-{test_layer.layer.name}.xlsx") exp = ToSvg(domain=test_layer.layer.domain, source='taxii', resource=None) exp.to_svg(test_layer, filepath=f"agg_tests/layer-{test_layer.layer.name}.svg") assert os.path.isfile( f"agg_tests/layer-{test_layer.layer.name}.xlsx") assert os.path.isfile( f"agg_tests/layer-{test_layer.layer.name}.svg") shutil.rmtree("agg_tests")
def test_showSubtechniques(self): """Test SVG export: Displaying Subtechniques""" if os.path.isdir('mass'): shutil.rmtree('mass') index = 0 os.mkdir('mass') os.mkdir('mass/output') for showSubtechniques in ["all", "expanded", "none"]: for showHeader in [True, False]: c = SVGConfig(showSubtechniques=showSubtechniques, showHeader=showHeader) l1.layer.description = f"subs={showSubtechniques},showHeader={showHeader}" t = ToSvg(domain=l1.layer.domain, source=source, resource=resource, config=c) t.to_svg(l1, filepath=f"mass/output/{index}.svg") e = ToExcel(domain=l1.layer.domain, source=source, resource=resource) e.to_xlsx(l1, filepath=f"mass/output/{index}.xlsx") assert os.path.exists(f"mass/output/{index}.xlsx") assert os.path.exists(f"mass/output/{index}.svg") index += 1 shutil.rmtree('mass')
def test_counts(self): """Test SVG export: scores/aggregation""" if os.path.isdir('mass'): shutil.rmtree('mass') index = 0 os.mkdir('mass') os.mkdir('mass/output') for countUnscored in [True, False]: for aggregateFunction in ["average", "min", "max", "sum"]: l1.layer.layout.countUnscored = countUnscored l1.layer.layout.aggregateFunction = aggregateFunction l1.layer.description = f"countUnscored={countUnscored}, aggregateFunction={aggregateFunction}" print(l1.layer.description) t = ToSvg(domain=l1.layer.domain, source=source, resource=resource) t.to_svg(l1, filepath=f"mass/output/{index}.svg") e = ToExcel(domain=l1.layer.domain, source=source, resource=resource) e.to_xlsx(l1, filepath=f"mass/output/{index}.xlsx") assert os.path.exists(f"mass/output/{index}.xlsx") assert os.path.exists(f"mass/output/{index}.svg") index += 1 shutil.rmtree('mass')
def test_dimensions(self): """Test SVG export: dimensions""" if os.path.isdir('mass'): shutil.rmtree('mass') index = 0 os.mkdir('mass') os.mkdir('mass/output') for width in [8.5, 11]: for height in [8.5, 11]: for headerHeight in [1, 2]: for unit in ["in", "cm"]: c = SVGConfig(width=width, height=height, headerHeight=headerHeight, unit=unit) l1.layer.description = f"{width}x{height}{unit}; header={headerHeight}" t = ToSvg(domain=l1.layer.domain, source=source, resource=resource, config=c) t.to_svg(l1, filepath=f"mass/output/{index}.svg") e = ToExcel(domain=l1.layer.domain, source=source, resource=resource) e.to_xlsx(l1, filepath=f"mass/output/{index}.xlsx") assert os.path.exists(f"mass/output/{index}.xlsx") assert os.path.exists(f"mass/output/{index}.svg") index += 1 shutil.rmtree('mass')
def test_borders(self): """Test SVG export: borders""" if os.path.isdir('mass'): shutil.rmtree('mass') index = 0 os.mkdir('mass') os.mkdir('mass/output') for border in [0.1, 0.3]: for tableBorderColor in ["#ddd", "#ffaaaa"]: c = SVGConfig(border=border, tableBorderColor=tableBorderColor) l1.layer.description = f"border={border}, tableBorderColor={tableBorderColor}" t = ToSvg(domain=l1.layer.domain, source=source, resource=resource, config=c) t.to_svg(l1, filepath=f"mass/output/{index}.svg") e = ToExcel(domain=l1.layer.domain, source=source, resource=resource) e.to_xlsx(l1, filepath=f"mass/output/{index}.xlsx") assert os.path.exists(f"mass/output/{index}.xlsx") assert os.path.exists(f"mass/output/{index}.svg") index += 1 shutil.rmtree('mass')
def test_showFilters(self): """Test SVG export: customization options""" if os.path.isdir('mass'): shutil.rmtree('mass') index = 0 os.mkdir('mass') os.mkdir('mass/output') for showFilters in [True, False]: for showAbout in [True, False]: for showLegend in [True, False]: for showDomain in [True, False]: c = SVGConfig(showFilters=showFilters, showAbout=showAbout, showLegend=showLegend, showDomain=showDomain) l1.layer.description = f"legend={showLegend}, filters={showFilters}, about={showAbout}" t = ToSvg(domain=l1.layer.domain, source=source, resource=resource, config=c) t.to_svg(l1, filepath=f"mass/output/{index}.svg") e = ToExcel(domain=l1.layer.domain, source=source, resource=resource) e.to_xlsx(l1, filepath=f"mass/output/{index}.xlsx") assert os.path.exists(f"mass/output/{index}.xlsx") assert os.path.exists(f"mass/output/{index}.svg") index += 1 shutil.rmtree('mass')
def test_config_load(): """Test loading a svg config""" lay = Layer(testing_data.example_layer_v3_all) exp = ToSvg(domain=lay.layer.domain) exp.config.load_from_file("resources/demo.json") exp.config.__str__() exp.to_svg(lay) os.remove('example.svg')
def test_depreciated_tactics_export(): """Test exporting a layer with depreciated tactics""" if os.path.isfile("test.xlsx"): os.remove("test.xlsx") if os.path.isfile("test.svg"): os.remove("test.svg") lay = Layer(testing_data.example_layer_v3_longer) t = ToExcel(domain=lay.layer.domain) t2 = ToSvg(domain=lay.layer.domain) t.to_xlsx(lay, "test.xlsx") t2.to_svg(lay, "test.svg") assert os.path.isfile("test.xlsx") assert os.path.isfile("test.svg") os.remove("test.xlsx") os.remove("test.svg")
def test_colormap_export(): """Test exporting a layer with a gradiant of scores""" if os.path.isfile("layer.xlsx"): os.remove("layer.xlsx") if os.path.isfile("layer.svg"): os.remove("layer.svg") lay = Layer() lay.from_file('resources/heatmap_example.json') xlsx_exporter = ToExcel(domain=lay.layer.domain) xlsx_exporter.to_xlsx(lay, filepath="layer.xlsx") svg_exporter = ToSvg(domain=lay.layer.domain) svg_exporter.to_svg(lay, filepath="layer.svg") assert os.path.isfile("layer.xlsx") assert os.path.isfile("layer.svg") os.remove('layer.xlsx') os.remove('layer.svg')