From 98473577d7127d2ebb8f71c1a6016ca71b0fad2e Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 25 May 2009 09:27:13 -0400 Subject: A sample HTML coverage report. --- doc/sample_html/README.txt | 5 + doc/sample_html/cogapp_cogapp.html | 1468 ++++++++++++ doc/sample_html/cogapp_makefiles.html | 178 ++ doc/sample_html/cogapp_test_cogapp.html | 3970 +++++++++++++++++++++++++++++++ doc/sample_html/cogapp_whiteutils.html | 176 ++ doc/sample_html/index.html | 78 + doc/sample_html/jquery-1.3.2.min.js | 19 + doc/sample_html/style.css | 159 ++ 8 files changed, 6053 insertions(+) create mode 100644 doc/sample_html/README.txt create mode 100644 doc/sample_html/cogapp_cogapp.html create mode 100644 doc/sample_html/cogapp_makefiles.html create mode 100644 doc/sample_html/cogapp_test_cogapp.html create mode 100644 doc/sample_html/cogapp_whiteutils.html create mode 100644 doc/sample_html/index.html create mode 100644 doc/sample_html/jquery-1.3.2.min.js create mode 100644 doc/sample_html/style.css (limited to 'doc/sample_html') diff --git a/doc/sample_html/README.txt b/doc/sample_html/README.txt new file mode 100644 index 00000000..c1e49828 --- /dev/null +++ b/doc/sample_html/README.txt @@ -0,0 +1,5 @@ +This directory was made with:: + + cd C:\ned\cog\trunk + coverage -e -x cogapp\test_cogapp.py CogTestsInMemory + coverage -b -i -d htmlcov diff --git a/doc/sample_html/cogapp_cogapp.html b/doc/sample_html/cogapp_cogapp.html new file mode 100644 index 00000000..6930fb5e --- /dev/null +++ b/doc/sample_html/cogapp_cogapp.html @@ -0,0 +1,1468 @@ + + + +Coverage for cogapp\cogapp + + + + + + + +
+ + + + + +
+

1

+

2

+

3

+

4

+

5

+

6

+

7

+

8

+

9

+

10

+

11

+

12

+

13

+

14

+

15

+

16

+

17

+

18

+

19

+

20

+

21

+

22

+

23

+

24

+

25

+

26

+

27

+

28

+

29

+

30

+

31

+

32

+

33

+

34

+

35

+

36

+

37

+

38

+

39

+

40

+

41

+

42

+

43

+

44

+

45

+

46

+

47

+

48

+

49

+

50

+

51

+

52

+

53

+

54

+

55

+

56

+

57

+

58

+

59

+

60

+

61

+

62

+

63

+

64

+

65

+

66

+

67

+

68

+

69

+

70

+

71

+

72

+

73

+

74

+

75

+

76

+

77

+

78

+

79

+

80

+

81

+

82

+

83

+

84

+

85

+

86

+

87

+

88

+

89

+

90

+

91

+

92

+

93

+

94

+

95

+

96

+

97

+

98

+

99

+

100

+

101

+

102

+

103

+

104

+

105

+

106

+

107

+

108

+

109

+

110

+

111

+

112

+

113

+

114

+

115

+

116

+

117

+

118

+

119

+

120

+

121

+

122

+

123

+

124

+

125

+

126

+

127

+

128

+

129

+

130

+

131

+

132

+

133

+

134

+

135

+

136

+

137

+

138

+

139

+

140

+

141

+

142

+

143

+

144

+

145

+

146

+

147

+

148

+

149

+

150

+

151

+

152

+

153

+

154

+

155

+

156

+

157

+

158

+

159

+

160

+

161

+

162

+

163

+

164

+

165

+

166

+

167

+

168

+

169

+

170

+

171

+

172

+

173

+

174

+

175

+

176

+

177

+

178

+

179

+

180

+

181

+

182

+

183

+

184

+

185

+

186

+

187

+

188

+

189

+

190

+

191

+

192

+

193

+

194

+

195

+

196

+

197

+

198

+

199

+

200

+

201

+

202

+

203

+

204

+

205

+

206

+

207

+

208

+

209

+

210

+

211

+

212

+

213

+

214

+

215

+

216

+

217

+

218

+

219

+

220

+

221

+

222

+

223

+

224

+

225

+

226

+

227

+

228

+

229

+

230

+

231

+

232

+

233

+

234

+

235

+

236

+

237

+

238

+

239

+

240

+

241

+

242

+

243

+

244

+

245

+

246

+

247

+

248

+

249

+

250

+

251

+

252

+

253

+

254

+

255

+

256

+

257

+

258

+

259

+

260

+

261

+

262

+

263

+

264

+

265

+

266

+

267

+

268

+

269

+

270

+

271

+

272

+

273

+

274

+

275

+

276

+

277

+

278

+

279

+

280

+

281

+

282

+

283

+

284

+

285

+

286

+

287

+

288

+

289

+

290

+

291

+

292

+

293

+

294

+

295

+

296

+

297

+

298

+

299

+

300

+

301

+

302

+

303

+

304

+

305

+

306

+

307

+

308

+

309

+

310

+

311

+

312

+

313

+

314

+

315

+

316

+

317

+

318

+

319

+

320

+

321

+

322

+

323

+

324

+

325

+

326

+

327

+

328

+

329

+

330

+

331

+

332

+

333

+

334

+

335

+

336

+

337

+

338

+

339

+

340

+

341

+

342

+

343

+

344

+

345

+

346

+

347

+

348

+

349

+

350

+

351

+

352

+

353

+

354

+

355

+

356

+

357

+

358

+

359

+

360

+

361

+

362

+

363

+

364

+

365

+

366

+

367

+

368

+

369

+

370

+

371

+

372

+

373

+

374

+

375

+

376

+

377

+

378

+

379

+

380

+

381

+

382

+

383

+

384

+

385

+

386

+

387

+

388

+

389

+

390

+

391

+

392

+

393

+

394

+

395

+

396

+

397

+

398

+

399

+

400

+

401

+

402

+

403

+

404

+

405

+

406

+

407

+

408

+

409

+

410

+

411

+

412

+

413

+

414

+

415

+

416

+

417

+

418

+

419

+

420

+

421

+

422

+

423

+

424

+

425

+

426

+

427

+

428

+

429

+

430

+

431

+

432

+

433

+

434

+

435

+

436

+

437

+

438

+

439

+

440

+

441

+

442

+

443

+

444

+

445

+

446

+

447

+

448

+

449

+

450

+

451

+

452

+

453

+

454

+

455

+

456

+

457

+

458

+

459

+

460

+

461

+

462

+

463

+

464

+

465

+

466

+

467

+

468

+

469

+

470

+

471

+

472

+

473

+

474

+

475

+

476

+

477

+

478

+

479

+

480

+

481

+

482

+

483

+

484

+

485

+

486

+

487

+

488

+

489

+

490

+

491

+

492

+

493

+

494

+

495

+

496

+

497

+

498

+

499

+

500

+

501

+

502

+

503

+

504

+

505

+

506

+

507

+

508

+

509

+

510

+

511

+

512

+

513

+

514

+

515

+

516

+

517

+

518

+

519

+

520

+

521

+

522

+

523

+

524

+

525

+

526

+

527

+

528

+

529

+

530

+

531

+

532

+

533

+

534

+

535

+

536

+

537

+

538

+

539

+

540

+

541

+

542

+

543

+

544

+

545

+

546

+

547

+

548

+

549

+

550

+

551

+

552

+

553

+

554

+

555

+

556

+

557

+

558

+

559

+

560

+

561

+

562

+

563

+

564

+

565

+

566

+

567

+

568

+

569

+

570

+

571

+

572

+

573

+

574

+

575

+

576

+

577

+

578

+

579

+

580

+

581

+

582

+

583

+

584

+

585

+

586

+

587

+

588

+

589

+

590

+

591

+

592

+

593

+

594

+

595

+

596

+

597

+

598

+

599

+

600

+

601

+

602

+

603

+

604

+

605

+

606

+

607

+

608

+

609

+

610

+

611

+

612

+

613

+

614

+

615

+

616

+

617

+

618

+

619

+

620

+

621

+

622

+

623

+

624

+

625

+

626

+

627

+

628

+

629

+

630

+

631

+

632

+

633

+

634

+

635

+

636

+

637

+

638

+

639

+

640

+

641

+

642

+

643

+

644

+

645

+

646

+

647

+

648

+

649

+

650

+

651

+

652

+

653

+

654

+

655

+

656

+

657

+

658

+

659

+

660

+

661

+

662

+

663

+

664

+

665

+

666

+

667

+

668

+

669

+

670

+

671

+

672

+

673

+

674

+

675

+

676

+

677

+

678

+

679

+

680

+

681

+

682

+

683

+

684

+

685

+

686

+

687

+

688

+

689

+

690

+

691

+

692

+

693

+

694

+

695

+

696

+

697

+

698

+

699

+

700

+

701

+

702

+

703

+

704

+

705

+

706

+

707

+

708

+

709

+ +
+

""" Cog code generation tool.

+

    http://nedbatchelder.com/code/cog

+

 

+

    Copyright 2004-2009, Ned Batchelder.

+

"""

+

 

+

import copy, getopt, imp, os, re, shlex, string, sys, traceback

+

from cStringIO import StringIO

+

 

+

# The recommended way to compute md5's changed in Python 2.5

+

try:

+

    import hashlib

+

    hash_factory = hashlib.md5

+

except ImportError:

+

    import md5

+

    hash_factory = md5.new

+

 

+

__all__ = ['Cog', 'CogUsageError']

+

 

+

__version__ = '2.2'       # History at the end of the file.

+

 

+

usage = """\

+

cog - generate code with inlined Python code.

+

 

+

cog [OPTIONS] [INFILE | @FILELIST] ...

+

 

+

INFILE is the name of an input file.

+

FILELIST is the name of a text file containing file names or

+

    other @FILELISTs.

+

 

+

OPTIONS:

+

    -c          Checksum the output to protect it against accidental change.

+

    -d          Delete the generator code from the output file.

+

    -D name=val Define a global string available to your generator code.

+

    -e          Warn if a file has no cog code in it.

+

    -I PATH     Add PATH to the list of directories for data files and modules.

+

    -o OUTNAME  Write the output to OUTNAME.

+

    -r          Replace the input file with the output.

+

    -s STRING   Suffix all generated output lines with STRING.

+

    -U          Write the output with Unix newlines (only LF line-endings).

+

    -w CMD      Use CMD if the output file needs to be made writable.

+

                    A %s in the CMD will be filled with the filename.

+

    -x          Excise all the generated output without running the generators.

+

    -z          The [[[end]]] marker can be omitted, and is assumed at eof.

+

    -v          Print the version of cog and exit.

+

    -h          Print this help.

+

"""

+

 

+

# Other package modules

+

from whiteutils import *

+

 

+

class CogError(Exception):

+

    """ Any exception raised by Cog.

+

    """

+

    def __init__(self, msg, file='', line=0):

+

        if file:

+

            Exception.__init__(self, "%s(%d): %s" % (file, line, msg))

+

        else:

+

            Exception.__init__(self, msg)

+

 

+

class CogUsageError(CogError):

+

    """ An error in usage of command-line arguments in cog.

+

    """

+

    pass    #pragma: no cover

+

 

+

class CogInternalError(CogError):

+

    """ An error in the coding of Cog. Should never happen.

+

    """

+

    pass    #pragma: no cover

+

 

+

class CogGeneratedError(CogError):

+

    """ An error raised by a user's cog generator.

+

    """

+

    pass    #pragma: no cover

+

 

+

class Redirectable:

+

    """ An object with its own stdout and stderr files.

+

    """

+

    def __init__(self):

+

        self.stdout = sys.stdout

+

        self.stderr = sys.stderr

+

 

+

    def setOutput(self, stdout=None, stderr=None):

+

        """ Assign new files for standard out and/or standard error.

+

        """

+

        if stdout:

+

            self.stdout = stdout

+

        if stderr:

+

            self.stderr = stderr

+

 

+

class CogGenerator(Redirectable):

+

    """ A generator pulled from a source file.

+

    """

+

    def __init__(self):

+

        Redirectable.__init__(self)

+

        self.markers = []

+

        self.lines = []

+

 

+

    def parseMarker(self, l):

+

        self.markers.append(l)

+

 

+

    def parseLine(self, l):

+

        self.lines.append(l.strip('\n'))

+

 

+

    def getCode(self):

+

        """ Extract the executable Python code from the generator.

+

        """

+

        # If the markers and lines all have the same prefix

+

        # (end-of-line comment chars, for example),

+

        # then remove it from all the lines.

+

        prefIn = commonPrefix(self.markers + self.lines)

+

        if prefIn:

+

            self.markers = [ l.replace(prefIn, '', 1) for l in self.markers ]

+

            self.lines = [ l.replace(prefIn, '', 1) for l in self.lines ]

+

 

+

        return reindentBlock(self.lines, '')

+

 

+

    def evaluate(self, cog, globals, fname='cog generator'):

+

        # figure out the right whitespace prefix for the output

+

        prefOut = whitePrefix(self.markers)

+

 

+

        intext = self.getCode()

+

        if not intext:

+

            return ''

+

 

+

        # In Python 2.2, the last line has to end in a newline.

+

        intext = "import cog\n" + intext + "\n"

+

        code = compile(intext, str(fname), 'exec')

+

 

+

        # Make sure the "cog" module has our state.

+

        cog.cogmodule.msg = self.msg

+

        cog.cogmodule.out = self.out

+

        cog.cogmodule.outl = self.outl

+

        cog.cogmodule.error = self.error

+

 

+

        self.outstring = ''

+

        eval(code, globals)

+

 

+

        # We need to make sure that the last line in the output

+

        # ends with a newline, or it will be joined to the

+

        # end-output line, ruining cog's idempotency.

+

        if self.outstring and self.outstring[-1] != '\n':

+

            self.outstring += '\n'

+

 

+

        return reindentBlock(self.outstring, prefOut)

+

 

+

    def msg(self, s):

+

        print >>self.stdout, "Message: "+s

+

 

+

    def out(self, sOut='', dedent=False, trimblanklines=False):

+

        """ The cog.out function.

+

        """

+

        if trimblanklines and ('\n' in sOut):

+

            lines = sOut.split('\n')

+

            if lines[0].strip() == '':

+

                del lines[0]

+

            if lines and lines[-1].strip() == '':

+

                del lines[-1]

+

            sOut = '\n'.join(lines)+'\n'

+

        if dedent:

+

            sOut = reindentBlock(sOut)

+

        self.outstring += sOut

+

 

+

    def outl(self, sOut='', **kw):

+

        """ The cog.outl function.

+

        """

+

        self.out(sOut, **kw)

+

        self.out('\n')

+

 

+

    def error(self, msg='Error raised by cog generator.'):

+

        """ The cog.error function.

+

            Instead of raising standard python errors, cog generators can use

+

            this function.  It will display the error without a scary Python

+

            traceback.

+

        """

+

        raise CogGeneratedError(msg)

+

 

+

 

+

class NumberedFileReader:

+

    """ A decorator for files that counts the readline()'s called.

+

    """

+

    def __init__(self, f):

+

        self.f = f

+

        self.n = 0

+

 

+

    def readline(self):

+

        l = self.f.readline()

+

        if l:

+

            self.n += 1

+

        return l

+

 

+

    def linenumber(self):

+

        return self.n

+

 

+

 

+

class CogOptions:

+

    """ Options for a run of cog.

+

    """

+

    def __init__(self):

+

        # Defaults for argument values.

+

        self.args = []

+

        self.includePath = []

+

        self.defines = {}

+

        self.bShowVersion = False

+

        self.sMakeWritableCmd = None

+

        self.bReplace = False

+

        self.bNoGenerate = False

+

        self.sOutputName = None

+

        self.bWarnEmpty = False

+

        self.bHashOutput = False

+

        self.bDeleteCode = False

+

        self.bEofCanBeEnd = False

+

        self.sSuffix = None

+

        self.bNewlines = False

+

 

+

    def __cmp__(self, other):

+

        """ Comparison operator for tests to use.

+

        """

+

        return self.__dict__.__cmp__(other.__dict__)

+

 

+

    def clone(self):

+

        """ Make a clone of these options, for further refinement.

+

        """

+

        return copy.deepcopy(self)

+

 

+

    def addToIncludePath(self, dirs):

+

        """ Add directories to the include path.

+

        """

+

        dirs = dirs.split(os.pathsep)

+

        self.includePath.extend(dirs)

+

 

+

    def parseArgs(self, argv):

+

        # Parse the command line arguments.

+

        try:

+

            opts, self.args = getopt.getopt(argv, 'cdD:eI:o:rs:Uvw:xz')

+

        except getopt.error, msg:

+

            raise CogUsageError(msg)

+

 

+

        # Handle the command line arguments.

+

        for o, a in opts:

+

            if o == '-c':

+

                self.bHashOutput = True

+

            elif o == '-d':

+

                self.bDeleteCode = True

+

            elif o == '-D':

+

                if a.count('=') < 1:

+

                    raise CogUsageError("-D takes a name=value argument")

+

                name, value = a.split('=', 1)

+

                self.defines[name] = value

+

            elif o == '-e':

+

                self.bWarnEmpty = True

+

            elif o == '-I':

+

                self.addToIncludePath(a)

+

            elif o == '-o':

+

                self.sOutputName = a

+

            elif o == '-r':

+

                self.bReplace = True

+

            elif o == '-s':

+

                self.sSuffix = a

+

            elif o == '-U':

+

                self.bNewlines = True

+

            elif o == '-v':

+

                self.bShowVersion = True

+

            elif o == '-w':

+

                self.sMakeWritableCmd = a

+

            elif o == '-x':

+

                self.bNoGenerate = True

+

            elif o == '-z':

+

                self.bEofCanBeEnd = True

+

            else:

+

                # Since getopt.getopt is given a list of possible flags,

+

                # this is an internal error.

+

                raise CogInternalError("Don't understand argument %s" % o)

+

 

+

    def validate(self):

+

        """ Does nothing if everything is OK, raises CogError's if it's not.

+

        """

+

        if self.bReplace and self.bDeleteCode:

+

            raise CogUsageError("Can't use -d with -r (or you would delete all your source!)")

+

 

+

        if self.bReplace and self.sOutputName:

+

            raise CogUsageError("Can't use -o with -r (they are opposites)")

+

 

+

 

+

class Cog(Redirectable):

+

    """ The Cog engine.

+

    """

+

    def __init__(self):

+

        Redirectable.__init__(self)

+

        self.sBeginSpec = '[[[cog'

+

        self.sEndSpec = ']]]'

+

        self.sEndOutput = '[[[end]]]'

+

        self.reEndOutput = re.compile(r'\[\[\[end]]](?P<hashsect> *\(checksum: (?P<hash>[a-f0-9]+)\))')

+

        self.sEndFormat = '[[[end]]] (checksum: %s)'

+

 

+

        self.options = CogOptions()

+

        self.sOutputMode = 'w'

+

 

+

        self.installCogModule()

+

 

+

    def showWarning(self, msg):

+

        print >>self.stdout, "Warning:", msg

+

 

+

    def isBeginSpecLine(self, s):

+

        return string.find(s, self.sBeginSpec) >= 0

+

 

+

    def isEndSpecLine(self, s):

+

        return string.find(s, self.sEndSpec) >= 0 and \

+

            not self.isEndOutputLine(s)

+

 

+

    def isEndOutputLine(self, s):

+

        return string.find(s, self.sEndOutput) >= 0

+

 

+

    def installCogModule(self):

+

        """ Magic mumbo-jumbo so that imported Python modules

+

            can say "import cog" and get our state.

+

        """

+

        self.cogmodule = imp.new_module('cog')

+

        self.cogmodule.path = []

+

        sys.modules['cog'] = self.cogmodule

+

 

+

    def processFile(self, fIn, fOut, fname=None, globals=None):

+

        """ Process an input file object to an output file object.

+

            fIn and fOut can be file objects, or file names.

+

        """

+

 

+

        sFileIn = fname or ''

+

        sFileOut = fname or ''

+

        fInToClose = fOutToClose = None

+

        # Convert filenames to files.

+

        if isinstance(fIn, basestring):

+

            # Open the input file.

+

            sFileIn = fIn

+

            fIn = fInToClose = open(fIn, 'r')

+

        if isinstance(fOut, basestring):

+

            # Open the output file.

+

            sFileOut = fOut

+

            fOut = fOutToClose = open(fOut, self.sOutputMode)

+

 

+

        try:

+

            fIn = NumberedFileReader(fIn)

+

 

+

            bSawCog = False

+

 

+

            self.cogmodule.inFile = sFileIn

+

            self.cogmodule.outFile = sFileOut

+

 

+

            # The globals dict we'll use for this file.

+

            if globals is None:

+

                globals = {}

+

 

+

            # If there are any global defines, put them in the globals.

+

            globals.update(self.options.defines)

+

 

+

            # loop over generator chunks

+

            l = fIn.readline()

+

            while l:

+

                # Find the next spec begin

+

                while l and not self.isBeginSpecLine(l):

+

                    if self.isEndSpecLine(l):

+

                        raise CogError("Unexpected '%s'" % self.sEndSpec,

+

                            file=sFileIn, line=fIn.linenumber())

+

                    if self.isEndOutputLine(l):

+

                        raise CogError("Unexpected '%s'" % self.sEndOutput,

+

                            file=sFileIn, line=fIn.linenumber())

+

                    fOut.write(l)

+

                    l = fIn.readline()

+

                if not l:

+

                    break

+

                if not self.options.bDeleteCode:

+

                    fOut.write(l)

+

 

+

                # l is the begin spec

+

                gen = CogGenerator()

+

                gen.setOutput(stdout=self.stdout)

+

                gen.parseMarker(l)

+

                firstLineNum = fIn.linenumber()

+

                self.cogmodule.firstLineNum = firstLineNum

+

 

+

                # If the spec begin is also a spec end, then process the single

+

                # line of code inside.

+

                if self.isEndSpecLine(l):

+

                    beg = string.find(l, self.sBeginSpec)

+

                    end = string.find(l, self.sEndSpec)

+

                    if beg > end:

