Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Add debug-nad folder into .powsybl to write debug files #74

Merged
merged 3 commits into from
May 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/test/java/com/powsybl/nad/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
import java.util.function.Predicate;

Expand Down Expand Up @@ -60,24 +62,25 @@ protected String generateSvgString(Network network, Predicate<VoltageLevel> volt
}

private void writeToHomeDir(String refFilename, String svgString) {
File debugFolder = new File(System.getProperty("user.home"), ".powsybl");
if (debugFolder.exists() || debugFolder.mkdir()) {
File file = new File(debugFolder, refFilename);
try (OutputStream fos = new FileOutputStream(file)) {
fos.write(svgString.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new UncheckedIOException(e);
Path debugFolder = Path.of(System.getProperty("user.home"), ".powsybl", "debug-nad");
try {
Files.createDirectories(debugFolder);
Path debugFile = debugFolder.resolve(refFilename.startsWith("/") ? refFilename.substring(1) : refFilename);
try (BufferedWriter bw = Files.newBufferedWriter(debugFile, StandardCharsets.UTF_8)) {
bw.write(normalizeLineSeparator(svgString));
}
} catch (IOException e) {
flo-dup marked this conversation as resolved.
Show resolved Hide resolved
throw new UncheckedIOException(e);
}
}

private void overrideTestReference(String filename, String svgString) {
File testReference = new File("src/test/resources", filename);
if (!testReference.exists()) {
Path testReference = Path.of("src", "test", "resources", filename);
if (!Files.exists(testReference)) {
return;
}
try (OutputStream os = new FileOutputStream(testReference)) {
os.write(svgString.getBytes(StandardCharsets.UTF_8));
try (BufferedWriter bw = Files.newBufferedWriter(testReference, StandardCharsets.UTF_8)) {
bw.write(normalizeLineSeparator(svgString));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down