1- import collections
21import os
3- import time
4- import sysconfig
52import sys
63
7- import pytest
8-
94import pybind11_mkdoc
105
116DIR = os .path .abspath (os .path .dirname (__file__ ))
127
138
14- def test_generate_headers (capsys ):
9+ def test_generate_headers (capsys , tmp_path ):
1510 comments = pybind11_mkdoc .mkdoc_lib .extract_all ([os .path .join (DIR , "sample_header_docs" , "sample_header.h" )])
16- pybind11_mkdoc .mkdoc_lib .write_header (comments , sys .stdout )
11+ output = tmp_path / "docs.h"
12+ with output .open ("w" ) as fd :
13+ pybind11_mkdoc .mkdoc_lib .write_header (comments , fd )
1714
1815 res = capsys .readouterr ()
1916
2017 assert "warning" not in res .err
2118 assert "error" not in res .err
22- assert res . out == """\
19+ assert output . read_text () == """\
2320 /*
2421 This file contains docstrings for use in the Python bindings.
2522 Do not edit! They were automatically extracted by pybind11_mkdoc.
2623 */
2724
28- #define __EXPAND(x) x
29- #define __COUNT(_1, _2, _3, _4, _5, _6, _7, COUNT, ...) COUNT
30- #define __VA_SIZE(...) __EXPAND(__COUNT(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0))
31- #define __CAT1(a, b) a ## b
32- #define __CAT2(a, b) __CAT1(a, b)
33- #define __DOC1(n1) __doc_##n1
34- #define __DOC2(n1, n2) __doc_##n1##_##n2
35- #define __DOC3(n1, n2, n3) __doc_##n1##_##n2##_##n3
36- #define __DOC4(n1, n2, n3, n4) __doc_##n1##_##n2##_##n3##_##n4
37- #define __DOC5(n1, n2, n3, n4, n5) __doc_##n1##_##n2##_##n3##_##n4##_##n5
38- #define __DOC6(n1, n2, n3, n4, n5, n6) __doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6
39- #define __DOC7(n1, n2, n3, n4, n5, n6, n7) __doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7
40- #define DOC(...) __EXPAND(__EXPAND(__CAT2(__DOC, __VA_SIZE(__VA_ARGS__)))(__VA_ARGS__))
25+ #define MKD_EXPAND(x) x
26+ #define MKD_COUNT(_1, _2, _3, _4, _5, _6, _7, COUNT, ...) COUNT
27+ #define MKD_VA_SIZE(...) MKD_EXPAND(MKD_COUNT(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0))
28+ #define MKD_CAT1(a, b) a ## b
29+ #define MKD_CAT2(a, b) MKD_CAT1(a, b)
30+ #define MKD_DOC1(n1) mkd_doc_##n1
31+ #define MKD_DOC2(n1, n2) mkd_doc_##n1##_##n2
32+ #define MKD_DOC3(n1, n2, n3) mkd_doc_##n1##_##n2##_##n3
33+ #define MKD_DOC4(n1, n2, n3, n4) mkd_doc_##n1##_##n2##_##n3##_##n4
34+ #define MKD_DOC5(n1, n2, n3, n4, n5) mkd_doc_##n1##_##n2##_##n3##_##n4##_##n5
35+ #define MKD_DOC7(n1, n2, n3, n4, n5, n6, n7) mkd_doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7
36+ #define DOC(...) MKD_EXPAND(MKD_EXPAND(MKD_CAT2(MKD_DOC, MKD_VA_SIZE(__VA_ARGS__)))(__VA_ARGS__))
4137
4238#if defined(__GNUG__)
4339#pragma GCC diagnostic push
4440#pragma GCC diagnostic ignored "-Wunused-variable"
4541#endif
4642
4743
48- static const char *__doc_RootLevelSymbol =
44+ static const char *mkd_doc_RootLevelSymbol =
4945R"doc(Root-level symbol. Magna fermentum iaculis eu non diam phasellus
5046vestibulum.)doc";
5147
52- static const char *__doc_drake_MidLevelSymbol =
48+ static const char *mkd_doc_drake_MidLevelSymbol =
5349R"doc(1. Begin first ordered list element. Rutrum quisque non tellus orci ac
5450auctor. End first ordered list element. 2. Begin second ordered list
5551element. Ipsum faucibus vitae aliquet nec. Ligula ullamcorper
@@ -66,4 +62,3 @@ def test_generate_headers(capsys):
6662#endif
6763
6864"""
69-
0 commit comments