+

                        raise CogError("Cog code markers inverted",

+

                            file=sFileIn, line=firstLineNum)

+

                    else:

+

                        sCode = l[beg+len(self.sBeginSpec):end].strip()

+

                        gen.parseLine(sCode)

+

                else:

+

                    # Deal with an ordinary code block.

+

                    l = fIn.readline()

+

 

+

                    # Get all the lines in the spec

+

                    while l and not self.isEndSpecLine(l):

+

                        if self.isBeginSpecLine(l):

+

                            raise CogError("Unexpected '%s'" % self.sBeginSpec,

+

                                file=sFileIn, line=fIn.linenumber())

+

                        if self.isEndOutputLine(l):

+

                            raise CogError("Unexpected '%s'" % self.sEndOutput,

+

                                file=sFileIn, line=fIn.linenumber())

+

                        if not self.options.bDeleteCode:

+

                            fOut.write(l)

+

                        gen.parseLine(l)

+

                        l = fIn.readline()

+

                    if not l:

+

                        raise CogError(

+

                            "Cog block begun but never ended.",

+

                            file=sFileIn, line=firstLineNum)

+

 

+

                    if not self.options.bDeleteCode:

+

                        fOut.write(l)

+

                    gen.parseMarker(l)

+

 

+

                l = fIn.readline()

+

 

+

                # Eat all the lines in the output section.  While reading past

+

                # them, compute the md5 hash of the old output.

+

                hasher = hash_factory()

+

                while l and not self.isEndOutputLine(l):

+

                    if self.isBeginSpecLine(l):

+

                        raise CogError("Unexpected '%s'" % self.sBeginSpec,

+

                            file=sFileIn, line=fIn.linenumber())

+

                    if self.isEndSpecLine(l):

+

                        raise CogError("Unexpected '%s'" % self.sEndSpec,

+

                            file=sFileIn, line=fIn.linenumber())

+

                    hasher.update(l)

+

                    l = fIn.readline()

+

                curHash = hasher.hexdigest()

+

 

+

                if not l and not self.options.bEofCanBeEnd:

+

                    # We reached end of file before we found the end output line.

+

                    raise CogError("Missing '%s' before end of file." % self.sEndOutput,

+

                        file=sFileIn, line=fIn.linenumber())

+

 

+

                # Write the output of the spec to be the new output if we're

+

                # supposed to generate code.

+

                hasher = hash_factory()

+

                if not self.options.bNoGenerate:

+

                    sFile = "%s+%d" % (sFileIn, firstLineNum)

+

                    sGen = gen.evaluate(cog=self, globals=globals, fname=sFile)

+

                    sGen = self.suffixLines(sGen)

+

                    hasher.update(sGen)

+

                    fOut.write(sGen)

+

                newHash = hasher.hexdigest()

+

 

+

                bSawCog = True

+

 

+

                # Write the ending output line

+

                hashMatch = self.reEndOutput.search(l)

+

                if self.options.bHashOutput:

+

                    if hashMatch:

+

                        oldHash = hashMatch.groupdict()['hash']

+

                        if oldHash != curHash:

+

                            raise CogError("Output has been edited! Delete old checksum to unprotect.",

+

                                file=sFileIn, line=fIn.linenumber())

+

                        # Create a new end line with the correct hash.

+

                        endpieces = l.split(hashMatch.group(0), 1)

+

                    else:

+

                        # There was no old hash, but we want a new hash.

+

                        endpieces = l.split(self.sEndOutput, 1)

+

                    l = (self.sEndFormat % newHash).join(endpieces)

+

                else:

+

                    # We don't want hashes output, so if there was one, get rid of

+

                    # it.

+

                    if hashMatch:

+

                        l = l.replace(hashMatch.groupdict()['hashsect'], '', 1)

+

 

+

                if not self.options.bDeleteCode:

+

                    fOut.write(l)

+

                l = fIn.readline()

+

 

+

            if not bSawCog and self.options.bWarnEmpty:

+

                self.showWarning("no cog code found in %s" % sFileIn)

+

        finally:

+

            if fInToClose:

+

                fInToClose.close()

+

            if fOutToClose:

+

                fOutToClose.close()

+

 

+

 

+

    # A regex for non-empty lines, used by suffixLines.

+

    reNonEmptyLines = re.compile("^\s*\S+.*$", re.MULTILINE)

+

 

+

    def suffixLines(self, text):

+

        """ Add suffixes to the lines in text, if our options desire it.

+

            text is many lines, as a single string.

+

        """

+

        if self.options.sSuffix:

+

            # Find all non-blank lines, and add the suffix to the end.

+

            repl = r"\g<0>" + self.options.sSuffix.replace('\\', '\\\\')

+

            text = self.reNonEmptyLines.sub(repl, text)

+

        return text

+

 

+

    def processString(self, sInput, fname=None):

+

        """ Process sInput as the text to cog.

+

            Return the cogged output as a string.

+

        """

+

        fOld = StringIO(sInput)

+

        fNew = StringIO()

+

        self.processFile(fOld, fNew, fname=fname)

+

        return fNew.getvalue()

+

 

+

    def replaceFile(self, sOldPath, sNewText):

+

        """ Replace file sOldPath with the contents sNewText

+

        """

+

        if not os.access(sOldPath, os.W_OK):

+

            # Need to ensure we can write.

+

            if self.options.sMakeWritableCmd:

+

                # Use an external command to make the file writable.

+

                cmd = self.options.sMakeWritableCmd.replace('%s', sOldPath)

+

                self.stdout.write(os.popen(cmd).read())

+

                if not os.access(sOldPath, os.W_OK):

+

                    raise CogError("Couldn't make %s writable" % sOldPath)

+

            else:

+

                # Can't write!

+

                raise CogError("Can't overwrite %s" % sOldPath)

+

        f = open(sOldPath, self.sOutputMode)

+

        f.write(sNewText)

+

        f.close()

+

 

+

    def saveIncludePath(self):

+

        self.savedInclude = self.options.includePath[:]

+

        self.savedSysPath = sys.path[:]

+

 

+

    def restoreIncludePath(self):

+

        self.options.includePath = self.savedInclude

+

        self.cogmodule.path = self.options.includePath

+

        sys.path = self.savedSysPath

+

 

+

    def addToIncludePath(self, includePath):

+

        self.cogmodule.path.extend(includePath)

+

        sys.path.extend(includePath)

+

 

+

    def processOneFile(self, sFile):

+

        """ Process one filename through cog.

+

        """

+

 

+

        self.saveIncludePath()

+

 

+

        try:

+

            self.addToIncludePath(self.options.includePath)

+

            # Since we know where the input file came from,

+

            # push its directory onto the include path.

+

            self.addToIncludePath([os.path.dirname(sFile)])

+

 

+

            # Set the file output mode based on whether we want \n or native

+

            # line endings.

+

            self.sOutputMode = 'w'

+

            if self.options.bNewlines:

+

                self.sOutputMode = 'wb'

+

 

+

            # How we process the file depends on where the output is going.

+

            if self.options.sOutputName:

+

                self.processFile(sFile, self.options.sOutputName, sFile)

+

            elif self.options.bReplace:

+

                # We want to replace the cog file with the output,

+

                # but only if they differ.

+

                print >>self.stdout, "Cogging %s" % sFile,

+

                bNeedNewline = True

+

 

+

                try:

+

                    fOldFile = open(sFile)

+

                    sOldText = fOldFile.read()

+

                    fOldFile.close()

+

                    sNewText = self.processString(sOldText, fname=sFile)

+

                    if sOldText != sNewText:

+

                        print >>self.stdout, "  (changed)"

+

                        bNeedNewline = False

+

                        self.replaceFile(sFile, sNewText)

+

                finally:

+

                    # The try-finally block is so we can print a partial line

+

                    # with the name of the file, and print (changed) on the

+

                    # same line, but also make sure to break the line before

+

                    # any traceback.

+

                    if bNeedNewline:

+

                        print >>self.stdout

+

            else:

+

                self.processFile(sFile, self.stdout, sFile)

+

        finally:

+

            self.restoreIncludePath()

+

 

+

    def processFileList(self, sFileList):

+

        """ Process the files in a file list.

+

        """

+

        flist = open(sFileList)

+

        lines = flist.readlines()

+

        flist.close()

+

        for l in lines:

+

            # Use shlex to parse the line like a shell.

+

            lex = shlex.shlex(l, posix=True)

+

            lex.whitespace_split = True

+

            lex.commenters = '#'

+

            # No escapes, so that backslash can be part of the path

+

            lex.escape = ''

+

            args = list(lex)

+

            if args:

+

                self.processArguments(args)

+

 

+

    def processArguments(self, args):

+

        """ Process one command-line.

+

        """

+

        saved_options = self.options

+

        self.options = self.options.clone()

+

 

+

        self.options.parseArgs(args[1:])

+

        self.options.validate()

+

 

+

        if args[0][0] == '@':

+

            if self.options.sOutputName:

+

                raise CogUsageError("Can't use -o with @file")

+

            self.processFileList(args[0][1:])

+

        else:

+

            self.processOneFile(args[0])

+

 

+

        self.options = saved_options

+

 

+

    def callableMain(self, argv):

+

        """ All of command-line cog, but in a callable form.

+

            This is used by main.

+

            argv is the equivalent of sys.argv.

+

        """

+

        argv0 = argv.pop(0)

+

 

+

        # Provide help if asked for anywhere in the command line.

+

        if '-?' in argv or '-h' in argv:

+

            print >>self.stderr, usage,

+

            return

+

 

+

        self.options.parseArgs(argv)

+

        self.options.validate()

+

 

+

        if self.options.bShowVersion:

+

            print >>self.stdout, "Cog version %s" % __version__

+

            return

+

 

+

        if self.options.args:

+

            for a in self.options.args:

+

                self.processArguments([a])

+

        else:

+

            raise CogUsageError("No files to process")

+

 

+

    def main(self, argv):

+

        """ Handle the command-line execution for cog.

+

        """

+

 

+

        try:

+

            self.callableMain(argv)

+

            return 0

+

        except CogUsageError, err:

+

            print >>self.stderr, err

+

            print >>self.stderr, "(for help use -?)"

+

            return 2

+

        except CogGeneratedError, err:

+

            print >>self.stderr, "Error: %s" % err

+

            return 3

+

        except CogError, err:

+

            print >>self.stderr, err

+

            return 1

+

        except:

+

            traceback.print_exc(None, self.stderr)

+

            return 1

+

 

+

# History:

+

# 20040210: First public version.

+

# 20040220: Text preceding the start and end marker are removed from Python lines.

+

#           -v option on the command line shows the version.

+

# 20040311: Make sure the last line of output is properly ended with a newline.

+

# 20040605: Fixed some blank line handling in cog.

+

#           Fixed problems with assigning to xml elements in handyxml.

+

# 20040621: Changed all line-ends to LF from CRLF.

+

# 20041002: Refactor some option handling to simplify unittesting the options.

+

# 20041118: cog.out and cog.outl have optional string arguments.

+

# 20041119: File names weren't being properly passed around for warnings, etc.

+

# 20041122: Added cog.firstLineNum: a property with the line number of the [[[cog line.

+

#           Added cog.inFile and cog.outFile: the names of the input and output file.

+

# 20041218: Single-line cog generators, with start marker and end marker on

+

#           the same line.

+

# 20041230: Keep a single globals dict for all the code fragments in a single

+

#           file so they can share state.

+

# 20050206: Added the -x switch to remove all generated output.

+

# 20050218: Now code can be on the marker lines as well.

+

# 20050219: Added -c switch to checksum the output so that edits can be

+

#           detected before they are obliterated.

+

# 20050521: Added cog.error, contributed by Alexander Belchenko.

+

# 20050720: Added code deletion and settable globals contributed by Blake Winton.

+

# 20050724: Many tweaks to improve code coverage.

+

# 20050726: Error messages are now printed with no traceback.

+

#           Code can no longer appear on the marker lines,

+

#               except for single-line style.

+

#           -z allows omission of the [[[end]]] marker, and it will be assumed

+

#               at the end of the file.

+

# 20050729: Refactor option parsing into a separate class, in preparation for

+

#               future features.

+

# 20050805: The cogmodule.path wasn't being properly maintained.

+

# 20050808: Added the -D option to define a global value.

+

# 20050810: The %s in the -w command is dealt with more robustly.

+

#           Added the -s option to suffix output lines with a marker.

+

# 20050817: Now @files can have arguments on each line to change the cog's

+

#               behavior for that line.

+

# 20051006: Version 2.0

+

# 20080521: -U options lets you create Unix newlines on Windows.  Thanks,

+

#               Alexander Belchenko.

+

# 20080522: It's now ok to have -d with output to stdout, and now we validate

+

#               the args after each line of an @file.

+

# 20090520: Use hashlib where it's available, to avoid a warning.

+

#           Use the builtin compile() instead of compiler, for Jython.

+

#           Explicitly close files we opened, Jython likes this.

+ +
+
+ + + diff --git a/doc/sample_html/cogapp_makefiles.html b/doc/sample_html/cogapp_makefiles.html new file mode 100644 index 00000000..d1c7e56e --- /dev/null +++ b/doc/sample_html/cogapp_makefiles.html @@ -0,0 +1,178 @@ + + + +Coverage for cogapp\makefiles + + + + + + + +
+ + + + + +
+

1

+

2

+

3

+

4

+

5

+

6

+

7

+

8

+

9

+

10

+

11

+

12

+

13

+

14

+

15

+

16

+

17

+

18

+

19

+

20

+

21

+

22

+

23

+

24

+

25

+

26

+

27

+

28

+

29

+

30

+

31

+

32

+

33

+

34

+

35

+

36

+

37

+

38

+

39

+

40

+

41

+

42

+

43

+

44

+

45

+

46

+

47

+

48

+

49

+

50

+

51

+

52

+

53

+

54

+

55

+

56

+

57

+

58

+

59

+

60

+

61

+

62

+

63

+

64

+ +
+

""" Dictionary-to-filetree functions, to create test files for testing.

+

    http://nedbatchelder.com/code/cog

+

 

+

    Copyright 2004-2009, Ned Batchelder.

+

"""

+

 

+

import path     # Non-standard, from http://www.jorendorff.com/articles/python/path

+

from whiteutils import reindentBlock

+

 

+

__version__ = '1.0.20040126'

+

__all__ = ['makeFiles', 'removeFiles']

+

 

+

def makeFiles(d, basedir='.', raw=False):

+

    """ Create files from the dictionary d, in the directory named by dirpath.

+

    """

+

    dirpath = path.path(basedir)

+

    for name, contents in d.items():

+

        child = dirpath / name

+

        if isinstance(contents, basestring):

+

            mode = 'w'

+

            if raw:

+

                mode = 'wb'

+

            f = open(child, mode)

+

            if not raw:

+

                contents = reindentBlock(contents)

+

            f.write(contents)

+

            f.close()

+

        else:

+

            if not child.exists():

+

                child.mkdir()

+

            makeFiles(contents, child, raw=raw)

+

 

+

def removeFiles(d, basedir='.'):

+

    """ Remove the files created by makeFiles.

+

        Directories are removed if they are empty.

+

    """

+

    dirpath = path.path(basedir)

+

    for name, contents in d.items():

+

        child = dirpath / name

+

        if isinstance(contents, basestring):

+

            child.remove()

+

        else:

+

            removeFiles(contents, child)

+

            if not child.files() and not child.dirs():

+

                child.rmdir()

+

 

+

if __name__ == '__main__':      #pragma: no cover

+

    # Try it a little.

+

    d = {

+

        'test_makefiles': {

+

            'hey.txt': """\

+

                        This is hey.txt.

+

                        It's very simple.

+

                        """,

+

            'subdir': {

+

                'fooey': """\

+

                            # Fooey

+

                                Kablooey

+

                            Ew.

+

                            """

+

            }

+

        }

+

    }

+

    makeFiles(d)

+ +
+
+ + + diff --git a/doc/sample_html/cogapp_test_cogapp.html b/doc/sample_html/cogapp_test_cogapp.html new file mode 100644 index 00000000..2f19e051 --- /dev/null +++ b/doc/sample_html/cogapp_test_cogapp.html @@ -0,0 +1,3970 @@ + + + +Coverage for cogapp\test_cogapp + + + + + + + +
+ + + + + +
+

1

+

2

+

3

+

4

+

5

+

6

+

7

+

8

+

9

+

10

+

11

+

12

+

13

+

14

+

15

+

16

+

17

+

18

+

19

+

20

+

21

+

22

+

23

+

24

+

25

+

26

+

27

+

28

+

29

+

30

+

31

+

32

+

33

+

34

+

35

+

36

+

37

+

38

+

39

+

40

+

41

+

42

+

43

+

44

+

45

+

46

+

47

+

48

+

49

+

50

+

51

+

52

+

53

+

54

+

55

+

56

+

57

+

58

+

59

+

60

+

61

+

62

+

63

+

64

+

65

+

66

+

67

+

68

+

69

+

70

+

71

+

72

+

73

+

74

+

75

+

76

+

77

+

78

+

79

+

80

+

81

+

82

+

83

+

84

+

85

+

86

+

87

+

88

+

89

+

90

+

91

+

92

+

93

+

94

+

95

+

96

+

97

+

98

+

99

+

100

+

101

+

102

+

103

+

104

+

105

+

106

+

107

+

108

+

109

+

110

+

111

+

112

+

113

+

114

+

115

+

116

+

117

+

118

+

119

+

120

+

121

+

122

+

123

+

124

+

125

+

126

+

127

+

128

+

129

+

130

+

131

+

132

+

133

+

134

+

135

+

136

+

137

+

138

+

139

+

140

+

141

+

142

+

143

+

144

+

145

+

146

+

147

+

148

+

149

+

150

+

151

+

152

+

153

+

154

+

155

+

156

+

157

+

158

+

159

+

160

+

161

+

162

+

163

+

164

+

165

+

166

+

167

+

168

+

169

+

170

+

171

+

172

+

173

+

174

+

175

+

176

+

177

+

178

+

179

+

180

+

181

+

182

+

183

+

184

+

185

+

186

+

187

+

188

+

189

+

190

+

191

+

192

+

193

+

194

+

195

+

196

+

197

+

198

+

199

+

200

+

201

+

202

+

203

+

204

+

205

+

206

+

207

+

208

+

209

+

210

+

211

+

212

+

213

+

214

+

215

+

216

+

217

+

218

+

219

+

220

+

221

+

222

+

223

+

224

+

225

+

226

+

227

+

228

+

229

+

230

+

231

+

232

+

233

+

234

+

235

+

236

+

237

+

238

+

239

+

240

+

241

+

242

+

243

+

244

+

245

+

246

+

247

+

248

+

249

+

250

+

251

+

252

+

253

+

254

+

255

+

256

+

257

+

258

+

259

+

260

+

261

+

262

+

263

+

264

+

265

+

266

+

267

+

268

+

269

+

270

+

271

+

272

+

273

+

274

+

275

+

276

+

277

+

278

+

279

+

280

+

281

+

282

+

283

+

284

+

285

+

286

+

287

+

288

+

289

+

290

+

291

+

292

+

293

+

294

+

295

+

296

+

297

+

298

+

299

+

300

+

301

+

302

+

303

+

304

+

305

+

306

+

307

+

308

+

309

+

310

+

311

+

312

+

313

+

314

+

315

+

316

+

317

+

318

+

319

+

320

+

321

+

322

+

323

+

324

+

325

+

326

+

327

+

328

+

329

+

330

+

331

+

332

+

333

+

334

+

335

+

336

+

337

+

338

+

339

+

340

+

341

+

342

+

343

+

344

+

345

+

346

+

347

+

348

+

349

+

350

+

351

+

352

+

353

+

354

+

355

+

356

+

357

+

358

+

359

+

360

+

361

+

362

+

363

+

364

+

365

+

366

+

367

+

368

+

369

+

370

+

371

+

372

+

373

+

374

+

375

+

376

+

377

+

378

+

379

+

380

+

381

+

382

+

383

+

384

+

385

+

386

+

387

+

388

+

389

+

390

+

391

+

392

+

393

+

394

+

395

+

396

+

397

+

398

+

399

+

400

+

401

+

402

+

403

+

404

+

405

+

406

+

407

+

408

+

409

+

410

+

411

+

412

+

413

+

414

+

415

+

416

+

417

+

418

+

419

+

420

+

421

+

422

+

423

+

424

+

425

+

426

+

427

+

428

+

429

+

430

+

431

+

432

+

433

+

434

+

435

+

436

+

437

+

438

+

439

+

440

+

441

+

442

+

443

+

444

+

445

+

446

+

447

+

448

+

449

+

450

+

451

+

452

+

453

+

454

+

455

+

456

+

457

+

458

+

459

+

460

+

461

+

462

+

463

+

464

+

465

+

466

+

467

+

468

+

469

+

470

+

471

+

472

+

473

+

474

+

475

+

476

+

477

+

478

+

479

+

480

+

481

+

482

+

483

+

484

+

485

+

486

+

487

+

488

+

489

+

490

+

491

+

492

+

493

+

494

+

495

+

496

+

497

+

498

+

499

+

500

+

501

+

502

+

503

+

504

+

505

+

506

+

507

+

508

+

509

+

510

+

511

+

512

+

513

+

514

+

515

+

516

+

517

+

518

+

519

+

520

+

521

+

522

+

523

+

524

+

525

+

526

+

527

+

528

+

529

+

530

+

531

+

532

+

533

+

534

+

535

+

536

+

537

+

538

+

539

+

540

+

541

+

542

+

543

+

544

+

545

+

546

+

547

+

548

+

549

+

550

+

551

+

552

+

553

+

554

+

555

+

556

+

557

+

558

+

559

+

560

+

561

+

562

+

563

+

564

+

565

+

566

+

567

+

568

+

569

+

570

+

571

+

572

+

573

+

574

+

575

+

576

+

577

+

578

+

579

+

580

+

581

+

582

+

583

+

584

+

585

+

586

+

587

+

588

+

589

+

590

+

591

+

592

+

593

+

594

+

595

+

596

+

597

+

598

+

599

+

600

+

601

+

602

+

603

+

604

+

605

+

606

+

