• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

timcera / pyslice / 12340932278

15 Dec 2024 05:42PM CUT coverage: 45.447%. Remained the same
12340932278

Pull #4

github

web-flow
Merge d90cfa984 into 2ffee6f33
Pull Request #4: build(deps): bump actions/setup-python from 4 to 5

529 of 1164 relevant lines covered (45.45%)

2.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

15.0
/src/pyslice/pyslice_lib/PySPG/TeXParser.py
1
import os
5✔
2
import os.path
5✔
3
import sys
5✔
4

5
from .ParamParser import ParamParser
5✔
6

7

8
class TeXParser(ParamParser):
5✔
9
    replacing_rules = {
5✔
10
        r"\s": "_",
11
        r"\S": "^",
12
        "\f{Symbol}": " ",
13
        "\\f{}": " ",
14
        "\\N": "   ",
15
    }
16

17
    def __init__(self, comm, var_name):
5✔
18
        commands = [
×
19
            i.strip() for i in comm if (i.strip()[0] != "#" and i.strip() != "")
20
        ]
21
        # print commands
22

23
        pTmp = ParamParser(commands)
×
24
        try:
×
25
            lastvar_idx = pTmp.entities.index(var_name)
×
26
        except Exception:
×
27
            sys.stdout = sys.stderr
×
28
            print("last_var= ", var_name)
×
29
            print("var=", lastvar_idx)
×
30
            print("exiting... -presumible error: last var you provided does not")
×
31
            print(" exist among the variables-")
×
32
            sys.exit()
×
33

34
        self.parser_original = ParamParser(commands[:lastvar_idx])
×
35

36
        commands.index(filter(lambda x: x.strip()[0] in "+*/-.", commands).pop())
×
37

38
    def __tex(self, outname="plots.tex", plotnames=None):
5✔
39
        """
40
        for the actual values of the iterator self.parser_original, dumps a agr
41
        """
42
        if plotnames is None:
×
43
            plotnames = []
×
44
        cwd = os.path.abspath(os.path.curdir)
×
45
        #
46
        # Directory where the AGR will be located
47
        #
48
        thepath = self.parser_original.directory_tree(None)
×
49
        #
50
        #
51

52
        os.chdir(thepath)
×
53
        with open(outname, "w") as fOut:
×
54
            cout = self.__extracted_from___tex_17(fOut, plotnames)
×
55
        sys.stdout = cout
×
56
        os.system(f"latex {outname}")
×
57
        comandoexec = f"dvips -o {os.path.splitext(outname)[0]}.ps  {os.path.splitext(outname)[0]}.dvi"
×
58
        print(comandoexec)
×
59
        os.system(comandoexec)
×
60

61
        os.chdir(cwd)
×
62

63
    # TODO Rename this here and in `__tex`
64
    def __extracted_from___tex_17(self, fOut, plotnames):
5✔
65
        os.system("~/opt/bin/cts-print.sh")
×
66
        result = sys.stdout
×
67
        sys.stdout = fOut
×
68

69
        print("\\documentclass[12pt]{article}")
×
70
        print()
×
71
        print("\\usepackage{graphicx}")
×
72
        print()
×
73
        self.__extracted_from___tex_25("\\begin{document}")
×
74
        print("Gr\\'aficos generados con los siguientes par\\'ametros:")
×
75
        print("\\begin{itemize}")
×
76
        actual_values = self.parser_original.actual_values
×
77
        for i in actual_values:
×
78
            print("\\item    { \\tt")
×
79
            if actual_values[i] == "":
×
80
                posunder = i.find("_")
×
81
                if posunder > 0:
×
82
                    i.find("0")
×
83
                    print("\\begin{verbatim}")
×
84
                    print(i)
×
85
                    print("\\end{verbatim}")
×
86
                else:
87
                    print(i)
×
88
            else:
89
                print(f" $ {i} = {actual_values[i]} $")
×
90
            print(""" }   """)
×
91
        self.__extracted_from___tex_25("\\end{itemize}")
×
92
        for ac_floats, i in enumerate(plotnames, start=1):
×
93
            self.__extracted_from___tex_49(i, ac_floats)
×
94
        print("\\end{document}")
×
95
        return result
×
96

97
    # TODO Rename this here and in `__tex`
98
    def __extracted_from___tex_49(self, i, ac_floats):
5✔
99
        print("\\begin{figure}[!ht]")
×
100
        print("\\begin{center}")
×
101
        print("\\includegraphics[height=10cm,angle=-90]{%s.eps}" % (i))
×
102
        print("\\end{center}")
×
103
        print("\\end{figure}")
×
104
        if ac_floats % 12 == 0:
×
105
            print("\\clearpage")
×
106

107
    # TODO Rename this here and in `__tex`
108
    def __extracted_from___tex_25(self, arg0):
5✔
109
        print(arg0)
×
110
        print()
×
111
        print()
×
112

113
    def doit(self, outname="plots.tex", plotnames=None):
5✔
114
        """
115
        Suquencially dumps all the plotnames (a list of .agr files)
116
        """
117
        if plotnames is None:
×
118
            plotnames = []
×
119
        for _ in self.parser_original:
×
120
            self.__tex(outname, plotnames)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc