-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* simplify file write and make_directories simple file writing is simpler with pathlib.Path.write_text For make_directories, python2 is end of life. python3 doesn't require blank __init__.py files, so we can rely on pathlib.path.mkdir * default to adding __init__.py files to directories Python unittest discover still relies on __init__.py files and doesn't support namespace packages. By default we can create these but allow for their suppression if using other test frameworks. * test that non markdown extension is ignored * add per language test and data * remove python indicator, switch to language If mkcodes supports many language blocks, we can make the default language python. safe mode should remove that default and not output languages that aren't specified. 2 tests not passing * introduce default language, lang mappings rather than assume python, let's just recognize that's the default language for unknown blocsk. People can override that as needed if they want to put in some other assumptions. * collect and write per-language code blocks as we pass through a document, get per-language codeblocks, then write those out to the correct extensionfile. By default, everything is still python - though it can be overridden * make other languages work Now the default language is python codeblocks in other languages can be broken out into their own language files. There is a way to add more languages with mappings, but a language fenced codeblock will default to use that language as the output extension * add test for unmapped extension * clean up __init__.py addition logic Also remove some commented code, shorten comments * test __init__.py paths For non python paths, don't declare them to be python packages. * correct spelling mistakes also conform new test to self.call * separate 3rd party imports with a blank line * cleanup * Ignore capitalization of language strings. * Remove no-op else clause. * Document extension/language mappings. * Language should be reset even if --unsafe. The safety flag refers to whether a default language is used. This would have made it also accept the previous language used, which doesn't seem right. * Add warning when unhinted code blocks are skipped. * Use dash for cli parameters and fix typo. * Pull sanity check out of if-statement. * Don't create __init__.py in base output directory. * Avoid abusing return as a mid-function "break". I would consider this anti-pattern when avoidable and I find it harder to understand. * Remove redundant test assertion. Co-authored-by: Matt Katz <[email protected]> Co-authored-by: ryneeverett <[email protected]>
- Loading branch information
1 parent
c27b4b8
commit 16c8f9a
Showing
8 changed files
with
226 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# dotNet is still a thing | ||
|
||
What if you could provide a code sample here? | ||
|
||
```cs | ||
public void Sum(int a, int b) | ||
{ | ||
return a + b; | ||
} | ||
``` | ||
|
||
And we know that it is testable. | ||
|
||
```csharp | ||
[Testclass] | ||
public class UnitTest1 | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() | ||
{ | ||
//Arrange | ||
ApplicationToTest.Calc ClassCalc = new ApplicationToTest.Calc(); | ||
int expectedResult = 5; | ||
|
||
//Act | ||
int result = ClassCalc.Sum(2,3); | ||
|
||
//Assert | ||
Assert.AreEqual(expectedResult, result); | ||
} | ||
} | ||
``` | ||
|
||
Actually checking and running these tests, that's a different matter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Java documentation is important | ||
|
||
That's a language still. Here's a java codeblock: | ||
|
||
```java | ||
public class MyUnit { | ||
public String concatenate(String one, String two){ | ||
return one + two; | ||
} | ||
} | ||
``` | ||
|
||
And since we have that class, let's test it | ||
|
||
```java | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
public class MyUnitTest { | ||
|
||
@Test | ||
public void testConcatenate() { | ||
MyUnit myUnit = new MyUnit(); | ||
|
||
String result = myUnit.concatenate("one", "two"); | ||
|
||
assertEquals("onetwo", result); | ||
|
||
} | ||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Comparing and contrasting | ||
|
||
For some ideas about an api, we might give getting started code in a simple getting started page. | ||
|
||
In a pinch, let's hello that world. | ||
|
||
```py | ||
print("hello, world") | ||
``` | ||
|
||
But maybe we want this to be enterprise grade? | ||
|
||
```java | ||
class HelloWorld { | ||
public static void main(String[] args) { | ||
System.out.println("Hello, World!"); | ||
} | ||
} | ||
``` | ||
|
||
New orders from the CTO: let's use Azure cloud. | ||
```cs | ||
class HelloWorld { | ||
static void Main() { | ||
System.Console.WriteLine("Hello World"); | ||
} | ||
} | ||
``` | ||
|
||
We want to have a react vue jquery frontend. Assume that the code sample below has a testable extension as the language | ||
|
||
```js | ||
console.log('Hello, world"); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Cleanliness | ||
|
||
If there are no python files in a directory, we don't need to add an __init__.py file to that directory. Sure, they don't hurt, but having them where they aren't needed isn't very tidy and might be confusing. | ||
|
||
Speaking of confusing, lets test javascript | ||
```js | ||
function assert(condition, message) { | ||
if (!condition) { | ||
message = message || "Assertion failed"; | ||
throw new Error(message); | ||
} | ||
} | ||
|
||
assert([]+[]=="", "very sensible, adding arrays is a string") | ||
assert({}+[]==0, "of course adding a dict to an array is 0") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Test discovery | ||
|
||
For test discovery to work for unittest, python files generated from this document must have an `__init__.py` file added to the directory - otherwise they won't be considered testable packages. | ||
|
||
```python | ||
import unittest | ||
|
||
class TestDiscovery(unittest.TestCase): | ||
def test_discovery(self): | ||
self.assertTrue(True) | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters