示例#1
0
 def test16_content_ok(self):
     """Test content_ok method."""
     self.assertTrue(
         Namaste(0, 'frog').content_ok('tests/testdata/namaste'))
     self.assertFalse(Namaste().content_ok('tests/testdata/namaste'))
     self.assertFalse(
         Namaste(0, 'bison').content_ok('tests/testdata/namaste'))
示例#2
0
 def test13_tvalue(self):
     """Test tvalue property."""
     # Explicitly set
     n = Namaste(tvalue='xyz')
     self.assertEqual(n.tvalue, 'xyz')
     # Derived from content
     n = Namaste(content='x y z\n')
     self.assertEqual(n.tvalue, 'x_y_z')
示例#3
0
 def test14_write(self):
     """Test write method."""
     tempdir = tempfile.mkdtemp(prefix='test_namaste')
     n = Namaste(0, 'balloon')
     n.write(tempdir)
     filepath = os.path.join(tempdir, '0=balloon')
     self.assertTrue(os.path.isfile(filepath))
     with open(filepath, 'r') as fh:
         self.assertEqual(fh.read(), 'balloon\n')
示例#4
0
 def test15_check_content(self):
     """Test check_content method."""
     Namaste(0, 'frog').check_content('tests/testdata/namaste')
     self.assertRaises(NamasteException,
                       Namaste().check_content, 'tests/testdata/namaste')
     self.assertRaises(NamasteException,
                       Namaste(0, 'a').check_content,
                       'tests/testdata/namaste/does_not_exist')
     self.assertRaises(NamasteException,
                       Namaste(0, 'bison').check_content,
                       'tests/testdata/namaste')
示例#5
0
 def test11_init(self):
     """Test initialization."""
     n = Namaste()
     self.assertEqual(n.d, 0)
     self.assertEqual(n._tr_func, content_to_tvalue)  # pylint: disable=protected-access
     n = Namaste(0, 'myspec')
     self.assertEqual(n.d, 0)
     self.assertEqual(n.content, 'myspec')
     n = Namaste(d=0,
                 content='whatevs',
                 tvalue='myspec_1',
                 tr_func=lambda x: x[:3])
     self.assertEqual(n.content, 'whatevs')
示例#6
0
 def test14_write(self):
     """Test write method."""
     tempdir = tempfile.mkdtemp(prefix='test_namaste')
     # Plain OS method
     n = Namaste(0, 'balloon')
     n.write(tempdir)
     filepath = os.path.join(tempdir, '0=balloon')
     self.assertTrue(os.path.isfile(filepath))
     with open(filepath, 'r', encoding="utf-8") as fh:
         self.assertEqual(fh.read(), 'balloon\n')
     # With fs filesystem
     tmpfs = fs.tempfs.TempFS()
     n = Namaste(1, 'jelly')
     n.write(pyfs=tmpfs)
     self.assertTrue(tmpfs.isfile('1=jelly'))
     self.assertEqual(tmpfs.readtext('1=jelly'), 'jelly\n')
示例#7
0
 def test15_check_content(self):
     """Test check_content method."""
     Namaste(0, 'frog').check_content('tests/testdata/namaste')
     self.assertRaises(NamasteException,
                       Namaste().check_content, 'tests/testdata/namaste')
     self.assertRaises(NamasteException,
                       Namaste(0, 'a').check_content,
                       'tests/testdata/namaste/does_not_exist')
     self.assertRaises(NamasteException,
                       Namaste(0, 'bison').check_content,
                       'tests/testdata/namaste')
     # Using pyfs...
     tmpfs = fs.tempfs.TempFS()
     tmpfs.writetext('9=niner', 'niner\n')
     tmpfs.writetext('8=smiley', 'FROWNY\n')
     Namaste(9, 'niner').check_content(pyfs=tmpfs)
     Namaste(9, 'niner').check_content(dir='', pyfs=tmpfs)
     self.assertRaises(NamasteException,
                       Namaste(8, 'smiley').check_content,
                       pyfs=tmpfs)
     self.assertRaises(NamasteException,
                       Namaste(7, 'not-there').check_content,
                       pyfs=tmpfs)
示例#8
0
 def test12_filename(self):
     """Test filename property."""
     n = Namaste()
     self.assertEqual(n.filename, '0=')
     n = Namaste(2, 'wibble')
     self.assertEqual(n.filename, '2=wibble')