# Path: freesas/test/utilstests.py
# def get_datafile(name):
#     """Provides the full path of a test file,
#     downloading it from the internet if needed
# 
#     :param name: name of the file to get
#     :return: full path of the datafile
#     """
#     logger.info(f"Download file {name}")
#     fullpath = downloader.getfile(name)
#     return fullpath


import unittest
import pathlib
import re
import logging
import PyPDF2
from subprocess import run, Popen, PIPE, STDOUT
from os import linesep
from freesas.test.utilstests import get_datafile
    "BIFT fit legend": r"BIFT extraplolated: \$D_\{max\}=\$9\.[0-9][0-9] nm",
    "Label of Guinier plot X-axis": r"\$q\^2\$ \(nm\$\^\{-2\}\$\)",
    "Label of Guinier plot Y-axis": r"ln\[\$I\(q\)\$]",
    "Guinier - qRgmin": r"\$\(qR_\{g\}\)_\{min\}\$=0\.[0-9]",
    "Guinier - qRgmax": r"\$\(qR_\{g\}\)_\{max\}\$=1\.[0123]",
    "Guinier region label": r"Guinier region",
    "Guinier plot caption": r"Guinier plot: \$R_\{g\}=\$[23]\.[0-9][0-9] nm \$I_\{0\}=\$6[0-9]\.[0-9][0-9]",
    "Guinier fit equation": r"ln\[\$I\(q\)\$\] = 4\.12 -3\.01 \* \$q\^2\$",
    "Guinier fit data label": r"Experimental curve",
    "Label of Kratky plot X-Axis": r"\$qR_\{g\}\$",
    "Label of Kratky plot Y-Axis": r"\$\(qR_\{g\}\)\^2 I/I_\{0\}\$",
    "Kratky plot caption": r"Dimensionless Kratky plot",
    "Label of distribution plot X-axis": r"\$r\$ \(nm\)",
    "Label of distribution plot Y-axis": r"\$p\(r\)\$",
    "Distribution plot caption": r"Pair distribution function",
    # "BIFT chi": r"BIFT: χ\$_\{r\}\^\{2\}=\$1\.[0-9][0-9]",
    "BIFT Dmax": r"\$D_\{max\}=\$[1]?[09].[0-9][0-9] nm",
    "BIFT Rg": r"\$R_\{g\}=\$[23]\.[0-9][0-9] nm",
    "BIFT I0": r"\$I_\{0\}=\$6[0-9]\.[0-9][0-9]",
}


class TestFreeSAS(unittest.TestCase):

    cwd = pathlib.Path.cwd()
    TEST_IMAGE_NAME = pathlib.Path(cwd, "freesas.svg")
    TEST_PDF_NAME = pathlib.Path(cwd, "freesas.pdf")
    test_location = pathlib.Path(__file__)
    test_data_location = pathlib.Path(test_location.parent, "e2etest_data")
    bsa_filename = pathlib.Path(get_datafile("bsa_005_sub.dat"))

# Path: freesas/test/utilstests.py
# def get_datafile(name):
#     """Provides the full path of a test file,
#     downloading it from the internet if needed
# 
#     :param name: name of the file to get
#     :return: full path of the datafile
#     """
#     logger.info(f"Download file {name}")
#     fullpath = downloader.getfile(name)
#     return fullpath


# Path: e2etest/e2etest_freesas.py
import unittest
import pathlib
import re
import logging
import PyPDF2
from subprocess import run, Popen, PIPE, STDOUT
from os import linesep
from freesas.test.utilstests import get_datafile

    "BIFT fit legend": r"BIFT extraplolated: \$D_\{max\}=\$9\.[0-9][0-9] nm",
    "Label of Guinier plot X-axis": r"\$q\^2\$ \(nm\$\^\{-2\}\$\)",
    "Label of Guinier plot Y-axis": r"ln\[\$I\(q\)\$]",
    "Guinier - qRgmin": r"\$\(qR_\{g\}\)_\{min\}\$=0\.[0-9]",
    "Guinier - qRgmax": r"\$\(qR_\{g\}\)_\{max\}\$=1\.[0123]",
    "Guinier region label": r"Guinier region",
    "Guinier plot caption": r"Guinier plot: \$R_\{g\}=\$[23]\.[0-9][0-9] nm \$I_\{0\}=\$6[0-9]\.[0-9][0-9]",
    "Guinier fit equation": r"ln\[\$I\(q\)\$\] = 4\.12 -3\.01 \* \$q\^2\$",
    "Guinier fit data label": r"Experimental curve",
    "Label of Kratky plot X-Axis": r"\$qR_\{g\}\$",
    "Label of Kratky plot Y-Axis": r"\$\(qR_\{g\}\)\^2 I/I_\{0\}\$",
    "Kratky plot caption": r"Dimensionless Kratky plot",
    "Label of distribution plot X-axis": r"\$r\$ \(nm\)",
    "Label of distribution plot Y-axis": r"\$p\(r\)\$",
    "Distribution plot caption": r"Pair distribution function",
    # "BIFT chi": r"BIFT: χ\$_\{r\}\^\{2\}=\$1\.[0-9][0-9]",
    "BIFT Dmax": r"\$D_\{max\}=\$[1]?[09].[0-9][0-9] nm",
    "BIFT Rg": r"\$R_\{g\}=\$[23]\.[0-9][0-9] nm",
    "BIFT I0": r"\$I_\{0\}=\$6[0-9]\.[0-9][0-9]",
}


class TestFreeSAS(unittest.TestCase):

    cwd = pathlib.Path.cwd()
    TEST_IMAGE_NAME = pathlib.Path(cwd, "freesas.svg")
    TEST_PDF_NAME = pathlib.Path(cwd, "freesas.pdf")
    test_location = pathlib.Path(__file__)
    test_data_location = pathlib.Path(test_location.parent, "e2etest_data")
    bsa_filename = pathlib.Path(get_datafile("bsa_005_sub.dat"))

    sas_curve2_filename = pathlib.Path(get_datafile("SASDF52.dat"))