607

+

608

+

609

+

610

+

611

+

612

+

613

+

614

+

615

+

616

+

617

+

618

+

619

+

620

+

621

+

622

+

623

+

624

+

625

+

626

+

627

+

628

+

629

+

630

+

631

+

632

+

633

+

634

+

635

+

636

+

637

+

638

+

639

+

640

+

641

+

642

+

643

+

644

+

645

+

646

+

647

+

648

+

649

+

650

+

651

+

652

+

653

+

654

+

655

+

656

+

657

+

658

+

659

+

660

+

661

+

662

+

663

+

664

+

665

+

666

+

667

+

668

+

669

+

670

+

671

+

672

+

673

+

674

+

675

+

676

+

677

+

678

+

679

+

680

+

681

+

682

+

683

+

684

+

685

+

686

+

687

+

688

+

689

+

690

+

691

+

692

+

693

+

694

+

695

+

696

+

697

+

698

+

699

+

700

+

701

+

702

+

703

+

704

+

705

+

706

+

707

+

708

+

709

+

710

+

711

+

712

+

713

+

714

+

715

+

716

+

717

+

718

+

719

+

720

+

721

+

722

+

723

+

724

+

725

+

726

+

727

+

728

+

729

+

730

+

731

+

732

+

733

+

734

+

735

+

736

+

737

+

738

+

739

+

740

+

741

+

742

+

743

+

744

+

745

+

746

+

747

+

748

+

749

+

750

+

751

+

752

+

753

+

754

+

755

+

756

+

757

+

758

+

759

+

760

+

761

+

762

+

763

+

764

+

765

+

766

+

767

+

768

+

769

+

770

+

771

+

772

+

773

+

774

+

775

+

776

+

777

+

778

+

779

+

780

+

781

+

782

+

783

+

784

+

785

+

786

+

787

+

788

+

789

+

790

+

791

+

792

+

793

+

794

+

795

+

796

+

797

+

798

+

799

+

800

+

801

+

802

+

803

+

804

+

805

+

806

+

807

+

808

+

809

+

810

+

811

+

812

+

813

+

814

+

815

+

816

+

817

+

818

+

819

+

820

+

821

+

822

+

823

+

824

+

825

+

826

+

827

+

828

+

829

+

830

+

831

+

832

+

833

+

834

+

835

+

836

+

837

+

838

+

839

+

840

+

841

+

842

+

843

+

844

+

845

+

846

+

847

+

848

+

849

+

850

+

851

+

852

+

853

+

854

+

855

+

856

+

857

+

858

+

859

+

860

+

861

+

862

+

863

+

864

+

865

+

866

+

867

+

868

+

869

+

870

+

871

+

872

+

873

+

874

+

875

+

876

+

877

+

878

+

879

+

880

+

881

+

882

+

883

+

884

+

885

+

886

+

887

+

888

+

889

+

890

+

891

+

892

+

893

+

894

+

895

+

896

+

897

+

898

+

899

+

900

+

901

+

902

+

903

+

904

+

905

+

906

+

907

+

908

+

909

+

910

+

911

+

912

+

913

+

914

+

915

+

916

+

917

+

918

+

919

+

920

+

921

+

922

+

923

+

924

+

925

+

926

+

927

+

928

+

929

+

930

+

931

+

932

+

933

+

934

+

935

+

936

+

937

+

938

+

939

+

940

+

941

+

942

+

943

+

944

+

945

+

946

+

947

+

948

+

949

+

950

+

951

+

952

+

953

+

954

+

955

+

956

+

957

+

958

+

959

+

960

+

961

+

962

+

963

+

964

+

965

+

966

+

967

+

968

+

969

+

970

+

971

+

972

+

973

+

974

+

975

+

976

+

977

+

978

+

979

+

980

+

981

+

982

+

983

+

984

+

985

+

986

+

987

+

988

+

989

+

990

+

991

+

992

+

993

+

994

+

995

+

996

+

997

+

998

+

999

+

1000

+

1001

+

1002

+

1003

+

1004

+

1005

+

1006

+

1007

+

1008

+

1009

+

1010

+

1011

+

1012

+

1013

+

1014

+

1015

+

1016

+

1017

+

1018

+

1019

+

1020

+

1021

+

1022

+

1023

+

1024

+

1025

+

1026

+

1027

+

1028

+

1029

+

1030

+

1031

+

1032

+

1033

+

1034

+

1035

+

1036

+

1037

+

1038

+

1039

+

1040

+

1041

+

1042

+

1043

+

1044

+

1045

+

1046

+

1047

+

1048

+

1049

+

1050

+

1051

+

1052

+

1053

+

1054

+

1055

+

1056

+

1057

+

1058

+

1059

+

1060

+

1061

+

1062

+

1063

+

1064

+

1065

+

1066

+

1067

+

1068

+

1069

+

1070

+

1071

+

1072

+

1073

+

1074

+

1075

+

1076

+

1077

+

1078

+

1079

+

1080

+

1081

+

1082

+

1083

+

1084

+

1085

+

1086

+

1087

+

1088

+

1089

+

1090

+

1091

+

1092

+

1093

+

1094

+

1095

+

1096

+

1097

+

1098

+

1099

+

1100

+

1101

+

1102

+

1103

+

1104

+

1105

+

1106

+

1107

+

1108

+

1109

+

1110

+

1111

+

1112

+

1113

+

1114

+

1115

+

1116

+

1117

+

1118

+

1119

+

1120

+

1121

+

1122

+

1123

+

1124

+

1125

+

1126

+

1127

+

1128

+

1129

+

1130

+

1131

+

1132

+

1133

+

1134

+

1135

+

1136

+

1137

+

1138

+

1139

+

1140

+

1141

+

1142

+

1143

+

1144

+

1145

+

1146

+

1147

+

1148

+

1149

+

1150

+

1151

+

1152

+

1153

+

1154

+

1155

+

1156

+

1157

+

1158

+

1159

+

1160

+

1161

+

1162

+

1163

+

1164

+

1165

+

1166

+

1167

+

1168

+

1169

+

1170

+

1171

+

1172

+

1173

+

1174

+

1175

+

1176

+

1177

+

1178

+

1179

+

1180

+

1181

+

1182

+

1183

+

1184

+

1185

+

1186

+

1187

+

1188

+

1189

+

1190

+

1191

+

1192

+

1193

+

1194

+

1195

+

1196

+

1197

+

1198

+

1199

+

1200

+

1201

+

1202

+

1203

+

1204

+

1205

+

1206

+

1207

+

1208

+

1209

+

1210

+

1211

+

1212

+

1213

+

1214

+

1215

+

1216

+

1217

+

1218

+

1219

+

1220

+

1221

+

1222

+

1223

+

1224

+

1225

+

1226

+

1227

+

1228

+

1229

+

1230

+

1231

+

1232

+

1233

+

1234

+

1235

+

1236

+

1237

+

1238

+

1239

+

1240

+

1241

+

1242

+

1243

+

1244

+

1245

+

1246

+

1247

+

1248

+

1249

+

1250

+

1251

+

1252

+

1253

+

1254

+

1255

+

1256

+

1257

+

1258

+

1259

+

1260

+

1261

+

1262

+

1263

+

1264

+

1265

+

1266

+

1267

+

1268

+

1269

+

1270

+

1271

+

1272

+

1273

+

1274

+

1275

+

1276

+

1277

+

1278

+

1279

+

1280

+

1281

+

1282

+

1283

+

1284

+

1285

+

1286

+

1287

+

1288

+

1289

+

1290

+

1291

+

1292

+

1293

+

1294

+

1295

+

1296

+

1297

+

1298

+

1299

+

1300

+

1301

+

1302

+

1303

+

1304

+

1305

+

1306

+

1307

+

1308

+

1309

+

1310

+

1311

+

1312

+

1313

+

1314

+

1315

+

1316

+

1317

+

1318

+

1319

+

1320

+

1321

+

1322

+

1323

+

1324

+

1325

+

1326

+

1327

+

1328

+

1329

+

1330

+

1331

+

1332

+

1333

+

1334

+

1335

+

1336

+

1337

+

1338

+

1339

+

1340

+

1341

+

1342

+

1343

+

1344

+

1345

+

1346

+

1347

+

1348

+

1349

+

1350

+

1351

+

1352

+

1353

+

1354

+

1355

+

1356

+

1357

+

1358

+

1359

+

1360

+

1361

+

1362

+

1363

+

1364

+

1365

+

1366

+

1367

+

1368

+

1369

+

1370

+

1371

+

1372

+

1373

+

1374

+

1375

+

1376

+

1377

+

1378

+

1379

+

1380

+

1381

+

1382

+

1383

+

1384

+

1385

+

1386

+

1387

+

1388

+

1389

+

1390

+

1391

+

1392

+

1393

+

1394

+

1395

+

1396

+

1397

+

1398

+

1399

+

1400

+

1401

+

1402

+

1403

+

1404

+

1405

+

1406

+

1407

+

1408

+

1409

+

1410

+

1411

+

1412

+

1413

+

1414

+

1415

+

1416

+

1417

+

1418

+

1419

+

1420

+

1421

+

1422

+

1423

+

1424

+

1425

+

1426

+

1427

+

1428

+

1429

+

1430

+

1431

+

1432

+

1433

+

1434

+

1435

+

1436

+

1437

+

1438

+

1439

+

1440

+

1441

+

1442

+

1443

+

1444

+

1445

+

1446

+

1447

+

1448

+

1449

+

1450

+

1451

+

1452

+

1453

+

1454

+

1455

+

1456

+

1457

+

1458

+

1459

+

1460

+

1461

+

1462

+

1463

+

1464

+

1465

+

1466

+

1467

+

1468

+

1469

+

1470

+

1471

+

1472

+

1473

+

1474

+

1475

+

1476

+

1477

+

1478

+

1479

+

1480

+

1481

+

1482

+

1483

+

1484

+

1485

+

1486

+

1487

+

1488

+

1489

+

1490

+

1491

+

1492

+

1493

+

1494

+

1495

+

1496

+

1497

+

1498

+

1499

+

1500

+

1501

+

1502

+

1503

+

1504

+

1505

+

1506

+

1507

+

1508

+

1509

+

1510

+

1511

+

1512

+

1513

+

1514

+

1515

+

1516

+

1517

+

1518

+

1519

+

1520

+

1521

+

1522

+

1523

+

1524

+

1525

+

1526

+

1527

+

1528

+

1529

+

1530

+

1531

+

1532

+

1533

+

1534

+

1535

+

1536

+

1537

+

1538

+

1539

+

1540

+

1541

+

1542

+

1543

+

1544

+

1545

+

1546

+

1547

+

1548

+

1549

+

1550

+

1551

+

1552

+

1553

+

1554

+

1555

+

1556

+

1557

+

1558

+

1559

+

1560

+

1561

+

1562

+

1563

+

1564

+

1565

+

1566

+

1567

+

1568

+

1569

+

1570

+

1571

+

1572

+

1573

+

1574

+

1575

+

1576

+

1577

+

1578

+

1579

+

1580

+

1581

+

1582

+

1583

+

1584

+

1585

+

1586

+

1587

+

1588

+

1589

+

1590

+

1591

+

1592

+

1593

+

1594

+

1595

+

1596

+

1597

+

1598

+

1599

+

1600

+

1601

+

1602

+

1603

+

1604

+

1605

+

1606

+

1607

+

1608

+

1609

+

1610

+

1611

+

1612

+

1613

+

1614

+

1615

+

1616

+

1617

+

1618

+

1619

+

1620

+

1621

+

1622

+

1623

+

1624

+

1625

+

1626

+

1627

+

1628

+

1629

+

1630

+

1631

+

1632

+

1633

+

1634

+

1635

+

1636

+

1637

+

1638

+

1639

+

1640

+

1641

+

1642

+

1643

+

1644

+

1645

+

1646

+

1647

+

1648

+

1649

+

1650

+

1651

+

1652

+

1653

+

1654

+

1655

+

1656

+

1657

+

1658

+

1659

+

1660

+

1661

+

1662

+

1663

+

1664

+

1665

+

1666

+

1667

+

1668

+

1669

+

1670

+

1671

+

1672

+

1673

+

1674

+

1675

+

1676

+

1677

+

1678

+

1679

+

1680

+

1681

+

1682

+

1683

+

1684

+

1685

+

1686

+

1687

+

1688

+

1689

+

1690

+

1691

+

1692

+

1693

+

1694

+

1695

+

1696

+

1697

+

1698

+

1699

+

1700

+

1701

+

1702

+

1703

+

1704

+

1705

+

1706

+

1707

+

1708

+

1709

+

1710

+

1711

+

1712

+

1713

+

1714

+

1715

+

1716

+

1717

+

1718

+

1719

+

1720

+

1721

+

1722

+

1723

+

1724

+

1725

+

1726

+

1727

+

1728

+

1729

+

1730

+

1731

+

1732

+

1733

+

1734

+

1735

+

1736

+

1737

+

1738

+

1739

+

1740

+

1741

+

1742

+

1743

+

1744

+

1745

+

1746

+

1747

+

1748

+

1749

+

1750

+

1751

+

1752

+

1753

+

1754

+

1755

+

1756

+

1757

+

1758

+

1759

+

1760

+

1761

+

1762

+

1763

+

1764

+

1765

+

1766

+

1767

+

1768

+

1769

+

1770

+

1771

+

1772

+

1773

+

1774

+

1775

+

1776

+

1777

+

1778

+

1779

+

1780

+

1781

+

1782

+

1783

+

1784

+

1785

+

1786

+

1787

+

1788

+

1789

+

1790

+

1791

+

1792

+

1793

+

1794

+

1795

+

1796

+

1797

+

1798

+

1799

+

1800

+

1801

+

1802

+

1803

+

1804

+

1805

+

1806

+

1807

+

1808

+

1809

+

1810

+

1811

+

1812

+

1813

+

1814

+

1815

+

1816

+

1817

+

1818

+

1819

+

1820

+

1821

+

1822

+

1823

+

1824

+

1825

+

1826

+

1827

+

1828

+

1829

+

1830

+

1831

+

1832

+

1833

+

1834

+

1835

+

1836

+

1837

+

1838

+

1839

+

1840

+

1841

+

1842

+

1843

+

1844

+

1845

+

1846

+

1847

+

1848

+

1849

+

1850

+

1851

+

1852

+

1853

+

1854

+

1855

+

1856

+

1857

+

1858

+

1859

+

1860

+

1861

+

1862

+

1863

+

1864

+

1865

+

1866

+

1867

+

1868

+

1869

+

1870

+

1871

+

1872

+

1873

+

1874

+

1875

+

1876

+

1877

+

1878

+

1879

+

1880

+

1881

+

1882

+

1883

+

1884

+

1885

+

1886

+

1887

+

1888

+

1889

+

1890

+

1891

+

1892

+

1893

+

1894

+

1895

+

1896

+

1897

+

1898

+

1899

+

1900

+

1901

+

1902

+

1903

+

1904

+

1905

+

1906

+

1907

+

1908

+

1909

+

1910

+

1911

+

1912

+

1913

+

1914

+

1915

+

1916

+

1917

+

1918

+

1919

+

1920

+

1921

+

1922

+

1923

+

1924

+

1925

+

1926

+

1927

+

1928

+

1929

+

1930

+

1931

+

1932

+

1933

+

1934

+

1935

+

1936

+

1937

+

1938

+

1939

+

1940

+

1941

+

1942

+

1943

+

1944

+

1945

+

1946

+

1947

+

1948

+

1949

+

1950

+

1951

+

1952

+

1953

+

1954

+

1955

+

1956

+

1957

+

1958

+

1959

+

1960

+ +
+

""" Test cogapp.

+

    http://nedbatchelder.com/code/cog

+

 

+

    Copyright 2004-2009, Ned Batchelder.

+

"""

+

 

+

import unittest

+

import os, random, re, StringIO, stat, sys, tempfile

+

import path     # Non-standard, from http://www.jorendorff.com/articles/python/path

+

from cogapp import Cog, CogOptions, CogGenerator

+

from cogapp import CogError, CogUsageError, CogGeneratedError

+

from cogapp import usage, __version__

+

from whiteutils import reindentBlock

+

from makefiles import *

+

 

+

class TestCase(unittest.TestCase):

+

    """ Base class for all Cog test cases.  Adds utility methods I like.

+

    """

+

    def assertRaisesMsg(self, excClass, msg, callableObj, *args, **kwargs):

+

        """ Just like unittest.TestCase.assertRaises,

+

            but checks that the message is right too.

+

        """

+

        try:

+

            callableObj(*args, **kwargs)

+

        except excClass, exc:

+

            excMsg = str(exc)

+

            if not msg:

+

                # No message provided: it passes.

+

                return  #pragma: no cover

+

            elif excMsg == msg:

+

                # Message provided, and we got the right message: it passes.

+

                return

+

            else:   #pragma: no cover

+

                # Message provided, and it didn't match: fail!

+

                raise self.failureException("Right exception, wrong message: got '%s' expected '%s'" % (excMsg, msg))

+

        else:   #pragma: no cover

+

            if hasattr(excClass,'__name__'):

+

                excName = excClass.__name__

+

            else:

+

                excName = str(excClass)

+

            raise self.failureException("Expected to raise %s, didn't get an exception at all" % excName)

+

 

+

class CogTestsInMemory(TestCase):

+

    """ Test cases for cogapp.Cog()

+

    """

+

 

+

    def testNoCog(self):

+

        strings = [

+

            '',

+

            ' ',

+

            ' \t \t \tx',

+

            'hello',

+

            'the cat\nin the\nhat.',

+

            'Horton\n\tHears A\n\t\tWho'

+

            ]

+

        for s in strings:

+

            self.assertEqual(Cog().processString(s), s)

+

 

+

    def testSimple(self):

+

        infile = """\

+

            Some text.

+

            //[[[cog

+

            import cog

+

            cog.outl("This is line one\\n")

+

            cog.outl("This is line two")

+

            //]]]

+

            gobbledegook.

+

            //[[[end]]]

+

            epilogue.

+

            """

+

 

+

        outfile = """\

+

            Some text.

+

            //[[[cog

+

            import cog

+

            cog.outl("This is line one\\n")

+

            cog.outl("This is line two")

+

            //]]]

+

            This is line one

+

 

+

            This is line two

+

            //[[[end]]]

+

            epilogue.

+

            """

+

 

+

        self.assertEqual(Cog().processString(infile), outfile)

+

 

+

    def testEmptyCog(self):

+

        # The cog clause can be totally empty.  Not sure why you'd want it,

+

        # but it works.

+

        infile = """\

+

            hello

+

            //[[[cog

+

            //]]]

+

            //[[[end]]]

+

            goodbye

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def testMultipleCogs(self):

+

        # One file can have many cog chunks, even abutting each other.

+

        infile = """\

+

            //[[[cog

+

            cog.out("chunk1")

+

            //]]]

+

            chunk1

+

            //[[[end]]]

+

            //[[[cog

+

            cog.out("chunk2")

+

            //]]]

+

            chunk2

+

            //[[[end]]]

+

            between chunks

+

            //[[[cog

+

            cog.out("chunk3")

+

            //]]]

+

            chunk3

+

            //[[[end]]]

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def testTrimBlankLines(self):

+

        infile = """\

+

            //[[[cog

+

            cog.out("This is line one\\n", trimblanklines=True)

+

            cog.out('''

+

                This is line two

+

            ''', dedent=True, trimblanklines=True)

+

            cog.outl("This is line three", trimblanklines=True)

+

            //]]]

+

            This is line one

+

            This is line two

+

            This is line three

+

            //[[[end]]]

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def testTrimEmptyBlankLines(self):

+

        infile = """\

+

            //[[[cog

+

            cog.out("This is line one\\n", trimblanklines=True)

+

            cog.out('''

+

                This is line two

+

            ''', dedent=True, trimblanklines=True)

+

            cog.out('', dedent=True, trimblanklines=True)

+

            cog.outl("This is line three", trimblanklines=True)

+

            //]]]

+

            This is line one

+

            This is line two

+

            This is line three

+

            //[[[end]]]

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def test22EndOfLine(self):

+

        # In Python 2.2, this cog file was not parsing because the

+

        # last line is indented but didn't end with a newline.

+

        infile = """\

+

            //[[[cog

+

            import cog

+

            for i in range(3):

+

                cog.out("%d\\n" % i)

+

            //]]]

+

            0

+

            1

+

            2

+

            //[[[end]]]

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def testIndentedCode(self):

+

        infile = """\

+

            first line

+

                [[[cog

+

                import cog

+

                for i in range(3):

+

                    cog.out("xx%d\\n" % i)

+

                ]]]

+

                xx0

+

                xx1

+

                xx2

+

                [[[end]]]

+

            last line

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def testPrefixedCode(self):

+

        infile = """\

+

            --[[[cog

+

            --import cog

+

            --for i in range(3):

+

            --    cog.out("xx%d\\n" % i)

+

            --]]]

+

            xx0

+

            xx1

+

            xx2

+

            --[[[end]]]

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def testPrefixedIndentedCode(self):

+

        infile = """\

+

            prologue

+

            --[[[cog

+

            --   import cog

+

            --   for i in range(3):

+

            --       cog.out("xy%d\\n" % i)

+

            --]]]

+

            xy0

+

            xy1

+

            xy2

+

            --[[[end]]]

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def testBogusPrefixMatch(self):

+

        infile = """\

+

            prologue

+

            #[[[cog

+

                import cog

+

                # This comment should not be clobbered by removing the pound sign.

+

                for i in range(3):

+

                    cog.out("xy%d\\n" % i)

+

            #]]]

+

            xy0

+

            xy1

+

            xy2

+

            #[[[end]]]

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def testNoFinalNewline(self):

+

        # If the cog'ed output has no final newline,

+

        # it shouldn't eat up the cog terminator.

+

        infile = """\

+

            prologue

+

            [[[cog

+

                import cog

+

                for i in range(3):

+

                    cog.out("%d" % i)

+

            ]]]

+

            012

+

            [[[end]]]

+

            epilogue

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def testNoOutputAtAll(self):

+

        # If there is absolutely no cog output, that's ok.

