-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into main
- Loading branch information
Showing
5 changed files
with
99 additions
and
1 deletion.
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,26 @@ | ||
import os | ||
import shutil | ||
import unittest | ||
|
||
from pyrmanent import Pyrmanent | ||
|
||
|
||
class Example(Pyrmanent): | ||
pass | ||
|
||
|
||
class TestFiles(unittest.TestCase): | ||
def test_pickle_file(self): | ||
Example() | ||
self.assertTrue(os.path.isfile("Example.pickle")) | ||
os.remove("Example.pickle") | ||
|
||
def test_custom_folder(self): | ||
Example(folder="saves") | ||
self.assertTrue(os.path.isfile("saves/Example.pickle")) | ||
shutil.rmtree("saves") | ||
|
||
def test_custom_nested_folder(self): | ||
Example(folder="saves/data") | ||
self.assertTrue(os.path.isfile("saves/data/Example.pickle")) | ||
shutil.rmtree("saves") |
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,20 @@ | ||
import os | ||
import unittest | ||
|
||
from pyrmanent import Pyrmanent | ||
|
||
|
||
class Example(Pyrmanent): | ||
pass | ||
|
||
|
||
class TestName(unittest.TestCase): | ||
def test_custom_name(self): | ||
Example(name="foo") | ||
self.assertTrue(os.path.isfile("Example_foo.pickle")) | ||
os.remove("Example_foo.pickle") | ||
|
||
def test_no_custom_name(self): | ||
Example() | ||
self.assertTrue(os.path.isfile("Example.pickle")) | ||
os.remove("Example.pickle") |
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,50 @@ | ||
import os | ||
import unittest | ||
|
||
from pyrmanent import Pyrmanent | ||
|
||
|
||
class Example(Pyrmanent): | ||
def init(self): | ||
self.menu = "pizza" | ||
|
||
|
||
class TestPersistency(unittest.TestCase): | ||
def test_init_values(self): | ||
example = Example() | ||
self.assertTrue(hasattr(example, "menu")) | ||
self.assertEqual(example.menu, "pizza") | ||
os.remove("Example.pickle") | ||
|
||
def test_not_saved_values(self): | ||
example = Example() | ||
example.menu = "rice" | ||
example = Example() | ||
self.assertTrue(hasattr(example, "menu")) | ||
self.assertEqual(example.menu, "pizza") | ||
os.remove("Example.pickle") | ||
|
||
def test_saved_values(self): | ||
example = Example() | ||
example.menu = "rice" | ||
example.save() | ||
example = Example() | ||
self.assertTrue(hasattr(example, "menu")) | ||
self.assertEqual(example.menu, "rice") | ||
os.remove("Example.pickle") | ||
|
||
def test_values_for_different_names(self): | ||
first = Example(name="first") | ||
second = Example(name="second") | ||
first.menu = "rice" | ||
second.menu = "soup" | ||
first.save() | ||
second.save() | ||
first = Example(name="first") | ||
second = Example(name="second") | ||
self.assertTrue(hasattr(first, "menu")) | ||
self.assertTrue(hasattr(second, "menu")) | ||
self.assertEqual(first.menu, "rice") | ||
self.assertEqual(second.menu, "soup") | ||
os.remove("Example_first.pickle") | ||
os.remove("Example_second.pickle") |