Ejemplo n.º 1
0
 def test_exists_path(self):
   self.assertFalse(Helper.exists_path(test_file_path, True))
   with self.assertRaises(TypeError): Helper.exists_path()
   with self.assertRaises(TypeError): Helper.exists_path(isFolder=True)
   self.assertFalse(Helper.exists_path(self.base_path))
   self.assertTrue(Helper.exists_path(test_file_path))
   self.assertTrue(Helper.exists_path(self.base_path, True))
Ejemplo n.º 2
0
 def test_exists_path(self):
     self.assertFalse(Helper.exists_path(test_file_path, True))
     with self.assertRaises(TypeError):
         Helper.exists_path()
     with self.assertRaises(TypeError):
         Helper.exists_path(isFolder=True)
     self.assertFalse(Helper.exists_path(self.base_path))
     self.assertTrue(Helper.exists_path(test_file_path))
     self.assertTrue(Helper.exists_path(self.base_path, True))
Ejemplo n.º 3
0
    def test_write_to_file(self):
        test_filename = 'empty_file.txt'
        message = 'file content'
        file_path = Helper.join_path((os.getcwd(), test_filename))

        self.assertFalse(Helper.exists_path(file_path))
        Helper.write_to_file(file_path, message)

        self.assertTrue(os.path.exists(file_path))

        with open(file_path, 'r') as f:
            self.assertEqual(f.read().find(message), 0)

        os.remove(file_path)
        self.assertFalse(os.path.exists(file_path))

        file_path = Helper.join_path(
            (os.getcwd(), 'some_path', 'sub_path', test_filename))

        Helper.write_to_file(file_path, message)
        self.assertTrue(os.path.exists(file_path))
        with open(file_path, 'r') as f:
            self.assertEqual(f.read().find(message), 0)
        os.remove(file_path)
        self.assertFalse(os.path.exists(file_path))
        shutil.rmtree(Helper.join_path((os.getcwd(), 'some_path')))

        os.makedirs(Helper.join_path((os.getcwd(), 'some_path')))

        file_path = Helper.join_path(
            (os.getcwd(), 'some_path', 'sub_path', test_filename))

        Helper.write_to_file(file_path, message)
        self.assertTrue(os.path.exists(file_path))
        with open(file_path, 'r') as f:
            self.assertEqual(f.read().find(message), 0)
        os.remove(file_path)
        self.assertFalse(os.path.exists(file_path))

        shutil.rmtree(Helper.join_path((os.getcwd(), 'some_path')))
Ejemplo n.º 4
0
  def test_write_to_file(self):
    test_filename = 'empty_file.txt'
    message = 'file content'
    file_path = Helper.join_path((os.getcwd(), test_filename))

    self.assertFalse(Helper.exists_path(file_path))
    Helper.write_to_file(file_path, message)

    self.assertTrue(os.path.exists(file_path))

    with open(file_path, 'r') as f:
      self.assertEqual(f.read().find(message), 0)

    os.remove(file_path)
    self.assertFalse(os.path.exists(file_path))

    file_path = Helper.join_path((os.getcwd(), 'some_path', 'sub_path', test_filename))

    Helper.write_to_file(file_path, message)
    self.assertTrue(os.path.exists(file_path))
    with open(file_path, 'r') as f:
      self.assertEqual(f.read().find(message), 0)
    os.remove(file_path)
    self.assertFalse(os.path.exists(file_path))
    shutil.rmtree(Helper.join_path((os.getcwd(), 'some_path')))

    os.makedirs(Helper.join_path((os.getcwd(), 'some_path')))

    file_path = Helper.join_path((os.getcwd(), 'some_path', 'sub_path', test_filename))

    Helper.write_to_file(file_path, message)
    self.assertTrue(os.path.exists(file_path))
    with open(file_path, 'r') as f:
      self.assertEqual(f.read().find(message), 0)
    os.remove(file_path)
    self.assertFalse(os.path.exists(file_path))

    shutil.rmtree(Helper.join_path((os.getcwd(), 'some_path')))