+

        infile = """\

+

            prologue

+

            [[[cog

+

                i = 1

+

            ]]]

+

            [[[end]]]

+

            epilogue

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def testPurelyBlankLine(self):

+

        # If there is a blank line in the cog code with no whitespace

+

        # prefix, that should be OK.

+

 

+

        infile = """\

+

            prologue

+

                [[[cog

+

                    import sys

+

                    cog.out("Hello")

+

            $

+

                    cog.out("There")

+

                ]]]

+

                HelloThere

+

                [[[end]]]

+

            epilogue

+

            """

+

 

+

        infile = reindentBlock(infile.replace('$', ''))

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def testEmptyOutl(self):

+

        # Alexander Belchenko suggested the string argument to outl should

+

        # be optional.  Does it work?

+

 

+

        infile = """\

+

            prologue

+

            [[[cog

+

                cog.outl("x")

+

                cog.outl()

+

                cog.outl("y")

+

                cog.outl(trimblanklines=True)

+

                cog.outl("z")

+

            ]]]

+

            x

+

 

+

            y

+

 

+

            z

+

            [[[end]]]

+

            epilogue

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def testFirstLineNum(self):

+

        infile = """\

+

            fooey

+

            [[[cog

+

                cog.outl("started at line number %d" % cog.firstLineNum)

+

            ]]]

+

            started at line number 2

+

            [[[end]]]

+

            blah blah

+

            [[[cog

+

                cog.outl("and again at line %d" % cog.firstLineNum)

+

            ]]]

+

            and again at line 8

+

            [[[end]]]

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

    def testCompactOneLineCode(self):

+

        infile = """\

+

            first line

+

            hey: [[[cog cog.outl("hello %d" % (3*3*3*3)) ]]] looky!

+

            get rid of this!

+

            [[[end]]]

+

            last line

+

            """

+

 

+

        outfile = """\

+

            first line

+

            hey: [[[cog cog.outl("hello %d" % (3*3*3*3)) ]]] looky!

+

            hello 81

+

            [[[end]]]

+

            last line

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), reindentBlock(outfile))

+

 

+

    def testInsideOutCompact(self):

+

        infile = """\

+

            first line

+

            hey?: ]]] what is this? [[[cog strange!

+

            get rid of this!

+

            [[[end]]]

+

            last line

+

            """

+

        self.assertRaisesMsg(CogError,

+

             "infile.txt(2): Cog code markers inverted",

+

             Cog().processString,

+

             reindentBlock(infile), "infile.txt")

+

 

+

    def testSharingGlobals(self):

+

        infile = """\

+

            first line

+

            hey: [[[cog s="hey there" ]]] looky!

+

            [[[end]]]

+

            more literal junk.

+

            [[[cog cog.outl(s) ]]]

+

            [[[end]]]

+

            last line

+

            """

+

 

+

        outfile = """\

+

            first line

+

            hey: [[[cog s="hey there" ]]] looky!

+

            [[[end]]]

+

            more literal junk.

+

            [[[cog cog.outl(s) ]]]

+

            hey there

+

            [[[end]]]

+

            last line

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), reindentBlock(outfile))

+

 

+

class CogOptionsTests(TestCase):

+

    """ Test the CogOptions class.

+

    """

+

 

+

    def testEquality(self):

+

        o = CogOptions()

+

        p = CogOptions()

+

        self.assertEqual(o, p)

+

        o.parseArgs(['-r'])

+

        self.assertNotEqual(o, p)

+

        p.parseArgs(['-r'])

+

        self.assertEqual(o, p)

+

 

+

    def testCloning(self):

+

        o = CogOptions()

+

        o.parseArgs(['-I', 'fooey', '-I', 'booey', '-s', ' /*x*/'])

+

        p = o.clone()

+

        self.assertEqual(o, p)

+

        p.parseArgs(['-I', 'huey', '-D', 'foo=quux'])

+

        self.assertNotEqual(o, p)

+

        q = CogOptions()

+

        q.parseArgs(['-I', 'fooey', '-I', 'booey', '-s', ' /*x*/', '-I', 'huey', '-D', 'foo=quux'])

+

        self.assertEqual(p, q)

+

 

+

    def testCombiningFlags(self):

+

        # Single-character flags can be combined.

+

        o = CogOptions()

+

        o.parseArgs(['-e', '-r', '-z'])

+

        p = CogOptions()

+

        p.parseArgs(['-erz'])

+

        self.assertEqual(o, p)

+

 

+

class FileStructureTests(TestCase):

+

    """ Test cases to check that we're properly strict about the structure

+

        of files.

+

    """

+

 

+

    def isBad(self, infile, msg=None):

+

        infile = reindentBlock(infile)

+

        self.assertRaisesMsg(CogError,

+

            msg,

+

            Cog().processString, (infile), 'infile.txt')

+

 

+

    def testBeginNoEnd(self):

+

        infile = """\

+

            Fooey

+

            #[[[cog

+

                cog.outl('hello')

+

            """

+

        self.isBad(infile, "infile.txt(2): Cog block begun but never ended.")

+

 

+

    def testNoEoo(self):

+

        infile = """\

+

            Fooey

+

            #[[[cog

+

                cog.outl('hello')

+

            #]]]

+

            """

+

        self.isBad(infile, "infile.txt(4): Missing '[[[end]]]' before end of file.")

+

 

+

        infile2 = """\

+

            Fooey

+

            #[[[cog

+

                cog.outl('hello')

+

            #]]]

+

            #[[[cog

+

                cog.outl('goodbye')

+

            #]]]

+

            """

+

        self.isBad(infile2, "infile.txt(5): Unexpected '[[[cog'")

+

 

+

    def testStartWithEnd(self):

+

        infile = """\

+

            #]]]

+

            """

+

        self.isBad(infile, "infile.txt(1): Unexpected ']]]'")

+

 

+

        infile2 = """\

+

            #[[[cog

+

                cog.outl('hello')

+

            #]]]

+

            #[[[end]]]

+

            #]]]

+

            """

+

        self.isBad(infile2, "infile.txt(5): Unexpected ']]]'")

+

 

+

    def testStartWithEoo(self):

+

        infile = """\

+

            #[[[end]]]

+

            """

+

        self.isBad(infile, "infile.txt(1): Unexpected '[[[end]]]'")

+

 

+

        infile2 = """\

+

            #[[[cog

+

                cog.outl('hello')

+

            #]]]

+

            #[[[end]]]

+

            #[[[end]]]

+

            """

+

        self.isBad(infile2, "infile.txt(5): Unexpected '[[[end]]]'")

+

 

+

    def testNoEnd(self):

+

        infile = """\

+

            #[[[cog

+

                cog.outl("hello")

+

            #[[[end]]]

+

            """

+

        self.isBad(infile, "infile.txt(3): Unexpected '[[[end]]]'")

+

 

+

        infile2 = """\

+

            #[[[cog

+

                cog.outl('hello')

+

            #]]]

+

            #[[[end]]]

+

            #[[[cog

+

                cog.outl("hello")

+

            #[[[end]]]

+

            """

+

        self.isBad(infile2, "infile.txt(7): Unexpected '[[[end]]]'")

+

 

+

    def testTwoBegins(self):

+

        infile = """\

+

            #[[[cog

+

            #[[[cog

+

                cog.outl("hello")

+

            #]]]

+

            #[[[end]]]

+

            """

+

        self.isBad(infile, "infile.txt(2): Unexpected '[[[cog'")

+

 

+

        infile2 = """\

+

            #[[[cog

+

                cog.outl("hello")

+

            #]]]

+

            #[[[end]]]

+

            #[[[cog

+

            #[[[cog

+

                cog.outl("hello")

+

            #]]]

+

            #[[[end]]]

+

            """

+

        self.isBad(infile2, "infile.txt(6): Unexpected '[[[cog'")

+

 

+

    def testTwoEnds(self):

+

        infile = """\

+

            #[[[cog

+

                cog.outl("hello")

+

            #]]]

+

            #]]]

+

            #[[[end]]]

+

            """

+

        self.isBad(infile, "infile.txt(4): Unexpected ']]]'")

+

 

+

        infile2 = """\

+

            #[[[cog

+

                cog.outl("hello")

+

            #]]]

+

            #[[[end]]]

+

            #[[[cog

+

                cog.outl("hello")

+

            #]]]

+

            #]]]

+

            #[[[end]]]

+

            """

+

        self.isBad(infile2, "infile.txt(8): Unexpected ']]]'")

+

 

+

class CogErrorTests(TestCase):

+

    """ Test cases for cog.error().

+

    """

+

 

+

    def testErrorMsg(self):

+

        infile = """\

+

            [[[cog cog.error("This ain't right!")]]]

+

            [[[end]]]

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertRaisesMsg(CogGeneratedError,

+

            "This ain't right!",

+

            Cog().processString, (infile))

+

 

+

    def testErrorNoMsg(self):

+

        infile = """\

+

            [[[cog cog.error()]]]

+

            [[[end]]]

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertRaisesMsg(CogGeneratedError,

+

            "Error raised by cog generator.",

+

            Cog().processString, (infile))

+

 

+

    def testNoErrorIfErrorNotCalled(self):

+

        infile = """\

+

            --[[[cog

+

            --import cog

+

            --for i in range(3):

+

            --    if i > 10:

+

            --        cog.error("Something is amiss!")

+

            --    cog.out("xx%d\\n" % i)

+

            --]]]

+

            xx0

+

            xx1

+

            xx2

+

            --[[[end]]]

+

            """

+

 

+

        infile = reindentBlock(infile)

+

        self.assertEqual(Cog().processString(infile), infile)

+

 

+

class CogGeneratorGetCodeTests(TestCase):

+

    """ Unit tests against CogGenerator to see if its getCode() method works

+

        properly.

+

    """

+

 

+

    def setUp(self):

+

        """ All tests get a generator to use, and short same-length names for

+

            the functions we're going to use.

+

        """

+

        self.gen = CogGenerator()

+

        self.m = self.gen.parseMarker

+

        self.l = self.gen.parseLine

+

 

+

    def testEmpty(self):

+

        self.m('// [[[cog')

+

        self.m('// ]]]')

+

        self.assertEqual(self.gen.getCode(), '')

+

 

+

    def testSimple(self):

+

        self.m('// [[[cog')

+

        self.l('  print "hello"')

+

        self.l('  print "bye"')

+

        self.m('// ]]]')

+

        self.assertEqual(self.gen.getCode(), 'print "hello"\nprint "bye"')

+

 

+

    def testCompressed1(self):

+

        # For a while, I supported compressed code blocks, but no longer.

+

        self.m('// [[[cog: print """')

+

        self.l('// hello')

+

        self.l('// bye')

+

        self.m('// """)]]]')

+

        self.assertEqual(self.gen.getCode(), 'hello\nbye')

+

 

+

    def testCompressed2(self):

+

        # For a while, I supported compressed code blocks, but no longer.

+

        self.m('// [[[cog: print """')

+

        self.l('hello')

+

        self.l('bye')

+

        self.m('// """)]]]')

+

        self.assertEqual(self.gen.getCode(), 'hello\nbye')

+

 

+

    def testCompressed3(self):

+

        # For a while, I supported compressed code blocks, but no longer.

+

        self.m('// [[[cog')

+

        self.l('print """hello')

+

        self.l('bye')

+

        self.m('// """)]]]')

+

        self.assertEqual(self.gen.getCode(), 'print """hello\nbye')

+

 

+

    def testCompressed4(self):

+

        # For a while, I supported compressed code blocks, but no longer.

+

        self.m('// [[[cog: print """')

+

        self.l('hello')

+

        self.l('bye""")')

+

        self.m('// ]]]')

+

        self.assertEqual(self.gen.getCode(), 'hello\nbye""")')

+

 

+

    def testNoCommonPrefixForMarkers(self):

+

        # It's important to be able to use #if 0 to hide lines from a

+

        # C++ compiler.

+

        self.m('#if 0 //[[[cog')

+

        self.l('\timport cog, sys')

+

        self.l('')

+

        self.l('\tprint sys.argv')

+

        self.m('#endif //]]]')

+

        self.assertEqual(self.gen.getCode(), 'import cog, sys\n\nprint sys.argv')

+

 

+

class TestCaseWithTempDir(TestCase):

+

 

+

    def newCog(self):

+

        """ Initialize the cog members for another run.

+

        """

+

        # Create a cog engine, and catch its output.

+

        self.cog = Cog()

+

        self.output = StringIO.StringIO()

+

        self.cog.setOutput(stdout=self.output, stderr=self.output)

+

 

+

    def setUp(self):

+

        # Create a temporary directory.

+

        self.tempdir = path.path(tempfile.gettempdir()) / ('testcog_tempdir_' + str(random.random())[2:])

+

        self.tempdir.mkdir()

+

        self.olddir = os.getcwd()

+

        os.chdir(self.tempdir)

+

        self.newCog()

+

 

+

    def tearDown(self):

+

        os.chdir(self.olddir)

+

        # Get rid of the temporary directory.

+

        self.tempdir.rmtree()

+

 

+

    def assertFilesSame(self, sFName1, sFName2):

+

        self.assertEqual((self.tempdir / sFName1).text(), (self.tempdir / sFName2).text())

+

 

+

    def assertFileContent(self, sFName, sContent):

+

        sAbsName = self.tempdir / sFName

+

        f = open(sAbsName, 'rb')

+

        try:

+

            sFileContent = f.read()

+

        finally:

+

            f.close()

+

        self.assertEqual(sFileContent, sContent)

+

 

+

 

+

class ArgumentHandlingTests(TestCaseWithTempDir):

+

 

+

    def testArgumentFailure(self):

+

        # Return value 2 means usage problem.

+

        assert(self.cog.main(['argv0', '-j']) == 2)

+

        output = self.output.getvalue()

+

        assert(output.find("option -j not recognized") >= 0)

+

        self.assertRaises(CogUsageError, self.cog.callableMain, (['argv0']))

+

        self.assertRaises(CogUsageError, self.cog.callableMain, (['argv0', '-j']))

+

 

+

    def testNoDashOAndAtFile(self):

+

        d = {

+

            'cogfiles.txt': """\

+

                # Please run cog

+

                """

+

            }

+

 

+

        makeFiles(d)

+

        self.assertRaises(CogUsageError, self.cog.callableMain, (['argv0', '-o', 'foo', '@cogfiles.txt']))

+

 

+

    def testDashV(self):

+

        assert(self.cog.main(['argv0', '-v']) == 0)

+

        output = self.output.getvalue()

+

        self.assertEqual('Cog version %s\n' % __version__, output)

+

 

+

    def producesHelp(self, args):

+

        self.newCog()

+

        argv = ['argv0'] + args.split()

+

        assert(self.cog.main(argv) == 0)

+

        self.assertEquals(usage, self.output.getvalue())

+

 

+

    def testDashH(self):

+

        # -h or -? anywhere on the command line should just print help.

+

        self.producesHelp("-h")

+

        self.producesHelp("-?")

+

        self.producesHelp("fooey.txt -h")

+

        self.producesHelp("-o -r @fooey.txt -? @booey.txt")

+

 

+

    def testDashOAndDashR(self):

+

        d = {

+

            'cogfile.txt': """\

+

                # Please run cog

+

                """

+

            }

+

 

+

        makeFiles(d)

+

        self.assertRaises(CogUsageError, self.cog.callableMain, (['argv0', '-o', 'foo', '-r', 'cogfile.txt']))

+

 

+

    def testDashZ(self):

