Show More
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 |
@@ -0,0 +1,88 b'' | |||||
|
1 | #!/usr/bin/env python | |||
|
2 | """ | |||
|
3 | Contains base test class for nbconvert | |||
|
4 | """ | |||
|
5 | #----------------------------------------------------------------------------- | |||
|
6 | #Copyright (c) 2013, the IPython Development Team. | |||
|
7 | # | |||
|
8 | #Distributed under the terms of the Modified BSD License. | |||
|
9 | # | |||
|
10 | #The full license is in the file COPYING.txt, distributed with this software. | |||
|
11 | #----------------------------------------------------------------------------- | |||
|
12 | ||||
|
13 | #----------------------------------------------------------------------------- | |||
|
14 | # Imports | |||
|
15 | #----------------------------------------------------------------------------- | |||
|
16 | ||||
|
17 | import subprocess | |||
|
18 | ||||
|
19 | #----------------------------------------------------------------------------- | |||
|
20 | # Classes and functions | |||
|
21 | #----------------------------------------------------------------------------- | |||
|
22 | ||||
|
23 | class TestsBase(object): | |||
|
24 | """Base tests class. Contains usefull fuzzy comparison and nbconvert | |||
|
25 | functions.""" | |||
|
26 | ||||
|
27 | ||||
|
28 | def fuzzy_compare(self, a, b, newlines_are_spaces=True, tabs_are_spaces=True, | |||
|
29 | fuzzy_spacing=True, ignore_spaces=False, | |||
|
30 | ignore_newlines=False, ignore_case=True): | |||
|
31 | """ | |||
|
32 | Performs a fuzzy comparison of two strings. A fuzzy comparison is a | |||
|
33 | comparison that ignores insignificant differences in the two comparands. | |||
|
34 | The significance of certain differences can be specified via the keyword | |||
|
35 | parameters of this method. | |||
|
36 | """ | |||
|
37 | ||||
|
38 | if newlines_are_spaces: | |||
|
39 | a = a.replace('\n', ' ') | |||
|
40 | b = b.replace('\n', ' ') | |||
|
41 | ||||
|
42 | if tabs_are_spaces: | |||
|
43 | a = a.replace('\t', ' ') | |||
|
44 | b = b.replace('\t', ' ') | |||
|
45 | ||||
|
46 | if ignore_spaces: | |||
|
47 | a = a.replace(' ', '') | |||
|
48 | b = b.replace(' ', '') | |||
|
49 | ||||
|
50 | if fuzzy_spacing: | |||
|
51 | a = self.recursive_replace(a, ' ', ' ') | |||
|
52 | b = self.recursive_replace(b, ' ', ' ') | |||
|
53 | ||||
|
54 | if ignore_newlines: | |||
|
55 | a = a.replace('\n', '') | |||
|
56 | b = b.replace('\n', '') | |||
|
57 | ||||
|
58 | if ignore_case: | |||
|
59 | a = a.lower() | |||
|
60 | b = b.lower() | |||
|
61 | ||||
|
62 | return a == b | |||
|
63 | ||||
|
64 | ||||
|
65 | def recursive_replace(self, text, search, replacement): | |||
|
66 | """ | |||
|
67 | Performs a recursive replacement operation. Replaces all instances | |||
|
68 | of a search string in a text string with a replacement string until | |||
|
69 | the search string no longer exists. Recursion is needed because the | |||
|
70 | replacement string may generate additional search strings. | |||
|
71 | ||||
|
72 | For example: | |||
|
73 | Replace "ii" with "i" in the string "Hiiii" yields "Hii" | |||
|
74 | Another replacement yields "Hi" (the desired output) | |||
|
75 | ||||
|
76 | Parameters: | |||
|
77 | ----------- | |||
|
78 | text : string | |||
|
79 | Text to replace in. | |||
|
80 | search : string | |||
|
81 | String to search for within "text" | |||
|
82 | replacement : string | |||
|
83 | String to replace "search" with | |||
|
84 | """ | |||
|
85 | while search in text: | |||
|
86 | text = text.replace(search, replacement) | |||
|
87 | return text | |||
|
88 | No newline at end of file |
@@ -0,0 +1,28 b'' | |||||
|
1 | """ | |||
|
2 | Contains tests for the nbconvertapp | |||
|
3 | """ | |||
|
4 | #----------------------------------------------------------------------------- | |||
|
5 | #Copyright (c) 2013, the IPython Development Team. | |||
|
6 | # | |||
|
7 | #Distributed under the terms of the Modified BSD License. | |||
|
8 | # | |||
|
9 | #The full license is in the file COPYING.txt, distributed with this software. | |||
|
10 | #----------------------------------------------------------------------------- | |||
|
11 | ||||
|
12 | #----------------------------------------------------------------------------- | |||
|
13 | # Imports | |||
|
14 | #----------------------------------------------------------------------------- | |||
|
15 | ||||
|
16 | from .base import TestsBase | |||
|
17 | ||||
|
18 | #----------------------------------------------------------------------------- | |||
|
19 | # Classes and functions | |||
|
20 | #----------------------------------------------------------------------------- | |||
|
21 | ||||
|
22 | class NbConvertAppTests(object): | |||
|
23 | """Collection of NbConvertApp tests""" | |||
|
24 | ||||
|
25 | def test_a(self): | |||
|
26 | print('Success!') | |||
|
27 | assert True | |||
|
28 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now