+

        d = {

+

            'test.cog': """\

+

                // This is my C++ file.

+

                //[[[cog

+

                fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing']

+

                for fn in fnames:

+

                    cog.outl("void %s();" % fn)

+

                //]]]

+

                """,

+

 

+

            'test.out': """\

+

                // This is my C++ file.

+

                //[[[cog

+

                fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing']

+

                for fn in fnames:

+

                    cog.outl("void %s();" % fn)

+

                //]]]

+

                void DoSomething();

+

                void DoAnotherThing();

+

                void DoLastThing();

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.assertRaisesMsg(

+

            CogError, "test.cog(6): Missing '[[[end]]]' before end of file.",

+

            self.cog.callableMain, (['argv0', '-r', 'test.cog']))

+

        self.newCog()

+

        self.cog.callableMain(['argv0', '-r', '-z', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.out')

+

 

+

    def testBadDashD(self):

+

        self.assertRaises(CogUsageError, self.cog.callableMain, (['argv0', '-Dfooey', 'cog.txt']))

+

        self.assertRaises(CogUsageError, self.cog.callableMain, (['argv0', '-D', 'fooey', 'cog.txt']))

+

 

+

 

+

class TestFileHandling(TestCaseWithTempDir):

+

 

+

    def testSimple(self):

+

        d = {

+

            'test.cog': """\

+

                // This is my C++ file.

+

                //[[[cog

+

                fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing']

+

                for fn in fnames:

+

                    cog.outl("void %s();" % fn)

+

                //]]]

+

                //[[[end]]]

+

                """,

+

 

+

            'test.out': """\

+

                // This is my C++ file.

+

                //[[[cog

+

                fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing']

+

                for fn in fnames:

+

                    cog.outl("void %s();" % fn)

+

                //]]]

+

                void DoSomething();

+

                void DoAnotherThing();

+

                void DoLastThing();

+

                //[[[end]]]

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.out')

+

        output = self.output.getvalue()

+

        assert(output.find("(changed)") >= 0)

+

 

+

    def testOutputFile(self):

+

        # -o sets the output file.

+

        d = {

+

            'test.cog': """\

+

                // This is my C++ file.

+

                //[[[cog

+

                fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing']

+

                for fn in fnames:

+

                    cog.outl("void %s();" % fn)

+

                //]]]

+

                //[[[end]]]

+

                """,

+

 

+

            'test.out': """\

+

                // This is my C++ file.

+

                //[[[cog

+

                fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing']

+

                for fn in fnames:

+

                    cog.outl("void %s();" % fn)

+

                //]]]

+

                void DoSomething();

+

                void DoAnotherThing();

+

                void DoLastThing();

+

                //[[[end]]]

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-o', 'test.cogged', 'test.cog'])

+

        self.assertFilesSame('test.cogged', 'test.out')

+

 

+

    def testAtFile(self):

+

        d = {

+

            'one.cog': """\

+

                //[[[cog

+

                cog.outl("hello world")

+

                //]]]

+

                //[[[end]]]

+

                """,

+

 

+

            'one.out': """\

+

                //[[[cog

+

                cog.outl("hello world")

+

                //]]]

+

                hello world

+

                //[[[end]]]

+

                """,

+

 

+

            'two.cog': """\

+

                //[[[cog

+

                cog.outl("goodbye cruel world")

+

                //]]]

+

                //[[[end]]]

+

                """,

+

 

+

            'two.out': """\

+

                //[[[cog

+

                cog.outl("goodbye cruel world")

+

                //]]]

+

                goodbye cruel world

+

                //[[[end]]]

+

                """,

+

 

+

            'cogfiles.txt': """\

+

                # Please run cog

+

                one.cog

+

 

+

                two.cog

+

                """

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', '@cogfiles.txt'])

+

        self.assertFilesSame('one.cog', 'one.out')

+

        self.assertFilesSame('two.cog', 'two.out')

+

        output = self.output.getvalue()

+

        assert(output.find("(changed)") >= 0)

+

 

+

    def testNestedAtFile(self):

+

        d = {

+

            'one.cog': """\

+

                //[[[cog

+

                cog.outl("hello world")

+

                //]]]

+

                //[[[end]]]

+

                """,

+

 

+

            'one.out': """\

+

                //[[[cog

+

                cog.outl("hello world")

+

                //]]]

+

                hello world

+

                //[[[end]]]

+

                """,

+

 

+

            'two.cog': """\

+

                //[[[cog

+

                cog.outl("goodbye cruel world")

+

                //]]]

+

                //[[[end]]]

+

                """,

+

 

+

            'two.out': """\

+

                //[[[cog

+

                cog.outl("goodbye cruel world")

+

                //]]]

+

                goodbye cruel world

+

                //[[[end]]]

+

                """,

+

 

+

            'cogfiles.txt': """\

+

                # Please run cog

+

                one.cog

+

                @cogfiles2.txt

+

                """,

+

 

+

            'cogfiles2.txt': """\

+

                # This one too, please.

+

                two.cog

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', '@cogfiles.txt'])

+

        self.assertFilesSame('one.cog', 'one.out')

+

        self.assertFilesSame('two.cog', 'two.out')

+

        output = self.output.getvalue()

+

        assert(output.find("(changed)") >= 0)

+

 

+

    def testAtFileWithArgs(self):

+

        d = {

+

            'both.cog': """\

+

                //[[[cog

+

                cog.outl("one: %s" % globals().has_key('one'))

+

                cog.outl("two: %s" % globals().has_key('two'))

+

                //]]]

+

                //[[[end]]]

+

                """,

+

 

+

            'one.out': """\

+

                //[[[cog

+

                cog.outl("one: %s" % globals().has_key('one'))

+

                cog.outl("two: %s" % globals().has_key('two'))

+

                //]]]

+

                one: True // ONE

+

                two: False // ONE

+

                //[[[end]]]

+

                """,

+

 

+

            'two.out': """\

+

                //[[[cog

+

                cog.outl("one: %s" % globals().has_key('one'))

+

                cog.outl("two: %s" % globals().has_key('two'))

+

                //]]]

+

                one: False // TWO

+

                two: True // TWO

+

                //[[[end]]]

+

                """,

+

 

+

            'cogfiles.txt': """\

+

                # Please run cog

+

                both.cog -o both.one -s ' // ONE' -D one=x

+

                both.cog -o both.two -s ' // TWO' -D two=x

+

                """

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '@cogfiles.txt'])

+

        self.assertFilesSame('both.one', 'one.out')

+

        self.assertFilesSame('both.two', 'two.out')

+

 

+

    def testAtFileWithBadArgCombo(self):

+

        d = {

+

            'both.cog': """\

+

                //[[[cog

+

                cog.outl("one: %s" % globals().has_key('one'))

+

                cog.outl("two: %s" % globals().has_key('two'))

+

                //]]]

+

                //[[[end]]]

+

                """,

+

 

+

            'cogfiles.txt': """\

+

                # Please run cog

+

                both.cog

+

                both.cog -d # This is bad: -r and -d

+

                """

+

            }

+

 

+

        makeFiles(d)

+

        self.assertRaises(CogUsageError, self.cog.callableMain, (['argv0', '-r', '@cogfiles.txt']))

+

 

+

    def testAtFileWithTrickyFilenames(self):

+

        d = {

+

            'one 1.cog': """\

+

                //[[[cog cog.outl("hello world") ]]]

+

                """,

+

 

+

            'one.out': """\

+

                //[[[cog cog.outl("hello world") ]]]

+

                hello world //xxx

+

                """,

+

 

+

            'subdir': {

+

                'subback.cog': """\

+

                    //[[[cog cog.outl("down deep with backslashes") ]]]

+

                    """,

+

 

+

                'subfwd.cog': """\

+

                    //[[[cog cog.outl("down deep with slashes") ]]]

+

                    """,

+

                },

+

 

+

            'subback.out': """\

+

                //[[[cog cog.outl("down deep with backslashes") ]]]

+

                down deep with backslashes //yyy

+

                """,

+

 

+

            'subfwd.out': """\

+

                //[[[cog cog.outl("down deep with slashes") ]]]

+

                down deep with slashes //zzz

+

                """,

+

 

+

            'cogfiles.txt': """\

+

                # Please run cog

+

                'one 1.cog' -s ' //xxx'

+

                subdir\subback.cog -s ' //yyy'

+

                subdir/subfwd.cog -s ' //zzz'

+

                """

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-z', '-r', '@cogfiles.txt'])

+

        self.assertFilesSame('one 1.cog', 'one.out')

+

        self.assertFilesSame('subdir/subback.cog', 'subback.out')

+

        self.assertFilesSame('subdir/subfwd.cog', 'subfwd.out')

+

 

+

 

+

class CogTestLineEndings(TestCaseWithTempDir):

+

    """Tests for -U option (force LF line-endings in output)."""

+

 

+

    lines_in = ['Some text.',

+

                '//[[[cog',

+

                'cog.outl("Cog text")',

+

                '//]]]',

+

                'gobbledegook.',

+

                '//[[[end]]]',

+

                'epilogue.',

+

                '']

+

 

+

    lines_out = ['Some text.',

+

                 '//[[[cog',

+

                 'cog.outl("Cog text")',

+

                 '//]]]',

+

                 'Cog text',

+

                 '//[[[end]]]',

+

                 'epilogue.',

+

                 '']

+

 

+

    def testOutputNativeEol(self):

+

        makeFiles({'infile': '\n'.join(self.lines_in)})

+

        self.cog.callableMain(['argv0', '-o', 'outfile', 'infile'])

+

        self.assertFileContent('outfile', os.linesep.join(self.lines_out))

+

 

+

    def testOutputLfEol(self):

+

        makeFiles({'infile': '\n'.join(self.lines_in)})

+

        self.cog.callableMain(['argv0', '-U', '-o', 'outfile', 'infile'])

+

        self.assertFileContent('outfile', '\n'.join(self.lines_out))

+

 

+

    def testReplaceNativeEol(self):

+

        makeFiles({'test.cog': '\n'.join(self.lines_in)})

+

        self.cog.callableMain(['argv0', '-r', 'test.cog'])

+

        self.assertFileContent('test.cog', os.linesep.join(self.lines_out))

+

 

+

    def testReplaceLfEol(self):

+

        makeFiles({'test.cog': '\n'.join(self.lines_in)})

+

        self.cog.callableMain(['argv0', '-U', '-r', 'test.cog'])

+

        self.assertFileContent('test.cog', '\n'.join(self.lines_out))

+

 

+

 

+

class TestCaseWithImports(TestCaseWithTempDir):

+

    """ When running tests which import modules, the sys.modules list

+

        leaks from one test to the next.  This test case class scrubs

+

        the list after each run to keep the tests isolated from each other.

+

    """

+

 

+

    def setUp(self):

+

        TestCaseWithTempDir.setUp(self)

+

        self.sysmodulekeys = list(sys.modules)

+

 

+

    def tearDown(self):

+

        modstoscrub = [

+

            modname

+

            for modname in sys.modules

+

            if modname not in self.sysmodulekeys

+

            ]

+

        for modname in modstoscrub:

+

            del sys.modules[modname]

+

        TestCaseWithTempDir.tearDown(self)

+

 

+

 

+

class CogIncludeTests(TestCaseWithImports):

+

    dincludes = {

+

        'test.cog': """\

+

            //[[[cog

+

                import mymodule

+

            //]]]

+

            //[[[end]]]

+

            """,

+

 

+

        'test.out': """\

+

            //[[[cog

+

                import mymodule

+

            //]]]

+

            Hello from mymodule

+

            //[[[end]]]

+

            """,

+

 

+

        'test2.out': """\

+

            //[[[cog

+

                import mymodule

+

            //]]]

+

            Hello from mymodule in inc2

+

            //[[[end]]]

+

            """,

+

 

+

        'include': {

+

            'mymodule.py': """\

+

                import cog

+

                cog.outl("Hello from mymodule")

+

                """

+

            },

+

 

+

        'inc2': {

+

            'mymodule.py': """\

+

                import cog

+

                cog.outl("Hello from mymodule in inc2")

+

                """

+

            },

+

 

+

        'inc3': {

+

            'someothermodule.py': """\

+

                import cog

+

                cog.outl("This is some other module.")

+

                """

+

            },

+

        }

+

 

+

    def testNeedIncludePath(self):

+

        # Try it without the -I, to see that an ImportError happens.

+

        makeFiles(self.dincludes)

+

        self.assertRaises(ImportError, self.cog.callableMain, (['argv0', '-r', 'test.cog']))

+

 

+

    def testIncludePath(self):

+

        # Test that -I adds include directories properly.

+

        makeFiles(self.dincludes)

+

        self.cog.callableMain(['argv0', '-r', '-I', 'include', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.out')

+

 

+

    def testTwoIncludePaths(self):

+

        # Test that two -I's add include directories properly.

+

        makeFiles(self.dincludes)

+

        self.cog.callableMain(['argv0', '-r', '-I', 'include', '-I', 'inc2', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.out')

+

 

+

    def testTwoIncludePaths2(self):

+

        # Test that two -I's add include directories properly.

+

        makeFiles(self.dincludes)

+

        self.cog.callableMain(['argv0', '-r', '-I', 'inc2', '-I', 'include', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test2.out')

+

 

+

    def testUselessIncludePath(self):

+

        # Test that the search will continue past the first directory.

+

        makeFiles(self.dincludes)

+

        self.cog.callableMain(['argv0', '-r', '-I', 'inc3', '-I', 'include', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.out')

+

 

+

    def testSysPathIsUnchanged(self):

+

        d = {

+

            'bad.cog': """\

+

                //[[[cog cog.error("Oh no!") ]]]

+

                //[[[end]]]

+

                """,

+

            'good.cog': """\

+

                //[[[cog cog.outl("Oh yes!") ]]]

+

                //[[[end]]]

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        # Is it unchanged just by creating a cog engine?

+

        oldsyspath = sys.path[:]

+

        self.newCog()

+

        self.assertEqual(oldsyspath, sys.path)

+

        # Is it unchanged for a successful run?

+

        self.newCog()

+

        self.cog.callableMain(['argv0', '-r', 'good.cog'])

+

        self.assertEqual(oldsyspath, sys.path)

+

        # Is it unchanged for a successful run with includes?

+

        self.newCog()

+

        self.cog.callableMain(['argv0', '-r', '-I', 'xyzzy', 'good.cog'])

+

        self.assertEqual(oldsyspath, sys.path)

+

        # Is it unchanged for a successful run with two includes?

+

        self.newCog()

+

        self.cog.callableMain(['argv0', '-r', '-I', 'xyzzy', '-I', 'quux', 'good.cog'])

+

        self.assertEqual(oldsyspath, sys.path)

+

        # Is it unchanged for a failed run?

+

        self.newCog()

+

        self.assertRaises(CogError, self.cog.callableMain, (['argv0', '-r', 'bad.cog']))

+

        self.assertEqual(oldsyspath, sys.path)

+

        # Is it unchanged for a failed run with includes?

+

        self.newCog()

+

        self.assertRaises(CogError, self.cog.callableMain, (['argv0', '-r', '-I', 'xyzzy', 'bad.cog']))

+

        self.assertEqual(oldsyspath, sys.path)

+

        # Is it unchanged for a failed run with two includes?

+

        self.newCog()

+

        self.assertRaises(CogError, self.cog.callableMain, (['argv0', '-r', '-I', 'xyzzy', '-I', 'quux', 'bad.cog']))

+

        self.assertEqual(oldsyspath, sys.path)

+

 

+

    def testSubDirectories(self):

+

        # Test that relative paths on the command line work, with includes.

+

 

+

        d = {

+

            'code': {

+

                'test.cog': """\

+

                    //[[[cog

+

                        import mysubmodule

+

                    //]]]

+

                    //[[[end]]]

+

                    """,

+

 

+

                'test.out': """\

+

                    //[[[cog

+

                        import mysubmodule

+

                    //]]]

+

                    Hello from mysubmodule

+

                    //[[[end]]]

+

                    """,

+

 

+

                'mysubmodule.py': """\

+

                    import cog

+

                    cog.outl("Hello from mysubmodule")

+

                    """

+

                }

+

            }

+

 

+

        makeFiles(d)

+

        # We should be able to invoke cog without the -I switch, and it will

+

        # auto-include the current directory

+

        self.cog.callableMain(['argv0', '-r', 'code/test.cog'])

+

        self.assertFilesSame('code/test.cog', 'code/test.out')

+

 

+

 

+

class CogTestsInFiles(TestCaseWithTempDir):

+

 

+

    def testWarnIfNoCogCode(self):

+

        # Test that the -e switch warns if there is no Cog code.

+

        d = {

+

            'with.cog': """\

+

                //[[[cog

+

                cog.outl("hello world")

+

                //]]]

+

                hello world

+

                //[[[end]]]

+

                """,

+

 

+

            'without.cog': """\

+

                There's no cog

+

                code in this file.

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-e', 'with.cog'])

+

        output = self.output.getvalue()

+

        assert(output.find("Warning") < 0)

+

        self.newCog()

+

        self.cog.callableMain(['argv0', '-e', 'without.cog'])

+

        output = self.output.getvalue()

+

        assert(output.find("Warning: no cog code found in without.cog") >= 0)

+

        self.newCog()

+

        self.cog.callableMain(['argv0', 'without.cog'])

+

        output = self.output.getvalue()

+

        assert(output.find("Warning") < 0)

+

 

+

    def testFileNameProps(self):

+

        d = {

+

            'cog1.txt': """\

+

                //[[[cog

+

                cog.outl("This is %s in, %s out" % (cog.inFile, cog.outFile))

+

                //]]]

+

                this is cog1.txt in, cog1.txt out

+

                [[[end]]]

+

                """,

+

 

+

            'cog1.out': """\

+

                //[[[cog

+

                cog.outl("This is %s in, %s out" % (cog.inFile, cog.outFile))

+

                //]]]

+

                This is cog1.txt in, cog1.txt out

+

                [[[end]]]

+

                """,

+

 

+

            'cog1out.out': """\

+

                //[[[cog

+

                cog.outl("This is %s in, %s out" % (cog.inFile, cog.outFile))

+

                //]]]

+

                This is cog1.txt in, cog1out.txt out

+

                [[[end]]]

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', 'cog1.txt'])

+

        self.assertFilesSame('cog1.txt', 'cog1.out')

+

        self.newCog()

+

        self.cog.callableMain(['argv0', '-o', 'cog1out.txt', 'cog1.txt'])

+

        self.assertFilesSame('cog1out.txt', 'cog1out.out')

+

 

+

    def testGlobalsDontCrossFiles(self):

+

        # Make sure that global values don't get shared between files.

+

        d = {

+

            'one.cog': """\

+

                //[[[cog s = "This was set in one.cog" ]]]

+

                //[[[end]]]

+

                //[[[cog cog.outl(s) ]]]

+

                //[[[end]]]

+

                """,

+

 

+

            'one.out': """\

+

                //[[[cog s = "This was set in one.cog" ]]]

+

                //[[[end]]]

+

                //[[[cog cog.outl(s) ]]]

+

                This was set in one.cog

+

                //[[[end]]]

+

                """,

+

 

+

            'two.cog': """\

+

                //[[[cog

+

                try:

+

                    cog.outl(s)

+

                except NameError:

+

                    cog.outl("s isn't set!")

+

                //]]]

+

                //[[[end]]]

+

                """,

+

 

+

            'two.out': """\

+

                //[[[cog

+

                try:

+

                    cog.outl(s)

+

                except NameError:

+

                    cog.outl("s isn't set!")

+

                //]]]

+

                s isn't set!

+

                //[[[end]]]

+

                """,

+

 

+

            'cogfiles.txt': """\

+

                # Please run cog

+

                one.cog

+

 

+

                two.cog

+

                """

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', '@cogfiles.txt'])

+

        self.assertFilesSame('one.cog', 'one.out')

+

        self.assertFilesSame('two.cog', 'two.out')

+

        output = self.output.getvalue()

+

        assert(output.find("(changed)") >= 0)

+

 

+

    def testRemoveGeneratedOutput(self):

+

        d = {

+

            'cog1.txt': """\

+

                //[[[cog

+

                cog.outl("This line was generated.")

+

                //]]]

+

                This line was generated.

+

                //[[[end]]]

+

                This line was not.

+

                """,

+

 

+

            'cog1.out': """\

+

                //[[[cog

+

                cog.outl("This line was generated.")

+

                //]]]

+

                //[[[end]]]

+

                This line was not.

+

                """,

+

 

+

            'cog1.out2': """\

+

                //[[[cog

+

                cog.outl("This line was generated.")

+

                //]]]

+

                This line was generated.

+

                //[[[end]]]

+

                This line was not.

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        # Remove generated output.

+

        self.cog.callableMain(['argv0', '-r', '-x', 'cog1.txt'])

+

        self.assertFilesSame('cog1.txt', 'cog1.out')

+

        self.newCog()

+

        # Regenerate the generated output.

+

        self.cog.callableMain(['argv0', '-r', 'cog1.txt'])

+

        self.assertFilesSame('cog1.txt', 'cog1.out2')

+

        self.newCog()

+

        # Remove the generated output again.

+

        self.cog.callableMain(['argv0', '-r', '-x', 'cog1.txt'])

+

        self.assertFilesSame('cog1.txt', 'cog1.out')

+

 

+

    def testMsgCall(self):

+

        infile = """\

+

            #[[[cog

+

                cog.msg("Hello there!")

+

            #]]]

+

            #[[[end]]]

+

            """

+

        infile = reindentBlock(infile)

+

        self.assertEqual(self.cog.processString(infile), infile)

+

        output = self.output.getvalue()

+

        self.assertEqual(output, "Message: Hello there!\n")

+

 

+

    def testErrorMessageHasNoTraceback(self):

+

        # Test that a Cog error is printed to stderr with no traceback.

+

 

+

        d = {

+

            'cog1.txt': """\

+

                //[[[cog

+

                cog.outl("This line was newly")

+

                cog.outl("generated by cog")

+

                cog.outl("blah blah.")

+

                //]]]

+

                Xhis line was newly

+

                generated by cog

+

                blah blah.

+

                //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346)

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        stderr = StringIO.StringIO()

+

        self.cog.setOutput(stderr=stderr)

+

        self.cog.main(['argv0', '-c', '-r', "cog1.txt"])

+

        output = self.output.getvalue()

+

        self.assertEqual(self.output.getvalue(), "Cogging cog1.txt\n")

+

        self.assertEqual(stderr.getvalue(), "cog1.txt(9): Output has been edited! Delete old checksum to unprotect.\n")

+

 

+

    def testDashD(self):

+

        d = {

+

            'test.cog': """\

+

                --[[[cog cog.outl("Defined fooey as " + fooey) ]]]

+

                --[[[end]]]

+

                """,

+

 

+

            'test.kablooey': """\

+

                --[[[cog cog.outl("Defined fooey as " + fooey) ]]]

+

                Defined fooey as kablooey

+

                --[[[end]]]

+

                """,

+

 

+

            'test.einstein': """\

+

                --[[[cog cog.outl("Defined fooey as " + fooey) ]]]

+

                Defined fooey as e=mc2

+

                --[[[end]]]

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', '-D', 'fooey=kablooey', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.kablooey')

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', '-Dfooey=kablooey', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.kablooey')

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', '-Dfooey=e=mc2', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.einstein')

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', '-Dbar=quux', '-Dfooey=kablooey', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.kablooey')

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', '-Dfooey=kablooey', '-Dbar=quux', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.kablooey')

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', '-Dfooey=gooey', '-Dfooey=kablooey', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.kablooey')

+

 

+

    def testOutputToStdout(self):

+

        d = {

+

            'test.cog': """\

+

                --[[[cog cog.outl('Hey there!') ]]]

+

                --[[[end]]]

+

                """

+

            }

+

 

+

        makeFiles(d)

+

        stderr = StringIO.StringIO()

+

        self.cog.setOutput(stderr=stderr)

+

        self.cog.callableMain(['argv0', 'test.cog'])

+

        output = self.output.getvalue()

+

        outerr = stderr.getvalue()

+

        self.assertEqual(output, "--[[[cog cog.outl('Hey there!') ]]]\nHey there!\n--[[[end]]]\n")

+

        self.assertEqual(outerr, "")

+

 

+

    def testSuffixOutputLines(self):

+

        d = {

+

            'test.cog': """\

+

                Hey there.

+

                ;[[[cog cog.outl('a\\nb\\n   \\nc') ]]]

+

                ;[[[end]]]

+

                Good bye.

+

                """,

+

 

+

            'test.out': """\

+

                Hey there.

+

                ;[[[cog cog.outl('a\\nb\\n   \\nc') ]]]

+

                a (foo)

+

                b (foo)

+

 

+

                c (foo)

+

                ;[[[end]]]

+

                Good bye.

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', '-s', ' (foo)', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.out')

+

 

+

    def testEmptySuffix(self):

+

        d = {

+

            'test.cog': """\

+

                ;[[[cog cog.outl('a\\nb\\nc') ]]]

+

                ;[[[end]]]

+

                """,

+

 

+

            'test.out': """\

+

                ;[[[cog cog.outl('a\\nb\\nc') ]]]

+

                a

+

                b

+

                c

+

                ;[[[end]]]

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', '-s', '', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.out')

+

 

+

    def testHellishSuffix(self):

+

        d = {

+

            'test.cog': """\

+

                ;[[[cog cog.outl('a\\n\\nb') ]]]

+

                """,

+

 

+

            'test.out': """\

+

                ;[[[cog cog.outl('a\\n\\nb') ]]]

+

                a /\\n*+([)]><

+

 

+

                b /\\n*+([)]><

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-z', '-r', '-s', r' /\n*+([)]><', 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.out')

+

 

+

class WritabilityTests(TestCaseWithTempDir):

+

 

+

    d = {

+

        'test.cog': """\

+

            //[[[cog

+

            for fn in ['DoSomething', 'DoAnotherThing', 'DoLastThing']:

+

                cog.outl("void %s();" % fn)

+

            //]]]

+

            //[[[end]]]

+

            """,

+

 

+

        'test.out': """\

+

            //[[[cog

+

            for fn in ['DoSomething', 'DoAnotherThing', 'DoLastThing']:

+

                cog.outl("void %s();" % fn)

+

            //]]]

+

            void DoSomething();

+

            void DoAnotherThing();

+

            void DoLastThing();

+

            //[[[end]]]

+

            """,

+

        }

+

 

+

    if os.name == 'nt':     # pragma: no cover

+

        # for Windows

+

        cmd_w_args = 'attrib -R %s'

+

        cmd_w_asterisk = 'attrib -R *'

+

    else:   # pragma: no cover

+

        # for unix-like

+

        cmd_w_args = 'chmod +w %s'

+

        cmd_w_asterisk = 'chmod +w *'

+

 

+

    def setUp(self):

+

        TestCaseWithTempDir.setUp(self)

+

        makeFiles(self.d)

+

        self.testcog = self.tempdir / 'test.cog'

+

        self.testcog.chmod(stat.S_IREAD)   # Make the file readonly.

+

        assert not os.access(self.testcog, os.W_OK)

+

 

+

    def tearDown(self):

+

        self.testcog.chmod(stat.S_IWRITE)   # Make the file writable again.

+

        TestCaseWithTempDir.tearDown(self)

+

 

+

    def testReadonlyNoCommand(self):

+

        self.assertRaisesMsg(

+

            CogError, "Can't overwrite test.cog",

+

            self.cog.callableMain, (['argv0', '-r', 'test.cog']))

+

        assert not os.access(self.testcog, os.W_OK)

+

 

+

    def testReadonlyWithCommand(self):

+

        self.cog.callableMain(['argv0', '-r', '-w', self.cmd_w_args, 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.out')

+

        assert os.access(self.testcog, os.W_OK)

+

 

+

    def testReadonlyWithCommandWithNoSlot(self):

+

        self.cog.callableMain(['argv0', '-r', '-w', self.cmd_w_asterisk, 'test.cog'])

+

        self.assertFilesSame('test.cog', 'test.out')

+

        assert os.access(self.testcog, os.W_OK)

+

 

+

    def testReadonlyWithIneffectualCommand(self):

+

        self.assertRaisesMsg(

+

            CogError, "Couldn't make test.cog writable",

+

            self.cog.callableMain, (['argv0', '-r', '-w', 'echo %s', 'test.cog']))

+

        assert not os.access(self.testcog, os.W_OK)

+

 

+

class ChecksumTests(TestCaseWithTempDir):

+

 

+

    def testCreateChecksumOutput(self):

+

        d = {

+

            'cog1.txt': """\

+

                //[[[cog

+

                cog.outl("This line was generated.")

+

                //]]]

+

                This line was generated.

+

                //[[[end]]]

+

                This line was not.

+

                """,

+

 

+

            'cog1.out': """\

+

                //[[[cog

+

                cog.outl("This line was generated.")

+

                //]]]

+

                This line was generated.

+

                //[[[end]]] (checksum: 8adb13fb59b996a1c7f0065ea9f3d893)

+

                This line was not.

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', '-c', 'cog1.txt'])

+

        self.assertFilesSame('cog1.txt', 'cog1.out')

+

 

+

    def testCheckChecksumOutput(self):

+

        d = {

+

            'cog1.txt': """\

+

                //[[[cog

+

                cog.outl("This line was newly")

+

                cog.outl("generated by cog")

+

                cog.outl("blah blah.")

+

                //]]]

+

                This line was generated.

+

                //[[[end]]] (checksum: 8adb13fb59b996a1c7f0065ea9f3d893)

+

                """,

+

 

+

            'cog1.out': """\

+

                //[[[cog

+

                cog.outl("This line was newly")

+

                cog.outl("generated by cog")

+

                cog.outl("blah blah.")

+

                //]]]

+

                This line was newly

+

                generated by cog

+

                blah blah.

+

                //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346)

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', '-c', 'cog1.txt'])

+

        self.assertFilesSame('cog1.txt', 'cog1.out')

+

 

+

    def testRemoveChecksumOutput(self):

+

        d = {

+

            'cog1.txt': """\

+

                //[[[cog

+

                cog.outl("This line was newly")

+

                cog.outl("generated by cog")

+

                cog.outl("blah blah.")

+

                //]]]

+

                This line was generated.

+

                //[[[end]]] (checksum: 8adb13fb59b996a1c7f0065ea9f3d893) fooey

+

                """,

+

 

+

            'cog1.out': """\

+

                //[[[cog

+

                cog.outl("This line was newly")

+

                cog.outl("generated by cog")

+

                cog.outl("blah blah.")

+

                //]]]

+

                This line was newly

+

                generated by cog

+

                blah blah.

+

                //[[[end]]] fooey

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-r', 'cog1.txt'])

+

        self.assertFilesSame('cog1.txt', 'cog1.out')

+

 

+

    def testTamperedChecksumOutput(self):

+

        d = {

+

            'cog1.txt': """\

+

                //[[[cog

+

                cog.outl("This line was newly")

+

                cog.outl("generated by cog")

+

                cog.outl("blah blah.")

+

                //]]]

+

                Xhis line was newly

+

                generated by cog

+

                blah blah.

+

                //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346)

+

                """,

+

 

+

            'cog2.txt': """\

+

                //[[[cog

+

                cog.outl("This line was newly")

+

                cog.outl("generated by cog")

+

                cog.outl("blah blah.")

+

                //]]]

+

                This line was newly

+

                generated by cog

+

                blah blah!

+

                //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346)

+

                """,

+

 

+

            'cog3.txt': """\

+

                //[[[cog

+

                cog.outl("This line was newly")

+

                cog.outl("generated by cog")

+

                cog.outl("blah blah.")

+

                //]]]

+

 

+

                This line was newly

+

                generated by cog

+

                blah blah.

+

                //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346)

+

                """,

+

 

+

            'cog4.txt': """\

+

                //[[[cog

+

                cog.outl("This line was newly")

+

                cog.outl("generated by cog")

+

                cog.outl("blah blah.")

+

                //]]]

+

                This line was newly

+

                generated by cog

+

                blah blah..

+

                //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346)

+

                """,

+

 

+

            'cog5.txt': """\

+

                //[[[cog

+

                cog.outl("This line was newly")

+

                cog.outl("generated by cog")

+

                cog.outl("blah blah.")

+

                //]]]

+

                This line was newly

+

                generated by cog

+

                blah blah.

+

                extra

+

                //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346)

+

                """,

+

 

+

            'cog6.txt': """\

+

                //[[[cog

+

                cog.outl("This line was newly")

+

                cog.outl("generated by cog")

+

                cog.outl("blah blah.")

+

                //]]]

+

                //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346)

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.assertRaisesMsg(CogError,

+

            "cog1.txt(9): Output has been edited! Delete old checksum to unprotect.",

+

            self.cog.callableMain, (['argv0', '-c', "cog1.txt"]))

+

        self.assertRaisesMsg(CogError,

+

            "cog2.txt(9): Output has been edited! Delete old checksum to unprotect.",

+

            self.cog.callableMain, (['argv0', '-c', "cog2.txt"]))

+

        self.assertRaisesMsg(CogError,

+

            "cog3.txt(10): Output has been edited! Delete old checksum to unprotect.",

+

            self.cog.callableMain, (['argv0', '-c', "cog3.txt"]))

+

        self.assertRaisesMsg(CogError,

+

            "cog4.txt(9): Output has been edited! Delete old checksum to unprotect.",

+

            self.cog.callableMain, (['argv0', '-c', "cog4.txt"]))

+

        self.assertRaisesMsg(CogError,

+

            "cog5.txt(10): Output has been edited! Delete old checksum to unprotect.",

+

            self.cog.callableMain, (['argv0', '-c', "cog5.txt"]))

+

        self.assertRaisesMsg(CogError,

+

            "cog6.txt(6): Output has been edited! Delete old checksum to unprotect.",

+

            self.cog.callableMain, (['argv0', '-c', "cog6.txt"]))

+

 

+

class BlakeTests(TestCaseWithTempDir):

+

 

+

    # Blake Winton's contributions.

+

    def testDeleteCode(self):

+

        # -o sets the output file.

+

        d = {

+

            'test.cog': """\

+

                // This is my C++ file.

+

                //[[[cog

+

                fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing']

+

                for fn in fnames:

+

                    cog.outl("void %s();" % fn)

+

                //]]]

+

                Some Sample Code Here

+

                //[[[end]]]Data Data

+

                And Some More

+

                """,

+

 

+

            'test.out': """\

+

                // This is my C++ file.

+

                void DoSomething();

+

                void DoAnotherThing();

+

                void DoLastThing();

+

                And Some More

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.callableMain(['argv0', '-d', '-o', 'test.cogged', 'test.cog'])

+

        self.assertFilesSame('test.cogged', 'test.out')

+

 

+

    def testDeleteCodeWithDashRFails(self):

+

        d = {

+

            'test.cog': """\

+

                // This is my C++ file.

+

                """

+

            }

+

 

+

        makeFiles(d)

+

        self.assertRaises(CogUsageError, self.cog.callableMain, (['argv0', '-r', '-d', 'test.cog']))

+

 

+

    def testSettingGlobals(self):

+

        # Blake Winton contributed a way to set the globals that will be used in

+

        # processFile().

+

        d = {

+

            'test.cog': """\

+

                // This is my C++ file.

+

                //[[[cog

+

                for fn in fnames:

+

                    cog.outl("void %s();" % fn)

+

                //]]]

+

                Some Sample Code Here

+

                //[[[end]]]""",

+

 

+

            'test.out': """\

+

                // This is my C++ file.

+

                void DoBlake();

+

                void DoWinton();

+

                void DoContribution();

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        globals = {}

+

        globals['fnames'] = ['DoBlake', 'DoWinton', 'DoContribution']

+

        self.cog.options.bDeleteCode = True

+

        self.cog.processFile('test.cog', 'test.cogged', globals=globals)

+

        self.assertFilesSame('test.cogged', 'test.out')

+

 

+

class ErrorCallTests(TestCaseWithTempDir):

+

 

+

    def testErrorCallHasNoTraceback(self):

+

        # Test that cog.error() doesn't show a traceback.

+

        d = {

+

            'error.cog': """\

+

                //[[[cog

+

                cog.error("Something Bad!")

+

                //]]]

+

                //[[[end]]]

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.main(['argv0', '-r', 'error.cog'])

+

        output = self.output.getvalue()

+

        self.assertEqual(output, "Cogging error.cog\nError: Something Bad!\n")

+

 

+

    def testRealErrorHasTraceback(self):

+

        # Test that a genuine error does show a traceback.

+

        d = {

+

            'error.cog': """\

+

                //[[[cog

+

                raise RuntimeError("Hey!")

+

                //]]]

+

                //[[[end]]]

+

                """,

+

            }

+

 

+

        makeFiles(d)

+

        self.cog.main(['argv0', '-r', 'error.cog'])

+

        output = self.output.getvalue()

+

        msg = 'Actual output:\n' + output

+

        self.assert_(output.startswith("Cogging error.cog\nTraceback (most recent"), msg)

+

        self.assert_(output.find("RuntimeError: Hey!") > 0, msg)

+

 

+

 

+

if __name__ == '__main__':      #pragma: no cover

+

    unittest.main()

+

 

+

# Things not yet tested:

+

# - A bad -w command (currently fails silently).

+ +
+
+ + + diff --git a/doc/sample_html/cogapp_whiteutils.html b/doc/sample_html/cogapp_whiteutils.html new file mode 100644 index 00000000..e5f84356 --- /dev/null +++ b/doc/sample_html/cogapp_whiteutils.html @@ -0,0 +1,176 @@ + + + +Coverage for cogapp\whiteutils + + + + + + + +
+ + + + + +
+

1

+

2

+

3

+

4

+

5

+

6

+

7

+

8

+

9

+

10

+

11

+

12

+

13

+

14

+

15

+

16

+

17

+

18

+

19

+

20

+

21

+

22

+

23

+

24

+

25

+

26

+

27

+

28

+

29

+

30

+

31

+

32

+

33

+

34

+

35

+

36

+

37

+

38

+

39

+

40

+

41

+

42

+

43

+

44

+

45

+

46

+

47

+

48

+

49

+

50

+

51

+

52

+

53

+

54

+

55

+

56

+

57

+

58

+

59

+

60

+

61

+

62

+

63

+ +
+

""" Indentation utilities for Cog.

+

    http://nedbatchelder.com/code/cog

+

 

+

    Copyright 2004-2009, Ned Batchelder.

+

"""

+

 

+

import re

+

 

+

def whitePrefix(strings):

+

    """ Determine the whitespace prefix common to all non-blank lines

+

        in the argument list.

+

    """

+

    # Remove all blank lines from the list

+

    strings = [s for s in strings if s.strip() != '']

+

 

+

    if not strings: return ''

+

 

+

    # Find initial whitespace chunk in the first line.

+

    # This is the best prefix we can hope for.

+

    prefix = re.match(r'\s*', strings[0]).group(0)

+

 

+

    # Loop over the other strings, keeping only as much of

+

    # the prefix as matches each string.

+

    for s in strings:

+

        for i in range(len(prefix)):

+

            if prefix[i] != s[i]:

+

                prefix = prefix[:i]

+

                break

+

    return prefix

+

 

+

def reindentBlock(lines, newIndent=''):

+

    """ Take a block of text as a string or list of lines.

+

        Remove any common whitespace indentation.

+

        Re-indent using newIndent, and return it as a single string.

+

    """

+

    if isinstance(lines, basestring):

+

        lines = lines.split('\n')

+

    oldIndent = whitePrefix(lines)

+

    outLines = []

+

    for l in lines:

+

        if oldIndent:

+

            l = l.replace(oldIndent, '', 1)

+

        if l and newIndent:

+

            l = newIndent + l

+

        outLines.append(l)

+

    return '\n'.join(outLines)

+

 

+

def commonPrefix(strings):

+

    """ Find the longest string that is a prefix of all the strings.

+

    """

+

    if not strings:

+

        return ''

+

    prefix = strings[0]

+

    for s in strings:

+

        if len(s) < len(prefix):

+

            prefix = prefix[:len(s)]

+

        if not prefix:

+

            return ''

+

        for i in range(len(prefix)):

+

            if prefix[i] != s[i]:

+

                prefix = prefix[:i]

+

                break

+

    return prefix

+ +
+
+ + + diff --git a/doc/sample_html/index.html b/doc/sample_html/index.html new file mode 100644 index 00000000..f49a9c7c --- /dev/null +++ b/doc/sample_html/index.html @@ -0,0 +1,78 @@ + + + +Coverage report + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Modulestatementsrunexcludedcoverage
cogapp\cogapp387219357%
cogapp\makefiles296321%
cogapp\test_cogapp5871951733%
cogapp\whiteutils3734092%
Total10404542344%
+
+ + + + + diff --git a/doc/sample_html/jquery-1.3.2.min.js b/doc/sample_html/jquery-1.3.2.min.js new file mode 100644 index 00000000..b1ae21d8 --- /dev/null +++ b/doc/sample_html/jquery-1.3.2.min.js @@ -0,0 +1,19 @@ +/* + * jQuery JavaScript Library v1.3.2 + * http://jquery.com/ + * + * Copyright (c) 2009 John Resig + * Dual licensed under the MIT and GPL licenses. + * http://docs.jquery.com/License + * + * Date: 2009-02-19 17:34:21 -0500 (Thu, 19 Feb 2009) + * Revision: 6246 + */ +(function(){var l=this,g,y=l.jQuery,p=l.$,o=l.jQuery=l.$=function(E,F){return new o.fn.init(E,F)},D=/^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,f=/^.[^:#\[\.,]*$/;o.fn=o.prototype={init:function(E,H){E=E||document;if(E.nodeType){this[0]=E;this.length=1;this.context=E;return this}if(typeof E==="string"){var G=D.exec(E);if(G&&(G[1]||!H)){if(G[1]){E=o.clean([G[1]],H)}else{var I=document.getElementById(G[3]);if(I&&I.id!=G[3]){return o().find(E)}var F=o(I||[]);F.context=document;F.selector=E;return F}}else{return o(H).find(E)}}else{if(o.isFunction(E)){return o(document).ready(E)}}if(E.selector&&E.context){this.selector=E.selector;this.context=E.context}return this.setArray(o.isArray(E)?E:o.makeArray(E))},selector:"",jquery:"1.3.2",size:function(){return this.length},get:function(E){return E===g?Array.prototype.slice.call(this):this[E]},pushStack:function(F,H,E){var G=o(F);G.prevObject=this;G.context=this.context;if(H==="find"){G.selector=this.selector+(this.selector?" ":"")+E}else{if(H){G.selector=this.selector+"."+H+"("+E+")"}}return G},setArray:function(E){this.length=0;Array.prototype.push.apply(this,E);return this},each:function(F,E){return o.each(this,F,E)},index:function(E){return o.inArray(E&&E.jquery?E[0]:E,this)},attr:function(F,H,G){var E=F;if(typeof F==="string"){if(H===g){return this[0]&&o[G||"attr"](this[0],F)}else{E={};E[F]=H}}return this.each(function(I){for(F in E){o.attr(G?this.style:this,F,o.prop(this,E[F],G,I,F))}})},css:function(E,F){if((E=="width"||E=="height")&&parseFloat(F)<0){F=g}return this.attr(E,F,"curCSS")},text:function(F){if(typeof F!=="object"&&F!=null){return this.empty().append((this[0]&&this[0].ownerDocument||document).createTextNode(F))}var E="";o.each(F||this,function(){o.each(this.childNodes,function(){if(this.nodeType!=8){E+=this.nodeType!=1?this.nodeValue:o.fn.text([this])}})});return E},wrapAll:function(E){if(this[0]){var F=o(E,this[0].ownerDocument).clone();if(this[0].parentNode){F.insertBefore(this[0])}F.map(function(){var G=this;while(G.firstChild){G=G.firstChild}return G}).append(this)}return this},wrapInner:function(E){return this.each(function(){o(this).contents().wrapAll(E)})},wrap:function(E){return this.each(function(){o(this).wrapAll(E)})},append:function(){return this.domManip(arguments,true,function(E){if(this.nodeType==1){this.appendChild(E)}})},prepend:function(){return this.domManip(arguments,true,function(E){if(this.nodeType==1){this.insertBefore(E,this.firstChild)}})},before:function(){return this.domManip(arguments,false,function(E){this.parentNode.insertBefore(E,this)})},after:function(){return this.domManip(arguments,false,function(E){this.parentNode.insertBefore(E,this.nextSibling)})},end:function(){return this.prevObject||o([])},push:[].push,sort:[].sort,splice:[].splice,find:function(E){if(this.length===1){var F=this.pushStack([],"find",E);F.length=0;o.find(E,this[0],F);return F}else{return this.pushStack(o.unique(o.map(this,function(G){return o.find(E,G)})),"find",E)}},clone:function(G){var E=this.map(function(){if(!o.support.noCloneEvent&&!o.isXMLDoc(this)){var I=this.outerHTML;if(!I){var J=this.ownerDocument.createElement("div");J.appendChild(this.cloneNode(true));I=J.innerHTML}return o.clean([I.replace(/ jQuery\d+="(?:\d+|null)"/g,"").replace(/^\s*/,"")])[0]}else{return this.cloneNode(true)}});if(G===true){var H=this.find("*").andSelf(),F=0;E.find("*").andSelf().each(function(){if(this.nodeName!==H[F].nodeName){return}var I=o.data(H[F],"events");for(var K in I){for(var J in I[K]){o.event.add(this,K,I[K][J],I[K][J].data)}}F++})}return E},filter:function(E){return this.pushStack(o.isFunction(E)&&o.grep(this,function(G,F){return E.call(G,F)})||o.multiFilter(E,o.grep(this,function(F){return F.nodeType===1})),"filter",E)},closest:function(E){var G=o.expr.match.POS.test(E)?o(E):null,F=0;return this.map(function(){var H=this;while(H&&H.ownerDocument){if(G?G.index(H)>-1:o(H).is(E)){o.data(H,"closest",F);return H}H=H.parentNode;F++}})},not:function(E){if(typeof E==="string"){if(f.test(E)){return this.pushStack(o.multiFilter(E,this,true),"not",E)}else{E=o.multiFilter(E,this)}}var F=E.length&&E[E.length-1]!==g&&!E.nodeType;return this.filter(function(){return F?o.inArray(this,E)<0:this!=E})},add:function(E){return this.pushStack(o.unique(o.merge(this.get(),typeof E==="string"?o(E):o.makeArray(E))))},is:function(E){return !!E&&o.multiFilter(E,this).length>0},hasClass:function(E){return !!E&&this.is("."+E)},val:function(K){if(K===g){var E=this[0];if(E){if(o.nodeName(E,"option")){return(E.attributes.value||{}).specified?E.value:E.text}if(o.nodeName(E,"select")){var I=E.selectedIndex,L=[],M=E.options,H=E.type=="select-one";if(I<0){return null}for(var F=H?I:0,J=H?I+1:M.length;F=0||o.inArray(this.name,K)>=0)}else{if(o.nodeName(this,"select")){var N=o.makeArray(K);o("option",this).each(function(){this.selected=(o.inArray(this.value,N)>=0||o.inArray(this.text,N)>=0)});if(!N.length){this.selectedIndex=-1}}else{this.value=K}}})},html:function(E){return E===g?(this[0]?this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g,""):null):this.empty().append(E)},replaceWith:function(E){return this.after(E).remove()},eq:function(E){return this.slice(E,+E+1)},slice:function(){return this.pushStack(Array.prototype.slice.apply(this,arguments),"slice",Array.prototype.slice.call(arguments).join(","))},map:function(E){return this.pushStack(o.map(this,function(G,F){return E.call(G,F,G)}))},andSelf:function(){return this.add(this.prevObject)},domManip:function(J,M,L){if(this[0]){var I=(this[0].ownerDocument||this[0]).createDocumentFragment(),F=o.clean(J,(this[0].ownerDocument||this[0]),I),H=I.firstChild;if(H){for(var G=0,E=this.length;G1||G>0?I.cloneNode(true):I)}}if(F){o.each(F,z)}}return this;function K(N,O){return M&&o.nodeName(N,"table")&&o.nodeName(O,"tr")?(N.getElementsByTagName("tbody")[0]||N.appendChild(N.ownerDocument.createElement("tbody"))):N}}};o.fn.init.prototype=o.fn;function z(E,F){if(F.src){o.ajax({url:F.src,async:false,dataType:"script"})}else{o.globalEval(F.text||F.textContent||F.innerHTML||"")}if(F.parentNode){F.parentNode.removeChild(F)}}function e(){return +new Date}o.extend=o.fn.extend=function(){var J=arguments[0]||{},H=1,I=arguments.length,E=false,G;if(typeof J==="boolean"){E=J;J=arguments[1]||{};H=2}if(typeof J!=="object"&&!o.isFunction(J)){J={}}if(I==H){J=this;--H}for(;H-1}},swap:function(H,G,I){var E={};for(var F in G){E[F]=H.style[F];H.style[F]=G[F]}I.call(H);for(var F in G){H.style[F]=E[F]}},css:function(H,F,J,E){if(F=="width"||F=="height"){var L,G={position:"absolute",visibility:"hidden",display:"block"},K=F=="width"?["Left","Right"]:["Top","Bottom"];function I(){L=F=="width"?H.offsetWidth:H.offsetHeight;if(E==="border"){return}o.each(K,function(){if(!E){L-=parseFloat(o.curCSS(H,"padding"+this,true))||0}if(E==="margin"){L+=parseFloat(o.curCSS(H,"margin"+this,true))||0}else{L-=parseFloat(o.curCSS(H,"border"+this+"Width",true))||0}})}if(H.offsetWidth!==0){I()}else{o.swap(H,G,I)}return Math.max(0,Math.round(L))}return o.curCSS(H,F,J)},curCSS:function(I,F,G){var L,E=I.style;if(F=="opacity"&&!o.support.opacity){L=o.attr(E,"opacity");return L==""?"1":L}if(F.match(/float/i)){F=w}if(!G&&E&&E[F]){L=E[F]}else{if(q.getComputedStyle){if(F.match(/float/i)){F="float"}F=F.replace(/([A-Z])/g,"-$1").toLowerCase();var M=q.getComputedStyle(I,null);if(M){L=M.getPropertyValue(F)}if(F=="opacity"&&L==""){L="1"}}else{if(I.currentStyle){var J=F.replace(/\-(\w)/g,function(N,O){return O.toUpperCase()});L=I.currentStyle[F]||I.currentStyle[J];if(!/^\d+(px)?$/i.test(L)&&/^\d/.test(L)){var H=E.left,K=I.runtimeStyle.left;I.runtimeStyle.left=I.currentStyle.left;E.left=L||0;L=E.pixelLeft+"px";E.left=H;I.runtimeStyle.left=K}}}}return L},clean:function(F,K,I){K=K||document;if(typeof K.createElement==="undefined"){K=K.ownerDocument||K[0]&&K[0].ownerDocument||document}if(!I&&F.length===1&&typeof F[0]==="string"){var H=/^<(\w+)\s*\/?>$/.exec(F[0]);if(H){return[K.createElement(H[1])]}}var G=[],E=[],L=K.createElement("div");o.each(F,function(P,S){if(typeof S==="number"){S+=""}if(!S){return}if(typeof S==="string"){S=S.replace(/(<(\w+)[^>]*?)\/>/g,function(U,V,T){return T.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i)?U:V+">"});var O=S.replace(/^\s+/,"").substring(0,10).toLowerCase();var Q=!O.indexOf("",""]||!O.indexOf("",""]||O.match(/^<(thead|tbody|tfoot|colg|cap)/)&&[1,"","
"]||!O.indexOf("",""]||(!O.indexOf("",""]||!O.indexOf("",""]||!o.support.htmlSerialize&&[1,"div
","
"]||[0,"",""];L.innerHTML=Q[1]+S+Q[2];while(Q[0]--){L=L.lastChild}if(!o.support.tbody){var R=/"&&!R?L.childNodes:[];for(var M=N.length-1;M>=0;--M){if(o.nodeName(N[M],"tbody")&&!N[M].childNodes.length){N[M].parentNode.removeChild(N[M])}}}if(!o.support.leadingWhitespace&&/^\s/.test(S)){L.insertBefore(K.createTextNode(S.match(/^\s*/)[0]),L.firstChild)}S=o.makeArray(L.childNodes)}if(S.nodeType){G.push(S)}else{G=o.merge(G,S)}});if(I){for(var J=0;G[J];J++){if(o.nodeName(G[J],"script")&&(!G[J].type||G[J].type.toLowerCase()==="text/javascript")){E.push(G[J].parentNode?G[J].parentNode.removeChild(G[J]):G[J])}else{if(G[J].nodeType===1){G.splice.apply(G,[J+1,0].concat(o.makeArray(G[J].getElementsByTagName("script"))))}I.appendChild(G[J])}}return E}return G},attr:function(J,G,K){if(!J||J.nodeType==3||J.nodeType==8){return g}var H=!o.isXMLDoc(J),L=K!==g;G=H&&o.props[G]||G;if(J.tagName){var F=/href|src|style/.test(G);if(G=="selected"&&J.parentNode){J.parentNode.selectedIndex}if(G in J&&H&&!F){if(L){if(G=="type"&&o.nodeName(J,"input")&&J.parentNode){throw"type property can't be changed"}J[G]=K}if(o.nodeName(J,"form")&&J.getAttributeNode(G)){return J.getAttributeNode(G).nodeValue}if(G=="tabIndex"){var I=J.getAttributeNode("tabIndex");return I&&I.specified?I.value:J.nodeName.match(/(button|input|object|select|textarea)/i)?0:J.nodeName.match(/^(a|area)$/i)&&J.href?0:g}return J[G]}if(!o.support.style&&H&&G=="style"){return o.attr(J.style,"cssText",K)}if(L){J.setAttribute(G,""+K)}var E=!o.support.hrefNormalized&&H&&F?J.getAttribute(G,2):J.getAttribute(G);return E===null?g:E}if(!o.support.opacity&&G=="opacity"){if(L){J.zoom=1;J.filter=(J.filter||"").replace(/alpha\([^)]*\)/,"")+(parseInt(K)+""=="NaN"?"":"alpha(opacity="+K*100+")")}return J.filter&&J.filter.indexOf("opacity=")>=0?(parseFloat(J.filter.match(/opacity=([^)]*)/)[1])/100)+"":""}G=G.replace(/-([a-z])/ig,function(M,N){return N.toUpperCase()});if(L){J[G]=K}return J[G]},trim:function(E){return(E||"").replace(/^\s+|\s+$/g,"")},makeArray:function(G){var E=[];if(G!=null){var F=G.length;if(F==null||typeof G==="string"||o.isFunction(G)||G.setInterval){E[0]=G}else{while(F){E[--F]=G[F]}}}return E},inArray:function(G,H){for(var E=0,F=H.length;E0?this.clone(true):this).get();o.fn[F].apply(o(L[K]),I);J=J.concat(I)}return this.pushStack(J,E,G)}});o.each({removeAttr:function(E){o.attr(this,E,"");if(this.nodeType==1){this.removeAttribute(E)}},addClass:function(E){o.className.add(this,E)},removeClass:function(E){o.className.remove(this,E)},toggleClass:function(F,E){if(typeof E!=="boolean"){E=!o.className.has(this,F)}o.className[E?"add":"remove"](this,F)},remove:function(E){if(!E||o.filter(E,[this]).length){o("*",this).add([this]).each(function(){o.event.remove(this);o.removeData(this)});if(this.parentNode){this.parentNode.removeChild(this)}}},empty:function(){o(this).children().remove();while(this.firstChild){this.removeChild(this.firstChild)}}},function(E,F){o.fn[E]=function(){return this.each(F,arguments)}});function j(E,F){return E[0]&&parseInt(o.curCSS(E[0],F,true),10)||0}var h="jQuery"+e(),v=0,A={};o.extend({cache:{},data:function(F,E,G){F=F==l?A:F;var H=F[h];if(!H){H=F[h]=++v}if(E&&!o.cache[H]){o.cache[H]={}}if(G!==g){o.cache[H][E]=G}return E?o.cache[H][E]:H},removeData:function(F,E){F=F==l?A:F;var H=F[h];if(E){if(o.cache[H]){delete o.cache[H][E];E="";for(E in o.cache[H]){break}if(!E){o.removeData(F)}}}else{try{delete F[h]}catch(G){if(F.removeAttribute){F.removeAttribute(h)}}delete o.cache[H]}},queue:function(F,E,H){if(F){E=(E||"fx")+"queue";var G=o.data(F,E);if(!G||o.isArray(H)){G=o.data(F,E,o.makeArray(H))}else{if(H){G.push(H)}}}return G},dequeue:function(H,G){var E=o.queue(H,G),F=E.shift();if(!G||G==="fx"){F=E[0]}if(F!==g){F.call(H)}}});o.fn.extend({data:function(E,G){var H=E.split(".");H[1]=H[1]?"."+H[1]:"";if(G===g){var F=this.triggerHandler("getData"+H[1]+"!",[H[0]]);if(F===g&&this.length){F=o.data(this[0],E)}return F===g&&H[1]?this.data(H[0]):F}else{return this.trigger("setData"+H[1]+"!",[H[0],G]).each(function(){o.data(this,E,G)})}},removeData:function(E){return this.each(function(){o.removeData(this,E)})},queue:function(E,F){if(typeof E!=="string"){F=E;E="fx"}if(F===g){return o.queue(this[0],E)}return this.each(function(){var G=o.queue(this,E,F);if(E=="fx"&&G.length==1){G[0].call(this)}})},dequeue:function(E){return this.each(function(){o.dequeue(this,E)})}}); +/* + * Sizzle CSS Selector Engine - v0.9.3 + * Copyright 2009, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * More information: http://sizzlejs.com/ + */ +(function(){var R=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g,L=0,H=Object.prototype.toString;var F=function(Y,U,ab,ac){ab=ab||[];U=U||document;if(U.nodeType!==1&&U.nodeType!==9){return[]}if(!Y||typeof Y!=="string"){return ab}var Z=[],W,af,ai,T,ad,V,X=true;R.lastIndex=0;while((W=R.exec(Y))!==null){Z.push(W[1]);if(W[2]){V=RegExp.rightContext;break}}if(Z.length>1&&M.exec(Y)){if(Z.length===2&&I.relative[Z[0]]){af=J(Z[0]+Z[1],U)}else{af=I.relative[Z[0]]?[U]:F(Z.shift(),U);while(Z.length){Y=Z.shift();if(I.relative[Y]){Y+=Z.shift()}af=J(Y,af)}}}else{var ae=ac?{expr:Z.pop(),set:E(ac)}:F.find(Z.pop(),Z.length===1&&U.parentNode?U.parentNode:U,Q(U));af=F.filter(ae.expr,ae.set);if(Z.length>0){ai=E(af)}else{X=false}while(Z.length){var ah=Z.pop(),ag=ah;if(!I.relative[ah]){ah=""}else{ag=Z.pop()}if(ag==null){ag=U}I.relative[ah](ai,ag,Q(U))}}if(!ai){ai=af}if(!ai){throw"Syntax error, unrecognized expression: "+(ah||Y)}if(H.call(ai)==="[object Array]"){if(!X){ab.push.apply(ab,ai)}else{if(U.nodeType===1){for(var aa=0;ai[aa]!=null;aa++){if(ai[aa]&&(ai[aa]===true||ai[aa].nodeType===1&&K(U,ai[aa]))){ab.push(af[aa])}}}else{for(var aa=0;ai[aa]!=null;aa++){if(ai[aa]&&ai[aa].nodeType===1){ab.push(af[aa])}}}}}else{E(ai,ab)}if(V){F(V,U,ab,ac);if(G){hasDuplicate=false;ab.sort(G);if(hasDuplicate){for(var aa=1;aa":function(Z,U,aa){var X=typeof U==="string";if(X&&!/\W/.test(U)){U=aa?U:U.toUpperCase();for(var V=0,T=Z.length;V=0)){if(!V){T.push(Y)}}else{if(V){U[X]=false}}}}return false},ID:function(T){return T[1].replace(/\\/g,"")},TAG:function(U,T){for(var V=0;T[V]===false;V++){}return T[V]&&Q(T[V])?U[1]:U[1].toUpperCase()},CHILD:function(T){if(T[1]=="nth"){var U=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(T[2]=="even"&&"2n"||T[2]=="odd"&&"2n+1"||!/\D/.test(T[2])&&"0n+"+T[2]||T[2]);T[2]=(U[1]+(U[2]||1))-0;T[3]=U[3]-0}T[0]=L++;return T},ATTR:function(X,U,V,T,Y,Z){var W=X[1].replace(/\\/g,"");if(!Z&&I.attrMap[W]){X[1]=I.attrMap[W]}if(X[2]==="~="){X[4]=" "+X[4]+" "}return X},PSEUDO:function(X,U,V,T,Y){if(X[1]==="not"){if(X[3].match(R).length>1||/^\w/.test(X[3])){X[3]=F(X[3],null,null,U)}else{var W=F.filter(X[3],U,V,true^Y);if(!V){T.push.apply(T,W)}return false}}else{if(I.match.POS.test(X[0])||I.match.CHILD.test(X[0])){return true}}return X},POS:function(T){T.unshift(true);return T}},filters:{enabled:function(T){return T.disabled===false&&T.type!=="hidden"},disabled:function(T){return T.disabled===true},checked:function(T){return T.checked===true},selected:function(T){T.parentNode.selectedIndex;return T.selected===true},parent:function(T){return !!T.firstChild},empty:function(T){return !T.firstChild},has:function(V,U,T){return !!F(T[3],V).length},header:function(T){return/h\d/i.test(T.nodeName)},text:function(T){return"text"===T.type},radio:function(T){return"radio"===T.type},checkbox:function(T){return"checkbox"===T.type},file:function(T){return"file"===T.type},password:function(T){return"password"===T.type},submit:function(T){return"submit"===T.type},image:function(T){return"image"===T.type},reset:function(T){return"reset"===T.type},button:function(T){return"button"===T.type||T.nodeName.toUpperCase()==="BUTTON"},input:function(T){return/input|select|textarea|button/i.test(T.nodeName)}},setFilters:{first:function(U,T){return T===0},last:function(V,U,T,W){return U===W.length-1},even:function(U,T){return T%2===0},odd:function(U,T){return T%2===1},lt:function(V,U,T){return UT[3]-0},nth:function(V,U,T){return T[3]-0==U},eq:function(V,U,T){return T[3]-0==U}},filter:{PSEUDO:function(Z,V,W,aa){var U=V[1],X=I.filters[U];if(X){return X(Z,W,V,aa)}else{if(U==="contains"){return(Z.textContent||Z.innerText||"").indexOf(V[3])>=0}else{if(U==="not"){var Y=V[3];for(var W=0,T=Y.length;W=0)}}},ID:function(U,T){return U.nodeType===1&&U.getAttribute("id")===T},TAG:function(U,T){return(T==="*"&&U.nodeType===1)||U.nodeName===T},CLASS:function(U,T){return(" "+(U.className||U.getAttribute("class"))+" ").indexOf(T)>-1},ATTR:function(Y,W){var V=W[1],T=I.attrHandle[V]?I.attrHandle[V](Y):Y[V]!=null?Y[V]:Y.getAttribute(V),Z=T+"",X=W[2],U=W[4];return T==null?X==="!=":X==="="?Z===U:X==="*="?Z.indexOf(U)>=0:X==="~="?(" "+Z+" ").indexOf(U)>=0:!U?Z&&T!==false:X==="!="?Z!=U:X==="^="?Z.indexOf(U)===0:X==="$="?Z.substr(Z.length-U.length)===U:X==="|="?Z===U||Z.substr(0,U.length+1)===U+"-":false},POS:function(X,U,V,Y){var T=U[2],W=I.setFilters[T];if(W){return W(X,V,U,Y)}}}};var M=I.match.POS;for(var O in I.match){I.match[O]=RegExp(I.match[O].source+/(?![^\[]*\])(?![^\(]*\))/.source)}var E=function(U,T){U=Array.prototype.slice.call(U);if(T){T.push.apply(T,U);return T}return U};try{Array.prototype.slice.call(document.documentElement.childNodes)}catch(N){E=function(X,W){var U=W||[];if(H.call(X)==="[object Array]"){Array.prototype.push.apply(U,X)}else{if(typeof X.length==="number"){for(var V=0,T=X.length;V";var T=document.documentElement;T.insertBefore(U,T.firstChild);if(!!document.getElementById(V)){I.find.ID=function(X,Y,Z){if(typeof Y.getElementById!=="undefined"&&!Z){var W=Y.getElementById(X[1]);return W?W.id===X[1]||typeof W.getAttributeNode!=="undefined"&&W.getAttributeNode("id").nodeValue===X[1]?[W]:g:[]}};I.filter.ID=function(Y,W){var X=typeof Y.getAttributeNode!=="undefined"&&Y.getAttributeNode("id");return Y.nodeType===1&&X&&X.nodeValue===W}}T.removeChild(U)})();(function(){var T=document.createElement("div");T.appendChild(document.createComment(""));if(T.getElementsByTagName("*").length>0){I.find.TAG=function(U,Y){var X=Y.getElementsByTagName(U[1]);if(U[1]==="*"){var W=[];for(var V=0;X[V];V++){if(X[V].nodeType===1){W.push(X[V])}}X=W}return X}}T.innerHTML="";if(T.firstChild&&typeof T.firstChild.getAttribute!=="undefined"&&T.firstChild.getAttribute("href")!=="#"){I.attrHandle.href=function(U){return U.getAttribute("href",2)}}})();if(document.querySelectorAll){(function(){var T=F,U=document.createElement("div");U.innerHTML="

";if(U.querySelectorAll&&U.querySelectorAll(".TEST").length===0){return}F=function(Y,X,V,W){X=X||document;if(!W&&X.nodeType===9&&!Q(X)){try{return E(X.querySelectorAll(Y),V)}catch(Z){}}return T(Y,X,V,W)};F.find=T.find;F.filter=T.filter;F.selectors=T.selectors;F.matches=T.matches})()}if(document.getElementsByClassName&&document.documentElement.getElementsByClassName){(function(){var T=document.createElement("div");T.innerHTML="
";if(T.getElementsByClassName("e").length===0){return}T.lastChild.className="e";if(T.getElementsByClassName("e").length===1){return}I.order.splice(1,0,"CLASS");I.find.CLASS=function(U,V,W){if(typeof V.getElementsByClassName!=="undefined"&&!W){return V.getElementsByClassName(U[1])}}})()}function P(U,Z,Y,ad,aa,ac){var ab=U=="previousSibling"&&!ac;for(var W=0,V=ad.length;W0){X=T;break}}}T=T[U]}ad[W]=X}}}var K=document.compareDocumentPosition?function(U,T){return U.compareDocumentPosition(T)&16}:function(U,T){return U!==T&&(U.contains?U.contains(T):true)};var Q=function(T){return T.nodeType===9&&T.documentElement.nodeName!=="HTML"||!!T.ownerDocument&&Q(T.ownerDocument)};var J=function(T,aa){var W=[],X="",Y,V=aa.nodeType?[aa]:aa;while((Y=I.match.PSEUDO.exec(T))){X+=Y[0];T=T.replace(I.match.PSEUDO,"")}T=I.relative[T]?T+"*":T;for(var Z=0,U=V.length;Z0||T.offsetHeight>0};F.selectors.filters.animated=function(T){return o.grep(o.timers,function(U){return T===U.elem}).length};o.multiFilter=function(V,T,U){if(U){V=":not("+V+")"}return F.matches(V,T)};o.dir=function(V,U){var T=[],W=V[U];while(W&&W!=document){if(W.nodeType==1){T.push(W)}W=W[U]}return T};o.nth=function(X,T,V,W){T=T||1;var U=0;for(;X;X=X[V]){if(X.nodeType==1&&++U==T){break}}return X};o.sibling=function(V,U){var T=[];for(;V;V=V.nextSibling){if(V.nodeType==1&&V!=U){T.push(V)}}return T};return;l.Sizzle=F})();o.event={add:function(I,F,H,K){if(I.nodeType==3||I.nodeType==8){return}if(I.setInterval&&I!=l){I=l}if(!H.guid){H.guid=this.guid++}if(K!==g){var G=H;H=this.proxy(G);H.data=K}var E=o.data(I,"events")||o.data(I,"events",{}),J=o.data(I,"handle")||o.data(I,"handle",function(){return typeof o!=="undefined"&&!o.event.triggered?o.event.handle.apply(arguments.callee.elem,arguments):g});J.elem=I;o.each(F.split(/\s+/),function(M,N){var O=N.split(".");N=O.shift();H.type=O.slice().sort().join(".");var L=E[N];if(o.event.specialAll[N]){o.event.specialAll[N].setup.call(I,K,O)}if(!L){L=E[N]={};if(!o.event.special[N]||o.event.special[N].setup.call(I,K,O)===false){if(I.addEventListener){I.addEventListener(N,J,false)}else{if(I.attachEvent){I.attachEvent("on"+N,J)}}}}L[H.guid]=H;o.event.global[N]=true});I=null},guid:1,global:{},remove:function(K,H,J){if(K.nodeType==3||K.nodeType==8){return}var G=o.data(K,"events"),F,E;if(G){if(H===g||(typeof H==="string"&&H.charAt(0)==".")){for(var I in G){this.remove(K,I+(H||""))}}else{if(H.type){J=H.handler;H=H.type}o.each(H.split(/\s+/),function(M,O){var Q=O.split(".");O=Q.shift();var N=RegExp("(^|\\.)"+Q.slice().sort().join(".*\\.")+"(\\.|$)");if(G[O]){if(J){delete G[O][J.guid]}else{for(var P in G[O]){if(N.test(G[O][P].type)){delete G[O][P]}}}if(o.event.specialAll[O]){o.event.specialAll[O].teardown.call(K,Q)}for(F in G[O]){break}if(!F){if(!o.event.special[O]||o.event.special[O].teardown.call(K,Q)===false){if(K.removeEventListener){K.removeEventListener(O,o.data(K,"handle"),false)}else{if(K.detachEvent){K.detachEvent("on"+O,o.data(K,"handle"))}}}F=null;delete G[O]}}})}for(F in G){break}if(!F){var L=o.data(K,"handle");if(L){L.elem=null}o.removeData(K,"events");o.removeData(K,"handle")}}},trigger:function(I,K,H,E){var G=I.type||I;if(!E){I=typeof I==="object"?I[h]?I:o.extend(o.Event(G),I):o.Event(G);if(G.indexOf("!")>=0){I.type=G=G.slice(0,-1);I.exclusive=true}if(!H){I.stopPropagation();if(this.global[G]){o.each(o.cache,function(){if(this.events&&this.events[G]){o.event.trigger(I,K,this.handle.elem)}})}}if(!H||H.nodeType==3||H.nodeType==8){return g}I.result=g;I.target=H;K=o.makeArray(K);K.unshift(I)}I.currentTarget=H;var J=o.data(H,"handle");if(J){J.apply(H,K)}if((!H[G]||(o.nodeName(H,"a")&&G=="click"))&&H["on"+G]&&H["on"+G].apply(H,K)===false){I.result=false}if(!E&&H[G]&&!I.isDefaultPrevented()&&!(o.nodeName(H,"a")&&G=="click")){this.triggered=true;try{H[G]()}catch(L){}}this.triggered=false;if(!I.isPropagationStopped()){var F=H.parentNode||H.ownerDocument;if(F){o.event.trigger(I,K,F,true)}}},handle:function(K){var J,E;K=arguments[0]=o.event.fix(K||l.event);K.currentTarget=this;var L=K.type.split(".");K.type=L.shift();J=!L.length&&!K.exclusive;var I=RegExp("(^|\\.)"+L.slice().sort().join(".*\\.")+"(\\.|$)");E=(o.data(this,"events")||{})[K.type];for(var G in E){var H=E[G];if(J||I.test(H.type)){K.handler=H;K.data=H.data;var F=H.apply(this,arguments);if(F!==g){K.result=F;if(F===false){K.preventDefault();K.stopPropagation()}}if(K.isImmediatePropagationStopped()){break}}}},props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),fix:function(H){if(H[h]){return H}var F=H;H=o.Event(F);for(var G=this.props.length,J;G;){J=this.props[--G];H[J]=F[J]}if(!H.target){H.target=H.srcElement||document}if(H.target.nodeType==3){H.target=H.target.parentNode}if(!H.relatedTarget&&H.fromElement){H.relatedTarget=H.fromElement==H.target?H.toElement:H.fromElement}if(H.pageX==null&&H.clientX!=null){var I=document.documentElement,E=document.body;H.pageX=H.clientX+(I&&I.scrollLeft||E&&E.scrollLeft||0)-(I.clientLeft||0);H.pageY=H.clientY+(I&&I.scrollTop||E&&E.scrollTop||0)-(I.clientTop||0)}if(!H.which&&((H.charCode||H.charCode===0)?H.charCode:H.keyCode)){H.which=H.charCode||H.keyCode}if(!H.metaKey&&H.ctrlKey){H.metaKey=H.ctrlKey}if(!H.which&&H.button){H.which=(H.button&1?1:(H.button&2?3:(H.button&4?2:0)))}return H},proxy:function(F,E){E=E||function(){return F.apply(this,arguments)};E.guid=F.guid=F.guid||E.guid||this.guid++;return E},special:{ready:{setup:B,teardown:function(){}}},specialAll:{live:{setup:function(E,F){o.event.add(this,F[0],c)},teardown:function(G){if(G.length){var E=0,F=RegExp("(^|\\.)"+G[0]+"(\\.|$)");o.each((o.data(this,"events").live||{}),function(){if(F.test(this.type)){E++}});if(E<1){o.event.remove(this,G[0],c)}}}}}};o.Event=function(E){if(!this.preventDefault){return new o.Event(E)}if(E&&E.type){this.originalEvent=E;this.type=E.type}else{this.type=E}this.timeStamp=e();this[h]=true};function k(){return false}function u(){return true}o.Event.prototype={preventDefault:function(){this.isDefaultPrevented=u;var E=this.originalEvent;if(!E){return}if(E.preventDefault){E.preventDefault()}E.returnValue=false},stopPropagation:function(){this.isPropagationStopped=u;var E=this.originalEvent;if(!E){return}if(E.stopPropagation){E.stopPropagation()}E.cancelBubble=true},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=u;this.stopPropagation()},isDefaultPrevented:k,isPropagationStopped:k,isImmediatePropagationStopped:k};var a=function(F){var E=F.relatedTarget;while(E&&E!=this){try{E=E.parentNode}catch(G){E=this}}if(E!=this){F.type=F.data;o.event.handle.apply(this,arguments)}};o.each({mouseover:"mouseenter",mouseout:"mouseleave"},function(F,E){o.event.special[E]={setup:function(){o.event.add(this,F,a,E)},teardown:function(){o.event.remove(this,F,a)}}});o.fn.extend({bind:function(F,G,E){return F=="unload"?this.one(F,G,E):this.each(function(){o.event.add(this,F,E||G,E&&G)})},one:function(G,H,F){var E=o.event.proxy(F||H,function(I){o(this).unbind(I,E);return(F||H).apply(this,arguments)});return this.each(function(){o.event.add(this,G,E,F&&H)})},unbind:function(F,E){return this.each(function(){o.event.remove(this,F,E)})},trigger:function(E,F){return this.each(function(){o.event.trigger(E,F,this)})},triggerHandler:function(E,G){if(this[0]){var F=o.Event(E);F.preventDefault();F.stopPropagation();o.event.trigger(F,G,this[0]);return F.result}},toggle:function(G){var E=arguments,F=1;while(F=0){var E=G.slice(I,G.length);G=G.slice(0,I)}var H="GET";if(J){if(o.isFunction(J)){K=J;J=null}else{if(typeof J==="object"){J=o.param(J);H="POST"}}}var F=this;o.ajax({url:G,type:H,dataType:"html",data:J,complete:function(M,L){if(L=="success"||L=="notmodified"){F.html(E?o("
").append(M.responseText.replace(//g,"")).find(E):M.responseText)}if(K){F.each(K,[M.responseText,L,M])}}});return this},serialize:function(){return o.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?o.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||/select|textarea/i.test(this.nodeName)||/text|hidden|password|search/i.test(this.type))}).map(function(E,F){var G=o(this).val();return G==null?null:o.isArray(G)?o.map(G,function(I,H){return{name:F.name,value:I}}):{name:F.name,value:G}}).get()}});o.each("ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","),function(E,F){o.fn[F]=function(G){return this.bind(F,G)}});var r=e();o.extend({get:function(E,G,H,F){if(o.isFunction(G)){H=G;G=null}return o.ajax({type:"GET",url:E,data:G,success:H,dataType:F})},getScript:function(E,F){return o.get(E,null,F,"script")},getJSON:function(E,F,G){return o.get(E,F,G,"json")},post:function(E,G,H,F){if(o.isFunction(G)){H=G;G={}}return o.ajax({type:"POST",url:E,data:G,success:H,dataType:F})},ajaxSetup:function(E){o.extend(o.ajaxSettings,E)},ajaxSettings:{url:location.href,global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,xhr:function(){return l.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest()},accepts:{xml:"application/xml, text/xml",html:"text/html",script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},lastModified:{},ajax:function(M){M=o.extend(true,M,o.extend(true,{},o.ajaxSettings,M));var W,F=/=\?(&|$)/g,R,V,G=M.type.toUpperCase();if(M.data&&M.processData&&typeof M.data!=="string"){M.data=o.param(M.data)}if(M.dataType=="jsonp"){if(G=="GET"){if(!M.url.match(F)){M.url+=(M.url.match(/\?/)?"&":"?")+(M.jsonp||"callback")+"=?"}}else{if(!M.data||!M.data.match(F)){M.data=(M.data?M.data+"&":"")+(M.jsonp||"callback")+"=?"}}M.dataType="json"}if(M.dataType=="json"&&(M.data&&M.data.match(F)||M.url.match(F))){W="jsonp"+r++;if(M.data){M.data=(M.data+"").replace(F,"="+W+"$1")}M.url=M.url.replace(F,"="+W+"$1");M.dataType="script";l[W]=function(X){V=X;I();L();l[W]=g;try{delete l[W]}catch(Y){}if(H){H.removeChild(T)}}}if(M.dataType=="script"&&M.cache==null){M.cache=false}if(M.cache===false&&G=="GET"){var E=e();var U=M.url.replace(/(\?|&)_=.*?(&|$)/,"$1_="+E+"$2");M.url=U+((U==M.url)?(M.url.match(/\?/)?"&":"?")+"_="+E:"")}if(M.data&&G=="GET"){M.url+=(M.url.match(/\?/)?"&":"?")+M.data;M.data=null}if(M.global&&!o.active++){o.event.trigger("ajaxStart")}var Q=/^(\w+:)?\/\/([^\/?#]+)/.exec(M.url);if(M.dataType=="script"&&G=="GET"&&Q&&(Q[1]&&Q[1]!=location.protocol||Q[2]!=location.host)){var H=document.getElementsByTagName("head")[0];var T=document.createElement("script");T.src=M.url;if(M.scriptCharset){T.charset=M.scriptCharset}if(!W){var O=false;T.onload=T.onreadystatechange=function(){if(!O&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){O=true;I();L();T.onload=T.onreadystatechange=null;H.removeChild(T)}}}H.appendChild(T);return g}var K=false;var J=M.xhr();if(M.username){J.open(G,M.url,M.async,M.username,M.password)}else{J.open(G,M.url,M.async)}try{if(M.data){J.setRequestHeader("Content-Type",M.contentType)}if(M.ifModified){J.setRequestHeader("If-Modified-Since",o.lastModified[M.url]||"Thu, 01 Jan 1970 00:00:00 GMT")}J.setRequestHeader("X-Requested-With","XMLHttpRequest");J.setRequestHeader("Accept",M.dataType&&M.accepts[M.dataType]?M.accepts[M.dataType]+", */*":M.accepts._default)}catch(S){}if(M.beforeSend&&M.beforeSend(J,M)===false){if(M.global&&!--o.active){o.event.trigger("ajaxStop")}J.abort();return false}if(M.global){o.event.trigger("ajaxSend",[J,M])}var N=function(X){if(J.readyState==0){if(P){clearInterval(P);P=null;if(M.global&&!--o.active){o.event.trigger("ajaxStop")}}}else{if(!K&&J&&(J.readyState==4||X=="timeout")){K=true;if(P){clearInterval(P);P=null}R=X=="timeout"?"timeout":!o.httpSuccess(J)?"error":M.ifModified&&o.httpNotModified(J,M.url)?"notmodified":"success";if(R=="success"){try{V=o.httpData(J,M.dataType,M)}catch(Z){R="parsererror"}}if(R=="success"){var Y;try{Y=J.getResponseHeader("Last-Modified")}catch(Z){}if(M.ifModified&&Y){o.lastModified[M.url]=Y}if(!W){I()}}else{o.handleError(M,J,R)}L();if(X){J.abort()}if(M.async){J=null}}}};if(M.async){var P=setInterval(N,13);if(M.timeout>0){setTimeout(function(){if(J&&!K){N("timeout")}},M.timeout)}}try{J.send(M.data)}catch(S){o.handleError(M,J,null,S)}if(!M.async){N()}function I(){if(M.success){M.success(V,R)}if(M.global){o.event.trigger("ajaxSuccess",[J,M])}}function L(){if(M.complete){M.complete(J,R)}if(M.global){o.event.trigger("ajaxComplete",[J,M])}if(M.global&&!--o.active){o.event.trigger("ajaxStop")}}return J},handleError:function(F,H,E,G){if(F.error){F.error(H,E,G)}if(F.global){o.event.trigger("ajaxError",[H,F,G])}},active:0,httpSuccess:function(F){try{return !F.status&&location.protocol=="file:"||(F.status>=200&&F.status<300)||F.status==304||F.status==1223}catch(E){}return false},httpNotModified:function(G,E){try{var H=G.getResponseHeader("Last-Modified");return G.status==304||H==o.lastModified[E]}catch(F){}return false},httpData:function(J,H,G){var F=J.getResponseHeader("content-type"),E=H=="xml"||!H&&F&&F.indexOf("xml")>=0,I=E?J.responseXML:J.responseText;if(E&&I.documentElement.tagName=="parsererror"){throw"parsererror"}if(G&&G.dataFilter){I=G.dataFilter(I,H)}if(typeof I==="string"){if(H=="script"){o.globalEval(I)}if(H=="json"){I=l["eval"]("("+I+")")}}return I},param:function(E){var G=[];function H(I,J){G[G.length]=encodeURIComponent(I)+"="+encodeURIComponent(J)}if(o.isArray(E)||E.jquery){o.each(E,function(){H(this.name,this.value)})}else{for(var F in E){if(o.isArray(E[F])){o.each(E[F],function(){H(F,this)})}else{H(F,o.isFunction(E[F])?E[F]():E[F])}}}return G.join("&").replace(/%20/g,"+")}});var m={},n,d=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];function t(F,E){var G={};o.each(d.concat.apply([],d.slice(0,E)),function(){G[this]=F});return G}o.fn.extend({show:function(J,L){if(J){return this.animate(t("show",3),J,L)}else{for(var H=0,F=this.length;H").appendTo("body");K=I.css("display");if(K==="none"){K="block"}I.remove();m[G]=K}o.data(this[H],"olddisplay",K)}}for(var H=0,F=this.length;H=0;H--){if(G[H].elem==this){if(E){G[H](true)}G.splice(H,1)}}});if(!E){this.dequeue()}return this}});o.each({slideDown:t("show",1),slideUp:t("hide",1),slideToggle:t("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"}},function(E,F){o.fn[E]=function(G,H){return this.animate(F,G,H)}});o.extend({speed:function(G,H,F){var E=typeof G==="object"?G:{complete:F||!F&&H||o.isFunction(G)&&G,duration:G,easing:F&&H||H&&!o.isFunction(H)&&H};E.duration=o.fx.off?0:typeof E.duration==="number"?E.duration:o.fx.speeds[E.duration]||o.fx.speeds._default;E.old=E.complete;E.complete=function(){if(E.queue!==false){o(this).dequeue()}if(o.isFunction(E.old)){E.old.call(this)}};return E},easing:{linear:function(G,H,E,F){return E+F*G},swing:function(G,H,E,F){return((-Math.cos(G*Math.PI)/2)+0.5)*F+E}},timers:[],fx:function(F,E,G){this.options=E;this.elem=F;this.prop=G;if(!E.orig){E.orig={}}}});o.fx.prototype={update:function(){if(this.options.step){this.options.step.call(this.elem,this.now,this)}(o.fx.step[this.prop]||o.fx.step._default)(this);if((this.prop=="height"||this.prop=="width")&&this.elem.style){this.elem.style.display="block"}},cur:function(F){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null)){return this.elem[this.prop]}var E=parseFloat(o.css(this.elem,this.prop,F));return E&&E>-10000?E:parseFloat(o.curCSS(this.elem,this.prop))||0},custom:function(I,H,G){this.startTime=e();this.start=I;this.end=H;this.unit=G||this.unit||"px";this.now=this.start;this.pos=this.state=0;var E=this;function F(J){return E.step(J)}F.elem=this.elem;if(F()&&o.timers.push(F)&&!n){n=setInterval(function(){var K=o.timers;for(var J=0;J=this.options.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;var E=true;for(var F in this.options.curAnim){if(this.options.curAnim[F]!==true){E=false}}if(E){if(this.options.display!=null){this.elem.style.overflow=this.options.overflow;this.elem.style.display=this.options.display;if(o.css(this.elem,"display")=="none"){this.elem.style.display="block"}}if(this.options.hide){o(this.elem).hide()}if(this.options.hide||this.options.show){for(var I in this.options.curAnim){o.attr(this.elem.style,I,this.options.orig[I])}}this.options.complete.call(this.elem)}return false}else{var J=G-this.startTime;this.state=J/this.options.duration;this.pos=o.easing[this.options.easing||(o.easing.swing?"swing":"linear")](this.state,J,0,1,this.options.duration);this.now=this.start+((this.end-this.start)*this.pos);this.update()}return true}};o.extend(o.fx,{speeds:{slow:600,fast:200,_default:400},step:{opacity:function(E){o.attr(E.elem.style,"opacity",E.now)},_default:function(E){if(E.elem.style&&E.elem.style[E.prop]!=null){E.elem.style[E.prop]=E.now+E.unit}else{E.elem[E.prop]=E.now}}}});if(document.documentElement.getBoundingClientRect){o.fn.offset=function(){if(!this[0]){return{top:0,left:0}}if(this[0]===this[0].ownerDocument.body){return o.offset.bodyOffset(this[0])}var G=this[0].getBoundingClientRect(),J=this[0].ownerDocument,F=J.body,E=J.documentElement,L=E.clientTop||F.clientTop||0,K=E.clientLeft||F.clientLeft||0,I=G.top+(self.pageYOffset||o.boxModel&&E.scrollTop||F.scrollTop)-L,H=G.left+(self.pageXOffset||o.boxModel&&E.scrollLeft||F.scrollLeft)-K;return{top:I,left:H}}}else{o.fn.offset=function(){if(!this[0]){return{top:0,left:0}}if(this[0]===this[0].ownerDocument.body){return o.offset.bodyOffset(this[0])}o.offset.initialized||o.offset.initialize();var J=this[0],G=J.offsetParent,F=J,O=J.ownerDocument,M,H=O.documentElement,K=O.body,L=O.defaultView,E=L.getComputedStyle(J,null),N=J.offsetTop,I=J.offsetLeft;while((J=J.parentNode)&&J!==K&&J!==H){M=L.getComputedStyle(J,null);N-=J.scrollTop,I-=J.scrollLeft;if(J===G){N+=J.offsetTop,I+=J.offsetLeft;if(o.offset.doesNotAddBorder&&!(o.offset.doesAddBorderForTableAndCells&&/^t(able|d|h)$/i.test(J.tagName))){N+=parseInt(M.borderTopWidth,10)||0,I+=parseInt(M.borderLeftWidth,10)||0}F=G,G=J.offsetParent}if(o.offset.subtractsBorderForOverflowNotVisible&&M.overflow!=="visible"){N+=parseInt(M.borderTopWidth,10)||0,I+=parseInt(M.borderLeftWidth,10)||0}E=M}if(E.position==="relative"||E.position==="static"){N+=K.offsetTop,I+=K.offsetLeft}if(E.position==="fixed"){N+=Math.max(H.scrollTop,K.scrollTop),I+=Math.max(H.scrollLeft,K.scrollLeft)}return{top:N,left:I}}}o.offset={initialize:function(){if(this.initialized){return}var L=document.body,F=document.createElement("div"),H,G,N,I,M,E,J=L.style.marginTop,K='
';M={position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"};for(E in M){F.style[E]=M[E]}F.innerHTML=K;L.insertBefore(F,L.firstChild);H=F.firstChild,G=H.firstChild,I=H.nextSibling.firstChild.firstChild;this.doesNotAddBorder=(G.offsetTop!==5);this.doesAddBorderForTableAndCells=(I.offsetTop===5);H.style.overflow="hidden",H.style.position="relative";this.subtractsBorderForOverflowNotVisible=(G.offsetTop===-5);L.style.marginTop="1px";this.doesNotIncludeMarginInBodyOffset=(L.offsetTop===0);L.style.marginTop=J;L.removeChild(F);this.initialized=true},bodyOffset:function(E){o.offset.initialized||o.offset.initialize();var G=E.offsetTop,F=E.offsetLeft;if(o.offset.doesNotIncludeMarginInBodyOffset){G+=parseInt(o.curCSS(E,"marginTop",true),10)||0,F+=parseInt(o.curCSS(E,"marginLeft",true),10)||0}return{top:G,left:F}}};o.fn.extend({position:function(){var I=0,H=0,F;if(this[0]){var G=this.offsetParent(),J=this.offset(),E=/^body|html$/i.test(G[0].tagName)?{top:0,left:0}:G.offset();J.top-=j(this,"marginTop");J.left-=j(this,"marginLeft");E.top+=j(G,"borderTopWidth");E.left+=j(G,"borderLeftWidth");F={top:J.top-E.top,left:J.left-E.left}}return F},offsetParent:function(){var E=this[0].offsetParent||document.body;while(E&&(!/^body|html$/i.test(E.tagName)&&o.css(E,"position")=="static")){E=E.offsetParent}return o(E)}});o.each(["Left","Top"],function(F,E){var G="scroll"+E;o.fn[G]=function(H){if(!this[0]){return null}return H!==g?this.each(function(){this==l||this==document?l.scrollTo(!F?H:o(l).scrollLeft(),F?H:o(l).scrollTop()):this[G]=H}):this[0]==l||this[0]==document?self[F?"pageYOffset":"pageXOffset"]||o.boxModel&&document.documentElement[G]||document.body[G]:this[0][G]}});o.each(["Height","Width"],function(I,G){var E=I?"Left":"Top",H=I?"Right":"Bottom",F=G.toLowerCase();o.fn["inner"+G]=function(){return this[0]?o.css(this[0],F,false,"padding"):null};o.fn["outer"+G]=function(K){return this[0]?o.css(this[0],F,false,K?"margin":"border"):null};var J=G.toLowerCase();o.fn[J]=function(K){return this[0]==l?document.compatMode=="CSS1Compat"&&document.documentElement["client"+G]||document.body["client"+G]:this[0]==document?Math.max(document.documentElement["client"+G],document.body["scroll"+G],document.documentElement["scroll"+G],document.body["offset"+G],document.documentElement["offset"+G]):K===g?(this.length?o.css(this[0],J):null):this.css(J,typeof K==="string"?K:K+"px")}})})(); \ No newline at end of file diff --git a/doc/sample_html/style.css b/doc/sample_html/style.css new file mode 100644 index 00000000..d9d324c4 --- /dev/null +++ b/doc/sample_html/style.css @@ -0,0 +1,159 @@ +/* CSS styles for Coverage. */ +/* Page-wide styles */ +html, body, h1, h2, h3, p, td, th { + margin: 0; + padding: 0; + border: 0; + outline: 0; + font-weight: inherit; + font-style: inherit; + font-size: 100%; + font-family: inherit; + vertical-align: baseline; + } + +/* Set baseline grid to 16 pt. */ +body { + font-family: georgia, serif; + font-size: 1em; + } + +html>body { + font-size: 16px; + } + +/* Set base font size to 12/16 */ +p { + font-size: .75em; /* 12/16 */ + line-height: 1.3333em; /* 16/12 */ + } + +table { + border-collapse: collapse; + } + +a.nav { + text-decoration: none; + color: inherit; + } +a.nav:hover { + text-decoration: underline; + color: inherit; + } + +/* Page structure */ +#header { + background: #f8f8f8; + width: 100%; + border-bottom: 1px solid #eee; + } + +#source { + padding: 1em; + font-family: "courier new", monospace; + } + +#footer { + font-size: 85%; + font-family: verdana, sans-serif; + color: #666666; + font-style: italic; + } + +#index { + margin: 1em 0 0 3em; + } + +/* Header styles */ +.content { + padding: 1em 3em; + } + +h1 { + font-size: 1.25em; +} + +h2.stats { + margin-top: .5em; + font-size: 1em; +} +.stats span { + border: 1px solid; + padding: .1em .25em; + margin: 0 .1em; + cursor: pointer; + border-color: #999 #ccc #ccc #999; +} +.stats span.hide { + border-color: #ccc #999 #999 #ccc; +} + +/* Source file styles */ +.linenos p { + text-align: right; + margin: 0; + padding: 0 .5em; + color: #999999; + font-family: verdana, sans-serif; + font-size: .625em; /* 10/16 */ + line-height: 1.6em; /* 16/10 */ + } +td.text { + width: 100%; + } +.text p { + margin: 0; + padding: 0 0 0 .5em; + border-left: 2px solid #ffffff; + white-space: nowrap; + } + +.text p.mis { + background: #ffdddd; + border-left: 2px solid #ff0000; + } +.text p.run { + background: #ddffdd; + border-left: 2px solid #00ff00; + } +.text p.exc { + background: #eeeeee; + border-left: 2px solid #808080; + } +.text p.hide { + background: inherit; + } + +/* index styles */ +#index td, #index th { + text-align: right; + width: 6em; + padding: .25em 0; + border-bottom: 1px solid #eee; + } +#index th { + font-style: italic; + color: #333; + border-bottom: 1px solid #ccc; + } +#index td.name, #index th.name { + text-align: left; + width: auto; + height: 1.5em; + } +#index td.name a { + text-decoration: none; + color: #000; + } +#index td.name a:hover { + text-decoration: underline; + color: #000; + } +#index tr.total { + font-weight: bold; + } +#index tr.total td { + padding: .25em 0; + border-top: 1px solid #ccc; + border-bottom: none; + } -- cgit v1.2.1